Skip to content

Commit

Permalink
Catch .. in paths sooner.
Browse files Browse the repository at this point in the history
Most browsers are already going to handle this by 
following RFC 3986
  • Loading branch information
briandfoy committed Mar 6, 2023
1 parent 6bf246e commit 21e7a22
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Mojolicious/Plugin/DirectoryServer.pm
Expand Up @@ -59,11 +59,13 @@ sub register {
my $c = shift;
return render_file( $c, $root, $handler ) if ( -f $root->to_string() );

my $path = $root->rel_file( Mojo::Util::url_unescape( $c->req->url->path ) );
if( $path =~ m"\Q/..\E(/|\z)"n ) {
if( $c->req->url->path =~ m"\Q/..\E(/|\z)"n ) {
$c->reply->not_found;
return;
}
elsif ( -f $path ) {

my $path = $root->rel_file( Mojo::Util::url_unescape( $c->req->url->path ) );
if ( -f $path ) {
render_file( $c, $path, $handler );
}
elsif ( -d $path ) {
Expand Down

0 comments on commit 21e7a22

Please sign in to comment.