`http.cookies.SimpleCookie.load()` fails to consistently handle malformed cookies
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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 \x09, which is not allowed per RFC 6265, Section 4.1.1.
When this is sent to a browser (Chrome 130), the browser processes all valid cookies and filters out invalid ones:
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: a=b;
Set-Cookie: c=d d;
Set-Cookie: e=f
Resulting behavior:
> document.cookie
< 'a=b; e=f'
However, http.cookies.SimpleCookie.load() ignores the entire cookie string:
>>> from http import cookies
>>> C = cookies.SimpleCookie()
>>> C.load("a=b;c=d\x09d;e=f")
>>> C.output()
''
- Malformed cookies are inconsistently processed
Consider the cookie a=b;c={"d":"e"};f=g. The c value is invalid per RFC 6265, Section 4.1.1.
Browsers process this cookie without an issue:
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: a=b;
Set-Cookie: c={"d":"e"};
Set-Cookie: f=g
Resulting behavior:
> document.cookie
< 'a=b; c={"d":"e"}; f=g'
However, http.cookies.SimpleCookie.load() processes only the valid portion before the malformed cookie and stops entirely:
>>> from http import cookies
>>> C = cookies.SimpleCookie()
>>> C.load('a=b; c={"d":"e"}; f=g')
>>> C.output()
'Set-Cookie: a=b'
It seems we should ensure consistent handling by (a) processing all valid cookies and discarding only invalid ones, or
(b) rejecting the entire cookie string if any invalid cookie is present.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
http.cookies.SimpleCookie.load() のエントリーポイントから始め、issue にある不正な Cookie の例を 2 つとも再現してください。意図された動作が、有効な Cookie を処理して無効な Cookie を破棄することなのか、それとも文字列全体を拒否することなのかを判断してください。その動作が一貫して実装され、テストでカバーされた時点で issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100