Note that in the &incomplete sub, we no longer print the HTTP_REFERER. Some Web servers will execute a server side include that's generated from a CGI (though I understand that this isn't common). If that happens, someone could easily spoof the REFERER variable to be an SSI and enter a bogus name. Then, when the &incomplete subroutine prints it out, it will execute whatever the SSI is. Something like <!--#exec cmd="rm -fr /"--> will delete all of the files on the server that your Web server would have the rights to delete (I am assuming that it's a *nix box, and I might have the actual syntax slightly off).#!/usr/bin/perl -wT use strict; use CGI; my $query = new CGI; my $datafile = "/home/sites/www.yourname.com/users/web/mysites.txt"; use vars qw($title $location $name $url); ############ THE ACTUAL PROGRAM ############ # regex should only allow characters that you # know are acceptable. In this case a-z, A-Z, _, 0-9 # The way we're assigning $1 to $name is called "taint checking" if ($query->param('name') =~ /^(\w+)$/) { $name = $1; } else { # If we got here, there were illegal characters entered (or no cha +racter) &incomplete; } $url = &findurl; if ($url) { # Send 'em where they want to go print $query->redirect($url); } else { # No url, so do something different } ############ FIND URL ############ sub findurl { # always check the return calls on an open open INFO, "<$datafile" or die "Can't open $datafile: $!"; my @information = <INFO>; foreach (@information) { ($title, $location) = split /\|/; } if ($title eq $name) { $url = $location; } close (INFO); return $url; } sub incomplete { print $query->header, $query->start_html(-title => "Incomplete", -bgcolor => "white"), $query->h1("Form not complete"), $query->p(), $query->hr(), $query->p("Sorry, you forgot to enter something."), $query->p("Please hit the back button on your browser and tr +y again."), $query->end_html; exit; }
Please see CGI.pm and perlsec for more information on these issues.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
In reply to (Ovid) Re: Error 404 fix
by Ovid
in thread Error 404 fix
by koacamper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |