Skip to content

fix: Fix panic on a malformed server cookie#491

Draft
Pijukatel wants to merge 4 commits into
masterfrom
claude/malformed-cookie-handling-mhdccv
Draft

fix: Fix panic on a malformed server cookie#491
Pijukatel wants to merge 4 commits into
masterfrom
claude/malformed-cookie-handling-mhdccv

Conversation

@Pijukatel

Copy link
Copy Markdown
Contributor

Malformed cookies are silently ignored like in JS version.

claude and others added 4 commits June 29, 2026 11:38
`set_cookies` runs inside reqwest's cookie-store callback, a Rust callback
driven by the HTTP stack. The `.unwrap()`s on the cookie constructor and
`set_cookie` call meant a hostile/buggy server's malformed `Set-Cookie`
(bad domain/expiry that `http.cookiejar.Cookie` rejects), or a custom cookie
jar whose `set_cookie` raises, would panic and unwind across the FFI
boundary — aborting the host process instead of raising a catchable
exception.

Mirror the Node wrapper's behavior of skipping cookies the jar rejects, but
emit a Python `UserWarning` (falling back to stderr) so the dropped cookie
is surfaced rather than silently ignored.

Closes #478

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015p2biLkkRLNEs9xWyqdpby
`set_cookies` runs inside reqwest's cookie-store callback, a Rust callback
driven by the HTTP stack. The `.unwrap()`s on the cookie constructor and
`set_cookie` call meant a hostile/buggy server's malformed `Set-Cookie`
(bad domain/expiry that `http.cookiejar.Cookie` rejects), or a custom cookie
jar whose `set_cookie` raises, would panic and unwind across the FFI
boundary — aborting the host process instead of raising a catchable
exception.

Skip the offending cookie and continue, ignoring parsing errors silently to
match the Node binding's `setCookie` handling in `index.wrapper.js`.

Closes #478

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015p2biLkkRLNEs9xWyqdpby
Add a regression test (sync and async) for #478: a custom cookie jar whose
`set_cookie` raises must not abort the interpreter. The request completes,
the offending cookie is skipped, and a valid cookie in the same response is
still stored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015p2biLkkRLNEs9xWyqdpby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants