Skip to content

[py] Align _cookie_matches domain and path matching with RFC 6265 - #18238

Merged
cgoldberg merged 3 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:fix-cookie-matches-rfc6265
Oct 25, 2026
Merged

cgoldberg merged 3 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:fix-cookie-matches-rfc6265

Conversation

@saiyam-jain-dev

@saiyam-jain-dev saiyam-jain-dev commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR addresses two RFC 6265 compliance issues in _cookie_matches in selenium.webdriver.common.api_request_context:

Description

This PR addresses two RFC 6265 compliance issues in _cookie_matches in selenium.webdriver.common.api_request_context:

  1. Domain matching without leading dot & case insensitivity (RFC 6265 ?5.1.3):

    • Per RFC 6265 ?4.1.2.3 and ?5.1.3, an optional leading dot on a domain attribute is ignored and domain matching applies to subdomains regardless of whether a leading dot is present (e.g. domain="example.com" matches sub.example.com). Previously, cookies with domain="example.com" only matched example.com exactly.
    • Domain matching is case-insensitive. Cookie domains and request hostnames are now lowercased before comparison.
  2. Path matching with trailing slash (RFC 6265 ?5.1.4):

    • When a cookie's path has a trailing slash (e.g., path="/docs/"), subpaths like path="/docs/page" previously failed because _cookie_matches tested path.startswith(cookie_path + "/") (which evaluated to "/docs//", causing a false mismatch). We now check if cookie_path.endswith("/") and path.startswith(cookie_path) before appending a slash.

Motivation and Context

Ensures APIRequestContext accurately matches browser cookies according to RFC 6265 specification, preventing cookies from being dropped on subdomain or subpath requests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@selenium-ci selenium-ci added the C-py Python Bindings label Oct 25, 2026
@CLAassistant

CLAassistant commented Oct 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

1. In domain matching, strip any optional leading dot per RFC 6265 §5.1.3
   so cookies with domain 'example.com' match subdomains (e.g. sub.example.com).
2. Canonicalize cookie domain and request hostname to lowercase for
   case-insensitive domain matching.
3. In path matching, handle cookie paths with trailing slashes (e.g. /docs/)
   so that subpaths (e.g. /docs/page) match correctly instead of attempting
   a prefix match against double slashes (/docs//).
@saiyam-jain-dev
saiyam-jain-dev force-pushed the fix-cookie-matches-rfc6265 branch from 88e3705 to 38efcb9 Compare October 25, 2026 06:48
@cgoldberg
cgoldberg self-requested a review October 25, 2026 15:41
@cgoldberg

cgoldberg commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

this branch failed the formatter and linter. I just pushed a commit to it that fixes formatting and simplifies one line of code so it passes: bc65d1e

@cgoldberg cgoldberg self-assigned this Oct 25, 2026

@cgoldberg cgoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍
thanks

@cgoldberg
cgoldberg merged commit e21558f into SeleniumHQ:trunk Oct 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants