Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^11: Recalcitrant placeholders

by pryrt (Abbot)
on Aug 05, 2021 at 20:27 UTC ( [id://11135633]=note: print w/replies, xml ) Need Help??


in reply to Re^10: Recalcitrant placeholders
in thread Recalcitrant placeholders

What happens if you untaint the email address? I don't have a mysql to test against, and didn't feel like changing the database aspects. But to untaint the email entry of your hash, you just need to follow the general rules for laundering tainted data. I would assume that once it's untainted, the TEST would give 5 again (untested).

Example of untainting an email address hash entry:

C:\Users\peter.jones\Downloads\TempData\perl>perl -T -M5.012 -Mwarning +s -MScalar::Util=tainted -le "my %h = (email => $ARGV[0]); print tain +ted($h{email}); $h{email} =~ m/\b([[:graph:]]+@[[:graph:]]+)\b/g and +$h{email} = $1; print tainted($h{email});" me@example 1 0
(you should probably pick a stronger/more-accurate regex than I used for "valid email address"...)

Replies are listed 'Best First'.
Re^12: Recalcitrant placeholders
by Bod (Parson) on Aug 05, 2021 at 23:24 UTC
    What happens if you untaint the email address?

    Not what I was expecting to happen!!!
    I was pretty sure that untainting the email address would have the same effect as turning off taint mode but it doesn't.

    This code:

    produces this with taint mode off:
    Perl: 5.016003 Database: MySQL 10.2.39-MariaDB Driver: mysql DBI Ver: 1.643 DBD::mysql Ver: 4.050 Tainted... EMAIL: foo@bar.com Untainted... EMAIL: foo@bar.com CRID: 5 TEST: 5
    and this with taint mode on:
    Perl: 5.016003 Database: MySQL 10.2.39-MariaDB Driver: mysql DBI Ver: 1.643 DBD::mysql Ver: 4.050 Email is tainted Tainted... EMAIL: foo@bar.com Untainted... EMAIL: foo@bar.com CRID: 5 TEST: 0

    I realise the regexp is not especially good but it is just for testing and does the job of untainting the email address. The extra say statements are added to prove that the emails address really is being untainted.

      When your code is untainting $argv[1] after the tainted value has been copied into $data{'email'}, why would you expect the database interaction to change? I believe that you need to untaint $data{'email'} , since that's your input to the database.

      I switched your code over to SQLite to try it myself; unfortunately, even with the code you posted (except for the switch to SQLite), both CRID and TEST gave me 5. So I cannot test that portion for you. But if you add debug prints of the taintedness of both after you believe you are untainted, you will see

      ... snippet ... # here, you untainted the argv[1], but not the hash value! if ($argv[1] =~ /^(.+\@.+\..+)$/) { $argv[1] = $1; say "Looking while Untainted..."; say "EMAIL: $argv[1]"; say __LINE__, ": argv is ", (tainted($argv[1])?'':'not ', "tainted +"); # edit: uncomment here to untaint the hash value as well #$data{'email'} = $argv[1]; } say "argv is ", (tainted($argv[1])?'':'not ', "tainted"); say "data{email} is ", tainted($data{'email'})?'':'not ', "tainted"; ... snippet ... __END__

      With the line commented, as shown:

      C:\usr\local\share\PassThru\perl\perlmonks>perl -T pm11135636.pl "" fo +o@bar.com Content-type: text/plain Perl: 5.030000 Database: SQLite 3.26.0 Driver: SQLite DBI Ver: 1.642 DBD::SQLite Ver: 1.62 Email is tainted Tainted... EMAIL: foo@bar.com Untainted... EMAIL: foo@bar.com argv is not tainted data{email} is tainted CRID: 5 TEST: 5

      With the line uncommented, so it untaints:

      C:\usr\local\share\PassThru\perl\perlmonks>perl -T pm11135636.pl "" fo +o@bar.com Content-type: text/plain Perl: 5.030000 Database: SQLite 3.26.0 Driver: SQLite DBI Ver: 1.642 DBD::SQLite Ver: 1.62 Email is tainted Tainted... EMAIL: foo@bar.com Untainted... EMAIL: foo@bar.com argv is not tainted data{email} is not tainted CRID: 5 TEST: 5

        When your code is untainting $argv1 after the tainted value has been copied into $data{'email'}, why would you expect the database interaction to change?

        That was rather stupid of me wasn't it?!?
        No answer required...

        That's what comes of trying to do something quickly last thing at night before bed. A combination of tiredness and rushing is always bound to lead to stupid mistakes. I should know this...

        When I untaint the correct variable I get what I expected...

        Perl: 5.016003 Database: MySQL 10.2.40-MariaDB Driver: mysql DBI Ver: 1.643 DBD::mysql Ver: 4.050 Email is tainted Tainted... EMAIL: foo@bar.com Untainted... EMAIL: foo@bar.com CRID: 5 TEST: 5

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2024-04-23 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found