-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Forbid SimpleHTTPRequestHandler
serving files outside of specified directory
#132142
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
Comments
As you observed, it's documented and I think it should be kept as is. Some users might want to use that for fast debugging, possibly with hacky solutions so I don't think we need to be safe here. On the other hand, we could, if needs arise, add an option that disables following symlinks but I don't know if it's worth it. I'm -0 for this one (as @gpshead wdyt? |
SimpleHTTPRequestHandler
allows serving files outside of specified directorySimpleHTTPRequestHandler
serving files outside of specified directory
I also want to add that it seems |
The discussion in that issue was quite long and I don't think it was categorized as such by a core dev. I personally don't consider this as a bug. It's known, documented and warned against.
We don't want to patch all possible security holes. Anyone using
This is a bit different. The issue here was that it was possible to send incorrect control characters into the log messages and directly affect the server without the latter being misconfigured (namely even by serving an empty directory!) There were other security issues that were patched, e.g., #87389, but this doesn't require the server to be faulty itself. Now in your example, the leakage of the secret is due to the symlink itself. Yes, it's a security issue, but this only happens if the server decides to host such files, not because an adversary is able to provide some input to the server and access files outside its root location. So for this specific one, I really don't think we need to change the existing behaviour. I'm interested in Gregory's opinion on that matter as he fixed previous security issues for |
|
I'd like to point out that this would not protect against faulty handlers who can still access files outside the server's location. In PHP, typical code subject to directory traversal attacks is: <?php
include($_GET['file']);
?> Assuming that the handler's So, maybe a Now, note that the above attack requires a faulty handler, so something on the server side that is already poorly written. So, I still want to keep the security considerations section and warn users that external files could still be accessed and that only naive directory listing is protected. |
Claiming something is "secure" adds a huge ongoing maintenance burden. This comment is ironically an example of why. Ex: If we add I don't think we should invest further in these servers. Quality http servers exist outside of the standard library. |
Also, most webservers do follow symlinks, and it's the behavior I would expect. I frequently create a folder full of symlinks to outside locations just to share all of those from one httpd. I'm not a cpython dev so this is just another outsider opinion. |
We didn't agree on this feature. And two core devs (Gregory and me) were not convinced. I prefer rejecting this feature. |
Current behavior has long been known (#54440 (comment)) and documented but it seems that leaving it is not the best solution, especially when it is easy to fix.
I suggest adding a check that the source file is not located above the current directory, otherwise return
Forbidden
.Can be reproduced by next steps:
We can implement this by adding a similar check to
SimpleHTTPRequestHandler.translate_path
method:I can send PR
The text was updated successfully, but these errors were encountered: