Skip to content

(py) set_cookies() .unwrap() panics across FFI on a malformed server Set-Cookie #478

Description

@barjin

🤖 Found by Claude ultrareview — automated high-effort code review. Please verify independently before acting.

Location: impit-python/src/cookies.rs:94 (set_cookies)

The Python cookie-constructor and set_cookie calls are .unwrap()ed:

let py_cookie = self.cookie_constructor.call(py, (), Some(&kwargs)).unwrap();
let args = PyTuple::new(py, vec![py_cookie]).unwrap();
self.cookie_jar.call_method1(py, "set_cookie", args).unwrap();

This runs inside reqwest's cookie-store callback during response handling — a Rust callback driven by the HTTP stack.

Impact: a hostile server's malformed Set-Cookie (e.g. a bad domain/expiry that http.cookiejar.Cookie rejects), or a custom cookie jar whose set_cookie raises, panics inside the callback and unwinds across the FFI boundary — an abort rather than a catchable Python exception. A crafted server response can therefore crash the host process. Note the neighboring set_item calls already use .unwrap_or_default().

Suggested direction: convert these .unwrap()s into propagated errors (or at minimum skip the offending cookie) so a malformed Set-Cookie cannot abort the process.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working.pythonThis issue is in the Python impit bindings.rustThis issue concerns the Rust part of this monorepo.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions