in reply to Insecure dependency in chmod while running setuid
I think the results you get from File::Find are tainted. This is good as you don't want to have unexpected filenames and don't want to change them to (even) 664. Also, operating on $_ works, but I prefer operating on $File::Find::name, as having absolute filenames is much better in error messages. I would look at perlsec and do something like the following:
sub setperms { my $fn = $File::Find::name; my $untained_fn; my $mode; if ($fn =~ m!^(\Q$baseDir\E([/\w.]+)\z!) { $untainted_fn = $1; $mode = 0664; } else { $fn =~ m!^(.*)$!; $untainted_fn = $1; $mode = 0000; warn "File name '$untainted_fn' does not match criteria, setti +ng mode to 0."; }; chmod($untained_fn,$mode) or die "Couldn't change '$untainted_fn' +to $mode: $!"; };
Also, you should really, really consider whether you want to have any script that runs as root accessible from the outside of your computer. I recommend having that script run from a cron job and having as the CGI program a program that just appends filenames to a list.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Insecure dependency in chmod while running setuid
by afoken (Chancellor) on Jun 12, 2009 at 09:06 UTC | |
|
Re^2: Insecure dependency in chmod while running setuid
by ak4good (Initiate) on Jun 13, 2009 at 04:18 UTC |