Taint so Easy, Is It?
Randal L. Schwartz
If you've been reading my columns for any length of time, you've probably
seen me mention "taint mode", usually briefly while I'm describing a "hash-bang"
line of something like:
#!/usr/bin/perl -Tw
which turns on warnings (the -w) and "taint mode" (the -T).
But what is taint mode?
Taint mode is a security feature of Perl and includes two levels of operation.
First, while taint mode is in effect, some operations are forbidden. One of
these is that $ENV{PATH} cannot contain any world-writeable
directories when firing off a child process (like with backticks or system).
Should your program attempt an unsafe action, the program aborts immediately
(via die), before the action has a chance to create a potential
security violation. You could have included code to check this yourself, but
having Perl perform the checks ensures a consistency and a "best practices"
level of competence that you may not have the capability or resources to include
explicitly.
The second level of operation is much more interesting and unique to Perl
(amongst all the popular languages I know of), in which Perl keeps track of
a "distrust" of each scalar value in the program. Every item of data coming
from input sources (command-line arguments, environment variables, locale information,
some system calls, and all file input) is marked "tainted".
For example, the following operations all generate tainted data:
$t1 = <STDIN>;
$t2 = $ENV{USER};
$t3 = $ARGV[2];
@t4 = <*.t
|