Title: `http.cookies.SimpleCookie.load()` fails to consistently handle malformed cookies · Issue #127195 · python/cpython · GitHub
Open Graph Title: `http.cookies.SimpleCookie.load()` fails to consistently handle malformed cookies · Issue #127195 · python/cpython
X Title: `http.cookies.SimpleCookie.load()` fails to consistently handle malformed cookies · Issue #127195 · python/cpython
Description: Bug report Bug description: There are several issues with http.cookies.SimpleCookie.load() that deviate from current browser behavior: Malformed cookies are not processed at all Consider the cookie a=b;c=d\x09d;e=f. The e value contains ...
Open Graph Description: Bug report Bug description: There are several issues with http.cookies.SimpleCookie.load() that deviate from current browser behavior: Malformed cookies are not processed at all Consider the cookie...
X Description: Bug report Bug description: There are several issues with http.cookies.SimpleCookie.load() that deviate from current browser behavior: Malformed cookies are not processed at all Consider the cookie...
Opengraph URL: https://github.com/python/cpython/issues/127195
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`http.cookies.SimpleCookie.load()` fails to consistently handle malformed cookies","articleBody":"# Bug report\n\n### Bug description:\n\nThere are several issues with `http.cookies.SimpleCookie.load()` that deviate from current browser behavior:\n\n1. Malformed cookies are not processed at all\n\nConsider the cookie `a=b;c=d\\x09d;e=f`. The `e` value contains `\\x09`, which is not allowed per [RFC 6265, Section 4.1.1](https://www.rfc-editor.org/rfc/rfc6265#section-4.1.1).\n\nWhen this is sent to a browser (Chrome 130), the browser processes all valid cookies and filters out invalid ones:\n```\nHTTP/1.1 200 OK\nContent-Type: text/html\nSet-Cookie: a=b;\nSet-Cookie: c=d\td;\nSet-Cookie: e=f\n```\nResulting behavior:\n```\n> document.cookie\n\u003c 'a=b; e=f'\n```\nHowever, `http.cookies.SimpleCookie.load()` ignores the entire cookie string:\n```\n>>> from http import cookies\n>>> C = cookies.SimpleCookie()\n>>> C.load(\"a=b;c=d\\x09d;e=f\")\n>>> C.output()\n''\n```\n2. Malformed cookies are inconsistently processed\n\nConsider the cookie `a=b;c={\"d\":\"e\"};f=g`. The `c` value is invalid per [RFC 6265, Section 4.1.1](https://www.rfc-editor.org/rfc/rfc6265#section-4.1.1).\n\nBrowsers process this cookie without an issue:\n```\nHTTP/1.1 200 OK\nContent-Type: text/html\nSet-Cookie: a=b;\nSet-Cookie: c={\"d\":\"e\"};\nSet-Cookie: f=g\n```\nResulting behavior:\n```\n> document.cookie\n\u003c 'a=b; c={\"d\":\"e\"}; f=g'\n```\nHowever, `http.cookies.SimpleCookie.load()` processes only the valid portion before the malformed cookie and stops entirely:\n```\n>>> from http import cookies\n>>> C = cookies.SimpleCookie()\n>>> C.load('a=b; c={\"d\":\"e\"}; f=g')\n>>> C.output()\n'Set-Cookie: a=b'\n```\n\nIt seems we should ensure consistent handling by (a) processing all valid cookies and discarding only invalid ones, or\n(b) rejecting the entire cookie string if any invalid cookie is present.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_","author":{"url":"https://github.com/moonsikpark","@type":"Person","name":"moonsikpark"},"datePublished":"2024-11-23T13:08:06Z","url":"https://github.com/python/cpython/issues/127195"}
| 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:04d767e2-d813-3871-5b58-f9a0602af891 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8100:1FAE:11ABA3E:17A3391:6B021B70 |
| html-safe-nonce | d9348e2c4e2394a1bad3ea7eadd896e2284315228ef102d033f8504b3b456a0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTAwOjFGQUU6MTFBQkEzRToxN0EzMzkxOjZCMDIxQjcwIiwidmlzaXRvcl9pZCI6Ijg2Mzc0MzczMDU3NTEyMTQ5NjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6ed460f0fad8e85a892a76a83f6fdd416e793e30b6e906aa9a562858439030e6 |
| hovercard-subject-tag | issue:2685999514 |
| 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/127195/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d85d341c989c4f478cf226eedf971b721b57645cdc0a74d02f60b6b380bbc2e/python/cpython/issues/127195 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d85d341c989c4f478cf226eedf971b721b57645cdc0a74d02f60b6b380bbc2e/python/cpython/issues/127195 |
| og:image:alt | Bug report Bug description: There are several issues with http.cookies.SimpleCookie.load() that deviate from current browser behavior: Malformed cookies are not processed at all Consider the cookie... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | moonsikpark |
| 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