in reply to
Re: Re: Re: Re: Re: Re: Re: How Internet is a mess. (Playing with HTTPD)
in thread How Internet is a mess. (Playing with HTTPD)
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