-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
StaticRoute is vulnerable to directory traversal attacks #380
Comments
Good point! |
Fixed by #383 |
Hi @asvetlov, I don't know if it's in your plans, however, I suggest to publish a new release: even if it's a better practice for now to serve static files via Nginx, I'm pretty sure that somebody somewhere use that on production. |
NP. Published 0.16.3 release. |
Thank you ;-) |
Hi. There is a problem in the way
StaticRoute
class tries to prevent directory traversal attacks.Currently it obtains the full file path by gluing the base directory with the requested path via
os.path.join
, and then checks if".."
is in the resulting path -- if there is, the path is rejected, otherwise, it is accepted. Here's the relevant code (taken from here):Unfortunately,
os.path.join
has a quirk: if it determines that it's second argument is an absolute path, it will ignore the first argument completely, and only return the second one, so iffilename
above is an absolute path,filepath
will just be this path. Therefore, the code above does not protect against directory traversal attacks.Here's a simple proof of concept:
Run this program and direct your browser to one of these addresses (depending on which OS you're using):
... and you'll obtain data which you should not be able to see.
OK, so there doesn't seem to be a single widely accepted way to sanitize relative paths; for example Django does this whole dance, while Bottle only does this. Both approaches seem to fix the current problem, so I ask you to adopt something of this sort.
The text was updated successfully, but these errors were encountered: