I've hacked together a couple of quick functions to handle untainting data in a cgi script. As I'm still fairly new to CGI, I was wondering if the fellow monks could offer some constructive criticism, specifically, are there any security problems with this (assuming I pass a proper regex)?
sub badinputerror ($) {
my $q = shift;
print $q->header('text/plain');
print <<"EOHTML";
There was an error with
your input. Please try again.
EOHTML
die "input did not pass taint checking\n";
}
sub untaint ($$$) {
my $q = shift;
my $name = shift;
my $re = shift;
my $tainted = $q->param($name);
my $untainted = undef;
$untainted = $1 if($tainted =~ m/^($re)$/);
badinputerror($q) unless($untainted);
return $untainted;
}
#
# And later on in the code, for example
#
my $username=untaint($q, 'user', "[a-zA-Z][a-zA-Z0-9_]+");
-
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.
|