Skip to content

Keep Secure and HttpOnly when overwriting cookies. - #501

Open
Cherith1222 wants to merge 1 commit into
Pylons:mainfrom
Cherith1222:fix/417-samesite-none-overwrite
Open

Cherith1222 wants to merge 1 commit into
Pylons:mainfrom
Cherith1222:fix/417-samesite-none-overwrite

Conversation

@Cherith1222

@Cherith1222 Cherith1222 commented Oct 7, 2026 •

Copy link
Copy Markdown

Fixes #417.

Response.set_cookie(..., overwrite=True) reloaded existing Set-Cookie headers and dropped the valueless Secure and HttpOnly flags. Overwriting a cookie beside SameSite=None then raised ValueError, and other cookies lost those flags.

Tests, on Windows with Python 3.13 and legacy-cgi, PYTHONPATH=src, via Resource Sentinel (1 CPU, 1.5 GiB, 1 I/O):

  • With src/webob/cookies.py checked out at main, test_set_cookie_overwrite_keeps_secure_and_httponly failed with ValueError: Incompatible cookie attributes: when the samesite equals 'none', then the secure must be True.

  • On this commit the same test passed (1 passed, 178 deselected).

  • black --check and isort --check-only passed on src/webob/cookies.py and tests/test_response.py.

Not run: the tox matrix, other Python versions, and anything other than Windows.

CHANGES.txt has a Bugfix note for this. There is no pull request template.

Drafted with Cursor. Cherith reviewed this diff and confirmed it with the person who helped draft it. There is no Co-authored-by or Signed-off-by trailer.

Reloading Set-Cookie dropped valueless flags, so SameSite=None raised ValueError and other cookies lost Secure or HttpOnly.

AI-assisted (Cursor). Not yet reviewed by a human.
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.

Error overwriting cookie when secure=True, samesite='none' set

1 participant