Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Taint checking?

by citromatik (Curate)
on Jul 01, 2009 at 16:13 UTC ( #776486=perlquestion: print w/replies, xml ) Need Help??
citromatik has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have encountered the following in production code:

if((defined ($command_str)) && ($command_str =~ /^(.*)$/)) {#taint che +cking $command_str = $1; # blah, blah

Does this make any sense? is there any benefit in reassigning $command_str this way?

Thanks in advance

citromatik

Replies are listed 'Best First'.
Re: Taint checking?
by jethro (Monsignor) on Jul 01, 2009 at 16:25 UTC

    You can run perl in tainted mode, where any data a script gets from I/O is tainted (i.e. flagged as unsafe and potentially dangerous). This is for example useful with CGI-scripts.

    Data can be untainted by filtering it with a regex. In that case perl assumes that you have filtered any dangerous parts and the extracted data is safe now

    As the code you are presenting does no real effort to filter anything the author was either absolutely sure that $command_str came from somewhere safe or he couldn't be bothered with security

Re: Taint checking?
by JavaFan (Canon) on Jul 01, 2009 at 17:32 UTC
    No, without context, it doesn't make any sense. If you're going to untaint by accepting anything, it easiest way is to get rid of the -T.

    Now, there may be other reasons why the program is using taint, and perhaps what is in $command_str comes from a trusted source. But that cannot be told from the snippet.

Re: Taint checking?
by graff (Chancellor) on Jul 02, 2009 at 04:04 UTC
    Well, since there is no "s" modifier on the regex, it is at least testing making sure that the value of $command_str does not contain "\n", which might be worth something, depending on how this variable is used later on.

    But if the whole script were in my hands, the next thing I would do would be to search for occurrences/uses of $command_str outside (following) that if block, because any such occurrence/usage could be getting a still-tainted value (in the case where that "if" condition wasn't met).

    (Update: and then, of course, I would also look very carefully at how this variable is being used inside that "if" block.)

Re: Taint checking?
by Anonymous Monk on Jul 01, 2009 at 16:21 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://776486]
Approved by Old_Gray_Bear
help
Chatterbox?
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...
[stevieb]: ...prepared for even the very worst
Discipulus seems a part of the globe very unfrindly with Kawasaki riders..

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2016-12-06 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.