Title: HTTP request smuggling via misinterpretation of bare CR as header field terminator · Issue #114782 · python/cpython · GitHub
Open Graph Title: HTTP request smuggling via misinterpretation of bare CR as header field terminator · Issue #114782 · python/cpython
X Title: HTTP request smuggling via misinterpretation of bare CR as header field terminator · Issue #114782 · python/cpython
Description: Bug report Bug description: The stdlib HTTP parser treats \r as equivalent to \r\n when parsing header field lines. This means that, in the following payload, the Python HTTP parser will see two headers; Visible and Smuggled: GET / HTTP/...
Open Graph Description: Bug report Bug description: The stdlib HTTP parser treats \r as equivalent to \r\n when parsing header field lines. This means that, in the following payload, the Python HTTP parser will see two he...
X Description: Bug report Bug description: The stdlib HTTP parser treats \r as equivalent to \r\n when parsing header field lines. This means that, in the following payload, the Python HTTP parser will see two he...
Opengraph URL: https://github.com/python/cpython/issues/114782
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"HTTP request smuggling via misinterpretation of bare CR as header field terminator","articleBody":"# Bug report\n\n### Bug description:\n\nThe stdlib HTTP parser treats `\\r` as equivalent to `\\r\\n` when parsing header field lines. This means that, in the following payload, the Python HTTP parser will see two headers; `Visible` and `Smuggled`:\n```\nGET / HTTP/1.1\\r\\n\nVisible: :/\\rSmuggled: :)\\r\\n\n\\r\\n\n```\nA standards-compliant HTTP server will either convert the bare `\\r` to a single space character, and therefore see only one header, or reject the message as invalid.\n\nUnfortunately, some HTTP proxy servers don't do this translation, and simply allow bare `\\r` within header values. If a server using the CPython stdlib HTTP parser is deployed behind such a proxy, then it is vulnerable to header injection, and subsequent request smuggling.\n\nTo confirm the bug for yourself:\n```sh\ncat \u003c\u003cEOF > repro.py\nfrom wsgiref.simple_server import make_server\n\n\ndef app(environ, start_response) -> list[bytes]:\n response_body: bytes = b\"\".join(k.encode(\"latin1\") + b\": \" + environ[k].encode(\"latin1\") + b\"\\n\" for k in environ if k.startswith(\"HTTP_\"))\n start_response(\n \"200 OK\", [(\"Content-type\", \"application/json\"), (\"Content-Length\", f\"{len(response_body)}\")]\n )\n return [response_body]\n\n\nif __name__ == \"__main__\":\n with make_server('127.0.0.1', 8000, app) as httpd:\n httpd.default_request_version = \"HTTP/1.1\"\n httpd.serve_forever()\nEOF\npython3 repro.py &>/dev/null &\nprintf 'GET / HTTP/1.1\\r\\nVisible: :/\\rSmuggled: :)\\r\\n\\r\\n' | nc localhost 8000\n```\nYou should see the following output, indicating that `\\r` was interpreted as a line ending:\n```\nHTTP/1.0 200 OK\nDate: Wed, 31 Jan 2024 05:46:12 GMT\nServer: WSGIServer/0.2 CPython/3.13.0a3+\nContent-type: application/json\nContent-Length: 35\n\nHTTP_VISIBLE: :/\nHTTP_SMUGGLED: :)\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-162397\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/kenballus","@type":"Person","name":"kenballus"},"datePublished":"2024-01-31T05:47:04Z","url":"https://github.com/python/cpython/issues/114782"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:e275f0fb-1512-61b9-99c6-c63ef1572f1a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1AE:2E7EBB:394DC37:48916CF:6B01EC34 |
| html-safe-nonce | 7a883e7bcb67ee472bdb4d5be74f49c0f46871b6a71ebdf5ab7ed11b4dca6e76 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUFFOjJFN0VCQjozOTREQzM3OjQ4OTE2Q0Y6NkIwMUVDMzQiLCJ2aXNpdG9yX2lkIjoiNTU1MDQ3ODIwMjI1NTgzMDA2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4d44e2e8fb1f00c9abc2e36851e2caad2e0c83431b3576041b1558f2abec134f |
| hovercard-subject-tag | issue:2109330735 |
| 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/114782/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b102f40545e71a588115ea70f76cd5c80a21fad76c41004169f1e7c8b909a4f/python/cpython/issues/114782 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b102f40545e71a588115ea70f76cd5c80a21fad76c41004169f1e7c8b909a4f/python/cpython/issues/114782 |
| og:image:alt | Bug report Bug description: The stdlib HTTP parser treats \r as equivalent to \r\n when parsing header field lines. This means that, in the following payload, the Python HTTP parser will see two he... |
| 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 | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width