It isn't only the security. Your line
$req = 'index' if -e $req;
will make all requests invoke
"index". Your code means " assign to 'index' if a file
named $req exists". I am not sure what you wanted to
achieve that way, but here is how I would do it.
use strict;
use warnings;
my $req = $ENV{QUERY_STRING};
# limits the applicability. Only lowercase file names
$req = lc $req;
# remove all unwanted characters from the beginning of the
string. # In this example, everything except alphanumerics
# and underscore is removed.
$req =~ s/^[^a-z_0-9]+//;
# remove an extension, if any
$req =~ s/\.html$//;
# default value is the index
my $page = "pages/index.html";
# if the page exists, then we use it
$page = "pages/$req.html" if -e "pages/$req.html" ;
Also, consider using CGI param
instead of reading the environment.
HTH
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|