Ovid has asked for the wisdom of the Perl Monks concerning the following question:
Here's a (modified for brevity) snippet of code from page 200 of the excellent book CGI Programming with Perl, Second Edition (note that the previous link is NOT amazon.com):
Personally, I don't see the problem with this code, aside from the lack of taint checking. In fact, the text mentions that the code is secure, but that someone may come along and modify it in a way which opens a security hole. The book recommends replacing the command that opens the pipe with the following code:my $string = $q->param( 'string' ); unless ( $string ) { error( $q, "Please enter some text." ) }; unless ( $string =~ /^[\w .!?-]+$/ ) { error( $q, "Invalid character entered." ); } local *PIPE; # This code is more secure, but still dangerous... # Do NOT use this code on a live web server!! open PIPE, "/usr/local/bin/figlet '$string' |" or die "Cannot open figlet: $!"; print $q->header( "text/plain" ); print while <PIPE>; close PIPE;
Since I have not worked with fork in the past, I am not sure exactly what happens here. Here's what I'm trying to understand:my $pid = open PIPE, "-|"; die "Cannot fork $!" unless defined $pid; unless ( $pid ) { exec FIGLET, $string or die "Cannot open pipe to figlet: $!"; }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: CGI Security and Forking
by tilly (Archbishop) on Dec 10, 2000 at 05:10 UTC | |
by Ovid (Cardinal) on Dec 11, 2000 at 22:00 UTC | |
|
Re: CGI Security and Forking
by AgentM (Curate) on Dec 10, 2000 at 04:46 UTC |