Ben said:
Quoth (e-mail address removed):
USE TAINT MODE.
#!/usr/bin/perl -T
This would have caught the error you noticed for yourself.
Ben
ok, I read perlsec and did a little testing...
------------------
#!/usr/bin/perl -T
my $a = 'perl';
`perldoc $a`;
------------------
me> perl -c test.pl
Perl> Too late for "-T" option at test.pl line 1.
(what does that mean?)
me> ./test.pl
Perl> Insecure $ENV{PATH} while running with -T switch at ./test.pl line 4.
(ok, this is useful and expected)
now test the CGI program with -T...with the protective regex
screening removed...
------------------------------------------
#!/usr/bin/perl -T
use CGI qw

standard);
if (param('display'))
{
if (my $doc = param('docname'))
{
$a = `perldoc $doc`; #this is the dangerous line
$a = 'not found' if not $a;
}
else
{
$a = 'invalid perldoc name';
}
}
print header(), start_html();
print start_form(), p('Type name of perldoc'),
p(textfield(-name=>'docname')),
p(submit(-name=>'display')),
end_form();
print pre($a), end_html();
-------------------------------------------
me> ./testcgi.pl
Perl> Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><title>Untitled Document</title>
</head><body><form method="post" action="/./pd.bak"
enctype="application/x-www-form-urlencoded">
<p>Type name of perldoc</p><p><input type="text"
name="docname" /></p><p><input type="submit" name="display"
value="display" /></p><div></div></form><pre /></body></html>
ok, no error from the -T this time although it is equally insecure.
Actually, more so since the entire world now has access to it via
the web (not that Perl should be aware of that fact). Is that correct
that Perl will not pick up a taint problem in this case? I know that it
is not secure because I was able to enter commands and make them run before
adding a screening regex statement.
Thanks for any help.
wana