-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Handling of Escaped Quotes in Cookie Values #6890
Comments
I have noticed the historical discussions on #1440, #3759, and #5459, and have written a supplementary analysis. Supplemental Analysis: Cookie Value Handling in Requests1. RFC 6265 vs. Real-World PracticesRFC 6265 defines
Notably:
However, many real-world servers (often unintentionally) generate cookie values like Requests relies on 2. Current Implementation Actively Corrupts DataRequests’ existing logic (introduced ~12 years ago) strips escaped quotes (
This behavior violates Postel’s Law (“Be conservative in what you send, liberal in what you accept”) and introduces silent data corruption in critical scenarios:
3. Industry Standards Prioritize Faithful TransmissionMajor HTTP clients (browsers,
By deviating from this norm, Requests introduces unique failure modes, forcing developers to implement brittle workarounds (e.g., double-escaping). This undermines interoperability and contradicts user expectations. 4. Proposed ResolutionWhile backward compatibility is important, data integrity is non-negotiable. We propose:
Why This Cannot WaitThe argument that “users rely on this behavior” conflates legacy inertia with intentional adoption. Most users impacted by this bug:
By contrast, the harm is concrete and escalating:
Final Appeal |
Expected Result
Legitimate escaped quotes (e.g.,
\"
) in cookie values should be preserved. For example:Input value
"159\\"687"
(actual string:159\"687
) should remain unchanged.Actual Result
Requests incorrectly replaces escaped quotes with an empty string, causing
"159\\"687"
to become"159687"
(string becomes159687
), which corrupts valid values.Reproduction Steps
Issue Analysis
The code at src/requests/cookies.py#L349-L356 has the following problem:
This logic makes incorrect assumptions about cookie value sanitization. While RFC 6265 specifies that cookie values shouldn't contain escaped characters (through its
cookie-value
definition), many real-world implementations:By forcibly stripping escaped quotes, Requests breaks values that:
Suggested Fix
Remove this non-standard cleanup logic entirely.
The text was updated successfully, but these errors were encountered: