-
-
Notifications
You must be signed in to change notification settings - Fork 16.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
static_file endpoint doesn't love null byte #1761
Comments
I don't think NULs are acceptable in any paths since the functions dealing with paths expect NUL-terminated strings in the C APIs. In any case, I'd raise a |
Nullbyte should raise a 400 Bad Request since they're invalid characters in filenames. |
hm.. are they disallowed in URLs? if yes 400 makes more sense indeed. otherwise i'd go for 404 since it's none of the client's business whether the file is loaded from the filesystem (where NUL is disallowed) or somewhere else (where it might be valid) |
I guess 404 is also a solution. Anyway, this should be implemented by catching ValueError from the |
I can make a pull-request but what is the best way to return a 400 inside flask/helpers? abort? |
check existing code, but you could import |
Fixed in above pull request; this issue should be closed. |
Hello,
while fuzzing my API, I think I've discovered a Flask issue. The static_file endpoint generate a 500 if the filename include a null byte (
\x00
).Here is a minimal flask application:
I've tried launching it with either python 2 (2.7.11) or python 3 interpreter (3.5.1) with flask 0.10.1, then make this request:
I get a 500, here is the traceback for python2:
And here is the traceback for python 3:
The error is not exactly the same but isfile doesn't seems to love null bytes.
I've tried to fix it locally by adding this piece of code to detect null bytes in
send_static_file
(https://github.com/mitsuhiko/flask/blob/master/flask/helpers.py#L862):It seems to works with both python2 and python3, but I'm not sure what is the best response when the request include a null byte.
Here is the output of pip freeze if necessary:
I only tried on Mac OS X 10.11.4, I don't know if null byte are accepted in valid filename on other filesystems.
The text was updated successfully, but these errors were encountered: