summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorMichael Felt <aixtools@users.noreply.github.com>2018-12-26 05:43:42 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-12-26 05:43:42 (GMT)
commit2062a20641febad5eb9c18d74e1cfb4d7a6e53ed (patch)
treee1da7d77317cc4428315cacf26ed30a1f64d6d3f /Lib/http
parent22462da70c1ae015a60a7b821547bc6d2b5bc265 (diff)
downloadcpython-2062a20641febad5eb9c18d74e1cfb4d7a6e53ed.zip
cpython-2062a20641febad5eb9c18d74e1cfb4d7a6e53ed.tar.gz
cpython-2062a20641febad5eb9c18d74e1cfb4d7a6e53ed.tar.bz2
bpo-34711: Return HTTPStatus.NOT_FOUND if path.endswith('/') and not a directory (GH-9687)
AIX allows a trailing slash on local file system paths, which isn't what we want in http.server. Accordingly, check explicitly for this case in the server code, rather than relying on the OS raising an exception. Patch by Michael Felt.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 22d865f..29c720e 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -692,6 +692,14 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
else:
return self.list_directory(path)
ctype = self.guess_type(path)
+ # check for trailing "/" which should return 404. See Issue17324
+ # The test for this was added in test_httpserver.py
+ # However, some OS platforms accept a trailingSlash as a filename
+ # See discussion on python-dev and Issue34711 regarding
+ # parseing and rejection of filenames with a trailing slash
+ if path.endswith("/"):
+ self.send_error(HTTPStatus.NOT_FOUND, "File not found")
+ return None
try:
f = open(path, 'rb')
except OSError: