-
Notifications
You must be signed in to change notification settings - Fork 22
When serving files, access to entire filesystem is possible #61
Comments
Hi! I can take this up |
Hi by initial ../ did you mean ones before the first directory, or all of them because directory traversal can also happen with requests like this GET /public/../../main.cpp HTTP/1.1 |
I had meant
|
Yes ideally it should only reject paths outside of the public folder and not just outright ban .. in the requested path. A method along these lines may be suitable for detecting bad paths simply parse each token between a pair of / if its a .. sub one from depth else add 1 to depth, if depth < 0 we have gone behind the file root |
That's quite close to what I'm thinking of. I think we should do something a little more sophisticated, and attempt to resolve the path, so that, for example: It could use the same state machine you describe, only instead of incrementing or decrementing an int, it is pushing and popping paths from a stack. So: See a Then iterate over the stack, concatenating what paths remain with |
At any point, if we encounter a |
Yeah, we can totally shortcut in that case. |
This is a security vulnerability exposed by the built-in file serving helper function
router::serve_files()
. It allows attackers to craft requests that begin with/..
, which means they can read arbitrary files in the filesystem.For example, run the following program from your home directory in OS X:
then in the terminal
and issue the following HTTP request
And you will get the contents of
/etc/passwd
. No good.Fix: Make
router::serve_files()
a bit smarter, by filtering out any initial..
in the path requested.The text was updated successfully, but these errors were encountered: