I have the following CGI script:
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
my $query = CGI->new();
my $searchterm = param('name');
my $file = "justafile.txt";
# Begin searching terms and ignoring case
my @entries = `grep -i \"$searchterm\" $file`; # Line10
chomp @entries;
# Do something
When I execute the command it gives me this
Insecure dependency in `` while running with -T switch at /foo/cgi-bin/mycode.cgi line 10.
How line 10 can be fixed?
The whole point of tainting is to ensure that unchecked input cannot be supplied to potentially unsafe functions.
In this case, your $searchterm
variable might contain unexpected input that might allow an attacker to execute arbitrary programs on your system.
Hence, you either need to:
untaint the variable by ensuring that it matches a pre-determined regexp (see @flesk's answer), at which point Perl assumes that you know what you're doing, or
don't use backticks (per @eugene y's answer).
If you're using backticks you should also specify the full path to the grep
command so that you're not depending on $PATH
.
Use the built-in grep
function, e.g.:
open my $fh, '<', $file or die $!;
my @entries = grep /$searchterm/i, <$fh>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With