Skip to content

cookie: refuse to load cookies set against a PSL domain - #22500

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/cookie-psl
Closed

bagder wants to merge 1 commit into
masterfrom
bagder/cookie-psl

Conversation

@bagder

@bagder bagder commented Aug 6, 2026

Copy link
Copy Markdown
Member

Verified by test 409

Reported-by: 1rhino2 on hackerone

@bagder bagder added the cookies label Aug 6, 2026
@github-actions github-actions Bot added the tests label Aug 6, 2026
@testclutch

Copy link
Copy Markdown

Analysis of PR #22500 at 3326a069:

Test 3103 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 492 different CI jobs (the link just goes to one of them).

Test 3104 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 433 different CI jobs (the link just goes to one of them).

Test 506 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 40 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@bagder
bagder requested a lite review from Copilot August 6, 2026 09:09
@bagder
bagder marked this pull request as ready for review August 6, 2026 09:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens curl’s cookie handling by rejecting cookies loaded from a cookie file when they target a Public Suffix List (PSL) domain (e.g., .co.uk), reducing the risk of cross-site cookie injection. It also refactors internal cookie APIs to pass structured flags instead of multiple booleans, and adds a regression test to verify the PSL-domain rejection behavior.

Changes:

  • Enforce PSL-domain rejection for cookies loaded from cookie files (during pre-transfer load).
  • Refactor Curl_cookie_add() and Curl_cookie_loadfiles() to use a flags bitmask (e.g., COOKIE_NOPSL, COOKIE_NOSESSION).
  • Add test 409 to validate that PSL-domain cookies from a file are refused while valid host cookies are accepted.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/data/test409 New test ensuring PSL-domain cookies from a file are rejected.
tests/data/Makefile.am Registers the new test case.
lib/transfer.c Loads cookie files with flags (session handling).
lib/setopt.c Routes COOKIELIST operations through the new cookie flags API.
lib/http.c Updates Set-Cookie processing to use the new flags API.
lib/cookie.h Introduces cookie flag macros and updates function signatures.
lib/cookie.c Implements PSL checks for file-loaded cookies and flag-based cookie parsing.
docs/libcurl/opts/CURLOPT_COOKIELIST.md Documents PSL-bypass behavior for manual cookie insertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/cookie.c
Comment thread lib/cookie.c Outdated
Comment thread lib/cookie.h Outdated
Comment thread docs/libcurl/opts/CURLOPT_COOKIELIST.md
bagder added a commit that referenced this pull request Aug 6, 2026
Verified by test 409

Reported-by: 1rhino2 on hackerone

Closes #22500
@bagder
bagder force-pushed the bagder/cookie-psl branch from 62ac381 to 73bf594 Compare August 6, 2026 09:22
@bagder
bagder requested a lite review from Copilot August 6, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (1)

lib/setopt.c:1567

  • CURLOPT_COOKIELIST "RELOAD" now calls Curl_cookie_loadfiles() with COOKIE_NOPSL only, which means it no longer honors CURLOPT_COOKIESESSION (dropping session cookies) the way the previous implementation did (cookie_loadfiles used data->set.cookiesession internally). This is a behavior regression for applications relying on COOKIESESSION + RELOAD.
  else if(curl_strequal(ptr, "RELOAD")) {
    /* reload cookies from file */
    return Curl_cookie_loadfiles(data, COOKIE_NOPSL);
  }

Verified by test 409

Reported-by: 1rhino2 on hackerone

Closes #22500
@bagder
bagder force-pushed the bagder/cookie-psl branch from 81c8fe7 to 99c8537 Compare August 6, 2026 12:44
@bagder bagder closed this in c041895 Aug 6, 2026
@bagder
bagder deleted the bagder/cookie-psl branch August 6, 2026 15:03
bagder added a commit that referenced this pull request Aug 23, 2026
The added code to avoid loading PSL cookies from files from PR #22500
(c041895, not shipped in a release), calls psl_is_public_suffix(),
returns TRUE also for "localhost" (!).

We now allow cookies again for localhost. Added test 320 to verify.

Reported-by: Athos Ribeiro
Fixes #22645
Closes #22646
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.

3 participants