S
Steve
Hi all, please excuse the long post, but this is the longest perl
script I've ever written. My main concern is with untainting data and
using backtics for system commands. I read most of the documentation,
but confess the perlsec leaves me a little confused as to the best way
to write to files, etc.
I'm using -Tw on the shabang line, plus "use strict"
I threw this in, but I am not sure if it is neccessary:
$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
I'm only using mkdir, open and rm with user input.
Here's my untaint routines:
-------------------
if ($pairs{affilate_ID} =~ /^([-_\w.\s]+)$/) { $pairs{affilate_ID} =
$1 }
else { bad_data_in_affilate_ID () }
if ($pairs{general_theme} =~ /^([-_\w.\s]+)$/) { $pairs{general_theme}
= $1 }
else { bad_data_in_theme () }
my @untainted_keywords = split(/\, /, $pairs{keywords});
my $untainted_keyword;
for $untainted_keyword (@untainted_keywords) {
if ($untainted_keyword =~ /^([-_\w.\s]+)$/) { $untainted_keyword = $1
}
else { bad_data_in_keywords () }
}
-------------------
most of my commands to create directories, files and to remove files
are with backtics, and I've untainted all the data....so have I
covered all the bases or should I understand more about the perlsec
and shell vs system calls...esp this example:
use English '-no_match_vars';
die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
if ($pid) { # parent
while (<KID>) {
# do something
}
close KID;
} else {
my @temp = ($EUID, $EGID);
my $orig_uid = $UID;
my $orig_gid = $GID;
$EUID = $UID;
$EGID = $GID;
# Drop privileges
$UID = $orig_uid;
$GID = $orig_gid;
# Make sure privs are really gone
($EUID, $EGID) = @temp;
die "Can't drop privileges"
unless $UID == $EUID && $GID eq $EGID;
$ENV{PATH} = "/bin:/usr/bin"; # Minimal PATH.
# Consider sanitizing the environment even more.
exec 'myprog', 'arg1', 'arg2'
or die "can't exec myprog: $!";
}
Thanks very much for any replys,
Steve
script I've ever written. My main concern is with untainting data and
using backtics for system commands. I read most of the documentation,
but confess the perlsec leaves me a little confused as to the best way
to write to files, etc.
I'm using -Tw on the shabang line, plus "use strict"
I threw this in, but I am not sure if it is neccessary:
$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
I'm only using mkdir, open and rm with user input.
Here's my untaint routines:
-------------------
if ($pairs{affilate_ID} =~ /^([-_\w.\s]+)$/) { $pairs{affilate_ID} =
$1 }
else { bad_data_in_affilate_ID () }
if ($pairs{general_theme} =~ /^([-_\w.\s]+)$/) { $pairs{general_theme}
= $1 }
else { bad_data_in_theme () }
my @untainted_keywords = split(/\, /, $pairs{keywords});
my $untainted_keyword;
for $untainted_keyword (@untainted_keywords) {
if ($untainted_keyword =~ /^([-_\w.\s]+)$/) { $untainted_keyword = $1
}
else { bad_data_in_keywords () }
}
-------------------
most of my commands to create directories, files and to remove files
are with backtics, and I've untainted all the data....so have I
covered all the bases or should I understand more about the perlsec
and shell vs system calls...esp this example:
use English '-no_match_vars';
die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
if ($pid) { # parent
while (<KID>) {
# do something
}
close KID;
} else {
my @temp = ($EUID, $EGID);
my $orig_uid = $UID;
my $orig_gid = $GID;
$EUID = $UID;
$EGID = $GID;
# Drop privileges
$UID = $orig_uid;
$GID = $orig_gid;
# Make sure privs are really gone
($EUID, $EGID) = @temp;
die "Can't drop privileges"
unless $UID == $EUID && $GID eq $EGID;
$ENV{PATH} = "/bin:/usr/bin"; # Minimal PATH.
# Consider sanitizing the environment even more.
exec 'myprog', 'arg1', 'arg2'
or die "can't exec myprog: $!";
}
Thanks very much for any replys,
Steve