Skip to content

Fix cookie unquoting regression #11173

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

Merged
merged 5 commits into from
Jun 10, 2025
Merged

Fix cookie unquoting regression #11173

merged 5 commits into from
Jun 10, 2025

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jun 10, 2025

What do these changes do?

This PR fixes a regression I introduced when vendoring SimpleCookie - I accidentally copied the wrong _unquote function. The correct implementation from Python's http.cookies module is now vendored, which properly handles:

  • Octal escape sequences in cookie values (e.g., \012 for newline, \011 for tab)
  • Escaped quotes (\") and backslashes (\\)
  • All edge cases that the standard library handles

Comprehensive tests have been added to ensure the vendored function behaves identically to SimpleCookie's implementation.

Are there changes in behavior for the user?

Cookie parsing will now correctly handle cookies with octal escape sequences in their values, restoring compatibility with servers that send such cookies. This fixes a regression where these cookies were not being decoded properly.

Is it a substantial burden for the maintainers to support this?

No. This is a straightforward vendoring of a stable function from Python's standard library that has remained unchanged for years. The implementation is well-tested and matches Python's cookie handling behavior exactly. The comprehensive test suite ensures any future changes will be caught.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@bdraco bdraco added backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot backport-3.13 Trigger automatic backporting to the 3.13 release branch by Patchback robot labels Jun 10, 2025
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jun 10, 2025
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.86%. Comparing base (8795da3) to head (c1f1556).
Report is 8 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11173   +/-   ##
=======================================
  Coverage   98.85%   98.86%           
=======================================
  Files         131      131           
  Lines       42966    43010   +44     
  Branches     2314     2316    +2     
=======================================
+ Hits        42476    42520   +44     
  Misses        340      340           
  Partials      150      150           
Flag Coverage Δ
CI-GHA 98.75% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.47% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.80% <100.00%> (-0.01%) ⬇️
OS-macOS 97.70% <100.00%> (-0.01%) ⬇️
Py-3.10.11 97.34% <100.00%> (-0.01%) ⬇️
Py-3.10.17 97.84% <100.00%> (+<0.01%) ⬆️
Py-3.11.12 98.02% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.54% <100.00%> (-0.01%) ⬇️
Py-3.12.10 98.40% <100.00%> (+<0.01%) ⬆️
Py-3.13.3 98.39% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.23% <100.00%> (-0.01%) ⬇️
Py-3.9.22 97.71% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 86.12% <100.00%> (-11.20%) ⬇️
VM-macos 97.70% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.47% <100.00%> (+<0.01%) ⬆️
VM-windows 96.80% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Jun 10, 2025

CodSpeed Performance Report

Merging #11173 will not alter performance

Comparing cookie_unquoting_regression (c1f1556) with master (8795da3)

Summary

✅ 59 untouched benchmarks

@bdraco bdraco marked this pull request as ready for review June 10, 2025 02:40
@bdraco bdraco requested review from webknjaz and asvetlov as code owners June 10, 2025 02:40
@bdraco bdraco merged commit 85b0df4 into master Jun 10, 2025
64 of 69 checks passed
@bdraco bdraco deleted the cookie_unquoting_regression branch June 10, 2025 02:49
Copy link
Contributor

patchback bot commented Jun 10, 2025

Backport to 3.12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.12/85b0df43bf99aeb1b5258aecae19d40a16ac273e/pr-11173

Backported as #11179

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 10, 2025
Copy link
Contributor

patchback bot commented Jun 10, 2025

Backport to 3.13: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.13/85b0df43bf99aeb1b5258aecae19d40a16ac273e/pr-11173

Backported as #11180

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 10, 2025
bdraco added a commit that referenced this pull request Jun 10, 2025
bdraco added a commit that referenced this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot backport-3.13 Trigger automatic backporting to the 3.13 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant