Skip to content

Protect static file routes from directory traversal attacks. #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

drgrice1
Copy link
Member

Currently using a URL like
http://baseURL/../../../../../../../../../../../../../../../../etc/passwd returns the file /etc/passwd. That of course is a security vulnerability that should not happen.

This was recently discovered and fixed for webwork2, and basically the same solution is used to fix it here.

Below is a minimal script that can be used to test this:

use Mojo::Base -strict;
use Mojo::UserAgent;

my $server = 'http://localhost:3001';

my $ua  = Mojo::UserAgent->new;
my $res = $ua->get("$server/../../../../../../../../../../../../../../../../etc/passwd")->result;

if    ($res->is_success)  { say 'success'; say $res->body }
elsif ($res->is_error)    { say 'error'; say $res->message }
elsif ($res->code == 301) { say '301'; say $res->headers->location }
else                      { say 'Whatever...' }

Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

Set $server to the URL of your renderer including the $baseURL.

With the develop branch the above script will output "success" followed by the contents of the /etc/passwd file on your server. With this branch it will output "error" followed by "Not found".

Currently using a URL like
`http://baseURL/../../../../../../../../../../../../../../../../etc/passwd`
returns the file `/etc/passwd`.  That of course is a security
vulnerability that should not happen.

This was recently discovered and fixed for webwork2, and basically the
same solution is used to fix it here.

Below is a minimal script that can be used to test this:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $server = 'http://localhost:3001';

my $ua  = Mojo::UserAgent->new;
my $res = $ua->get("$server/../../../../../../../../../../../../../../../../etc/passwd")->result;

if    ($res->is_success)  { say 'success'; say $res->body }
elsif ($res->is_error)    { say 'error'; say $res->message }
elsif ($res->code == 301) { say '301'; say $res->headers->location }
else                      { say 'Whatever...' }

Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
```

Set `$server` to the URL of your renderer including the `$baseURL`.

With the develop branch the above script will output "success" followed
by the contents of the `/etc/passwd` file on your server.  With this
branch it will output "error" followed by "Not found".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant