-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Sanic static handler allows parent ".." directory traversal #2478
Comments
Related to #2477. I suppose this can also be exploited by using backslashes, which on Windows would be interpreted as path separators. I suggest denying any escaped slashes and plain backslashes. Processing of Python Just my 5 cents. I didn't look at the current code, and in any case this probably needs more thought for a solid implementation. |
Most browsers and HTTP clients (like cURL) will automatically apply path normalization to URLs, which includes removing dot segments. It's not really necessary to process |
|
Ok, I've given it a try and have ended up with this. Quick things to note:
|
Describe the bug
The sanic static directory code checks for
../
as a substring of paths, but it also unquotes the path, which allows a malicious user to escape outside the static folder by using..%2F
, where%2F
is the URL-escaped version of/
.Code snippet
First, a basic server called
main.py
.Then create a static file folder.
Now run the server with
python3 main.py
and:This is very surprising behavior. From a security perspective it is not critical because sanic checks that the final resolved path has a prefix with the static directory, but this allows an attacker to expose information like the name of the static file folder.
Another case where this is dangerous is if you have a middleware that only allows a user to see certain subpaths like
/static/public/**
of the/static/**
routes without authentication. Then, even without authentication, a user could visit a path like/static/public/..%2F/private/secret_content.txt
and retrieve the contents of/static/private/secret_content.txt
.Expected behavior
Sanic should not allow parent directory traversal in static folders.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: