Skip to content

Commit

Permalink
More fixes for the directory traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Dec 10, 2010
1 parent 4448aef commit ffd71d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Plack/App/File.pm
Expand Up @@ -41,6 +41,10 @@ sub locate_file {

my $path = $env->{PATH_INFO} || '';

if ($path =~ /\0/) {
return $self->return_400;
}

my $docroot = $self->root || ".";
my @path = split '/', $path;
if (@path) {
Expand Down Expand Up @@ -110,6 +114,11 @@ sub return_403 {
return [403, ['Content-Type' => 'text/plain', 'Content-Length' => 9], ['forbidden']];
}

sub return_400 {
my $self = shift;
return [400, ['Content-Type' => 'text/plain', 'Content-Length' => 11], ['Bad Request']];
}

# Hint: subclasses can override this to return undef to pass through 404
sub return_404 {
my $self = shift;
Expand Down
3 changes: 3 additions & 0 deletions t/Plack-Middleware/directory.t
Expand Up @@ -21,6 +21,9 @@ my %test = (
$res = $cb->(GET "/..");
is $res->code, 403;

$res = $cb->(GET "/..%00foo");
is $res->code, 400;

$res = $cb->(GET "/stuff../Hello.txt");
is $res->code, 200;
is $res->content, "Hello\n";
Expand Down

0 comments on commit ffd71d0

Please sign in to comment.