Commit eb1f1a2
committed
Protect static file routes from directory traversal attacks.
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".1 parent 31abf57 commit eb1f1a2
1 file changed
+8
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
0 commit comments