in reply to Executing another Script
In terms of security, I think the three methods are equivalent (I hope others will correct me if I'm wrong):# one way: my $content = `other_script`; die "No output from other_script" unless ( $content ); # another way: open( SCR, "other_script |" ) or die "other_script failed: $!"; print while (<SCR>); close SCR; # the only other way: my $tmpfile = function_returning_uniq_name(); my $status = system( "other_script > $tmpfile" ); die "other_script failed" if ( $status or -s $tmpfile == 0 ); open( TMP, $tmpfile ) or die "WTF?? can't open $tmpfile: $!"; print <TMP>; close TMP: unlink $tmpfile;
If the name of "other_script" and any command line args that are needed are constants that you define in the source code (not derived from input CGI parameters), then there isn't much to worry about.
If the command line needs to be constructed on the basis of CGI params, then you need to be very careful about how you do this, no matter which method you use. Ideally, CGI params would only be used (via regex matches or value comparisons) to decide which script-internal, pre-defined constants -- or which server-internal, verifiable file/directory names -- should be included in the command line. If the app is supposed to allow CGI param strings to be included on the command line, apply the tightest possible untainting.
Regarding the 2nd, 3rd and 4th "alternatives" suggested in the OP, they won't work at all:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Executing another Script
by Avitar (Acolyte) on Aug 23, 2004 at 22:14 UTC |