Skip to content

cookie: check __Secure- and __Host- case sensitively when read from file#22085

Closed
alhudz wants to merge 1 commit into
curl:masterfrom
alhudz:cookie-prefix-case
Closed

cookie: check __Secure- and __Host- case sensitively when read from file#22085
alhudz wants to merge 1 commit into
curl:masterfrom
alhudz:cookie-prefix-case

Conversation

@alhudz

@alhudz alhudz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Repro: load a cookie file holding __secure-x (lower case, no Secure) and the name is dropped, while the identical __secure-x received over a Set-Cookie header is kept as an ordinary cookie. test2311 covers it.

Cause: parse_netscape() detected the __Secure-/__Host- name prefixes with case-insensitive curl_strnequal(), but the header path uses case-sensitive strncmp() and the 6265bis document specifies a case-sensitive match (the reason 5af0165 switched the header path). So on the file path a differently cased name was wrongly put through the prefix integrity checks.

Fix: use strncmp() on the file path too, so both paths match the prefixes case sensitively and agree with the spec. A correctly cased __Secure-/__Host- is still enforced.

Earlier I had this the other way round (making the header path case insensitive); that was wrong, the spec wants case-sensitive. Folded the coverage into test 2311 instead of a new file.

@github-actions github-actions Bot added the tests label Jun 18, 2026
@vszakats

Copy link
Copy Markdown
Member

Would it be possible to merge this test case into the recently added test 2311?

@bagder

bagder commented Jun 18, 2026

Copy link
Copy Markdown
Member

This is incorrect. See 5af0165 which made the exact opposite change for cookie spec reasons!

@bagder

bagder commented Jun 18, 2026

Copy link
Copy Markdown
Member

I think the fix should rather be to make sure file content is also parsed case sensitively.

The header path matches these prefixes case sensitively, as 5af0165
made it for cookie spec reasons, but the Netscape cookie-file path still
used a case-insensitive match. Align the file path so a differently cased
name like __secure-x is treated as an ordinary cookie instead of being
put through the prefix integrity checks.

Extended test 2311 to cover it.
@alhudz alhudz force-pushed the cookie-prefix-case branch from d408205 to 31f64c2 Compare June 18, 2026 17:09
@alhudz alhudz changed the title cookie: match __Secure- and __Host- prefixes case insensitively cookie: check __Secure- and __Host- case sensitively when read from file Jun 18, 2026
@alhudz

alhudz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

You're right, the spec wants a case-sensitive match and the header path already does that since 5af0165. I had it backwards.

Flipped it round: the file path now uses strncmp() too, so __secure-x loaded from a file is kept as an ordinary cookie and a correctly cased __Secure-/__Host- is still put through the integrity checks. Folded the case into test 2311 as you suggested and dropped the separate 2312.

@testclutch

Copy link
Copy Markdown

Analysis of PR #22085 at 31f64c25:

Test ../../tests/http/test_07_upload.py::TestUpload::test_07_31_put_10m[h3] failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@bagder bagder closed this in fdd6ba3 Jun 18, 2026
@bagder

bagder commented Jun 18, 2026

Copy link
Copy Markdown
Member

Thanks!

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

Development

Successfully merging this pull request may close these issues.

4 participants