Lately, I've spotted a few examples where user's haven't been parsing input before displaying in a web page (
katgirl!), allowing malicious users (ie me) to enter javascript in the inputs that then gets displayed on the web page.
Most people are aware of this, but I haven't seen a formal way of taking precautions that's globally accepted.
My thought was to create a module (CGI::Taint) that when used, overloaded print to add taint checks to items sent to it - currently, print is ignored as a factor in untainting data.
I'm not 100% sure this is the best approach, but would something like the following work?
use CGI;
use CGI::Taint;
my $q=CGI->new();
my $tainted_var = $q->param('form_input');
# first case - dies to browser with
# "attempt to print tainted var at line 10"
print $q->header.
"Tainted: $tainted_var";
exit(0);
# second case - no error
my $untainted_var = '';
$tainted_var =~ /(\w\s+)/ and $untainted_var=$1;
print $q->header.
"Untainted: $untainted_var";
exit(0);
So, my questions are (I guess):
- is this the right approach
- is it feasible, given how complicted CGI.pm is?
If it could work, I don't think it would ba that much work, or are there other functions that would need overloading too? printf?
Hmmm. Thoughts welcomed.
cLive ;-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.