This one is indead
IlyaM proof :) I stared on it for 5 mins and I could not find how it can be abused ++. Anyway I'm not sure I like this approach because it is very easy to do mistakes. I would not use regexps on whole string but I'd split path on components first and then I'd use regexps on them. I.e. something like:
use URI;
my $uri = URI->new($path);
die "bad schema" unless is_safe_schema($uri->schema);
die "bad domain" unless is_safe_domain($uri->host);
die "bad path" unless is_safe_path($uri->path);
sub is_safe_schema {
# left as excersize to reader
}
sub is_safe_domain {
# left as excersize to reader
}
sub is_safe_path {
my $path = shift;
my @comps = split '/', $path;
for my $comp (@comps) {
return 0 unless is_safe_path_comp
}
return 1;
}
sub is_safe_path_comp {
my $comp = shift;
return 0 if $comp =~ /\0\\/;
return 0 if $comp eq '..';
# other unsafe patterns
....
return 1;
}
--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support
UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org
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.