I'm gonna give you a crash course in tainting. Tainting is activated by the -T switch. What it basically does is it marks all data from outside your program as tainted:
If one variable in an expression is tainted, the result of that whole expression is too:my $from_outside=<STDIN>; my $from_inside='Hey!'; tainted($from_outside); #true tainted($from_inside); #false tainted($ENV{PATH}); #true
Taintedness is for individual pieces of scalar data--some elements of an array or hash can be tainted without tainting the whole thing.tainted(($untainted1+$untainted2).$tainted); #true tainted(($untainted1+$untainted2).$untainted3); #false
So, what does this taintedness do? Here's your answer:
All of those blow up. There are other functions that blow up too, but those are the biggies.open(FH, $tainted); system($tainted); `$tainted`; eval($tainted); exec($tainted);
Tainting helps you keep track of what you're doing with data from the outside. The idea is that you don't trust anything that came from outside your program--at least not when it affects something else outside your program. After all, if $tainted were 'rm -rf /', three of those examples would have deleted all your files.
Of course, data from outside is sometimes trustable. Taint just makes you check that it's trustable. How? Well, the only way to remove a variable's taintedness is to get it out of a regular expression group.
For example, let's say I'm going to get part of a file name from the outside. I know that the only characters that should be in that part of the file name are \w characters, so I can do this:
If $file_name matches the pattern, it gets untainted, but if it doesn't, it stays tainted. If it stays tainted, you'll get a fatal error like this: Insecure dependency in open while running with -T switch at script.pl line 4. There are two very important things to remember about taint checking.if($file_name=~/^(\w+)$/) { $file_name=$1; #no longer tainted } open(FH, "> users/grades/$file_name") or die "Can't open grades for $f +ile_name: $!";
=cut
--Brent Dax
There is no sig.
In reply to Re: Moving A Web Application From Hacky To ... Less Hacky
by BrentDax
in thread Moving A Web Application From Hacky To ... Less Hacky
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |