Title: Uncaught exception in `http.server` request handling (<=3.10) · Issue #103223 · python/cpython · GitHub
Open Graph Title: Uncaught exception in `http.server` request handling (<=3.10) · Issue #103223 · python/cpython
X Title: Uncaught exception in `http.server` request handling (<=3.10) · Issue #103223 · python/cpython
Description: Sending a null byte in an HTTP request path or URL triggers an uncaught ValueError in CPython 3.10 and below. Reproduction Instructions Open two terminals and do the following (requires python <=3.10; current 3.10 branch included): Termi...
Open Graph Description: Sending a null byte in an HTTP request path or URL triggers an uncaught ValueError in CPython 3.10 and below. Reproduction Instructions Open two terminals and do the following (requires python <=3....
X Description: Sending a null byte in an HTTP request path or URL triggers an uncaught ValueError in CPython 3.10 and below. Reproduction Instructions Open two terminals and do the following (requires python <...
Opengraph URL: https://github.com/python/cpython/issues/103223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Uncaught exception in `http.server` request handling (\u003c=3.10)","articleBody":"Sending a null byte in an HTTP request path or URL triggers an uncaught `ValueError` in CPython 3.10 and below.\r\n\r\n# Reproduction Instructions\r\nOpen two terminals and do the following (requires python \u003c=3.10; current 3.10 branch included):\r\n\r\nTerminal 1:\r\n```bash\r\n$ ./python -m http.server --bind 127.0.0.1\r\nServing HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...\r\n```\r\n\r\nTerminal 2:\r\n```bash\r\n$ printf 'GET \\x00 HTTP/1.1\\r\\n\\r\\n' | nc localhost 8000\r\n```\r\n\r\nTerminal 1:\r\n```\r\n----------------------------------------\r\nException occurred during processing of request from ('127.0.0.1', 56900)\r\nTraceback (most recent call last):\r\n File \"/home/bkallus/clones/cpython/Lib/socketserver.py\", line 683, in process_request_thread\r\n self.finish_request(request, client_address)\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 1304, in finish_request\r\n self.RequestHandlerClass(request, client_address, self,\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 668, in __init__\r\n super().__init__(*args, **kwargs)\r\n File \"/home/bkallus/clones/cpython/Lib/socketserver.py\", line 747, in __init__\r\n self.handle()\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 433, in handle\r\n self.handle_one_request()\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 421, in handle_one_request\r\n method()\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 672, in do_GET\r\n f = self.send_head()\r\n File \"/home/bkallus/clones/cpython/Lib/http/server.py\", line 727, in send_head\r\n f = open(path, 'rb')\r\nValueError: embedded null byte\r\n----------------------------------------\r\n```\r\n\r\nThis bug is fixed in python 3.11+, but I haven't yet figured out why. As far as I can tell, the relevant portions of `Lib/http/server.py` and `Lib/socketserver.py` remain unchanged. I think the issue boils down to catching only OSErrors, but not `ValueError`s, even though `open` can raise `ValueError`s. I would guess that this happened because the docs do not clearly state that `open(path, 'rb')` can raise a `ValueError`.\r\n\r\n# Environment:\r\nArch Linux, x86_64\r\nPython 3.10.10+","author":{"url":"https://github.com/kenballus","@type":"Person","name":"kenballus"},"datePublished":"2023-04-03T21:09:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/103223/cpython/issues/103223"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:02008518-562a-387e-6a3c-354618c6021a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8BC:43F78:29B6A21:35DAECB:6A5CB376 |
| html-safe-nonce | 5a32b0e8cfc300d54731f466250378db7109ab03fd98c54301041ab2ddf49648 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEJDOjQzRjc4OjI5QjZBMjE6MzVEQUVDQjo2QTVDQjM3NiIsInZpc2l0b3JfaWQiOiI0OTA1NDA2OTg4MDY1NDg1Njg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 339f670d669b343967f3b90bf4be22e54ca19d040a8a97c38381bd2c237f1bb5 |
| hovercard-subject-tag | issue:1652774769 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/103223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/150bba5acbda796f159d62a0de73a8f3fbb659fb65ef5dada0c3cf665e6ea9f6/python/cpython/issues/103223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/150bba5acbda796f159d62a0de73a8f3fbb659fb65ef5dada0c3cf665e6ea9f6/python/cpython/issues/103223 |
| og:image:alt | Sending a null byte in an HTTP request path or URL triggers an uncaught ValueError in CPython 3.10 and below. Reproduction Instructions Open two terminals and do the following (requires python <=3.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kenballus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width