Skip to content

fix(browser): decode Chromium SameSite storage values (135 cookies silently lost per profile) - #20076

Merged
brennanb2025 merged 3 commits into
mainfrom
fix/chromium-samesite-enum-decode
Sep 11, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
fix/chromium-samesite-enum-decode

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Orca decodes Chromium's stored SameSite integer with a numbering that does not exist. chromiumSameSite() read 1=None, 2=Lax, 3=Strict, citing an enum called CookieSameSiteForStorage.

That enum is an invention. A code search for the name returns zero Chromium hits — every hit is Orca's own comment or a fork of it. The real symbol is DBCookieSameSite, and Chromium stores net::CookieSameSite values unchanged:

// net/cookies/cookie_constants.h
UNSPECIFIED = -1, NO_RESTRICTION = 0, LAX_MODE = 1, STRICT_MODE = 2,
// Reserved 3 (was EXTENDED_MODE)

net/extras/sqlite/sqlite_persistent_cookie_store.cc confirms the storage encoding is an identity mapping, with the deprecated 3 folded to UNSPECIFIED. So Orca's table was off by one, and only UNSPECIFIED decoded correctly — by accident, via the default arm.

What that does, measured against a real 1,743-cookie Chrome profile

raw Chromium Orca decoded rows
-1 Unspecified unspecified 481 ✓
0 None unspecified 919 — narrowed, silently breaks cross-site
1 Lax None 138 widened
1, not Secure Lax None 135 — import REJECTED, 35 sites
2 Strict Lax 70 widened

Only 27.6% decoded correctly.

The 135 are the worst case, and they fail through a complete chain:

  1. chromiumSameSite(1) → no_restriction
  2. cdpSameSite('no_restriction') → 'None'
  3. the write URL is built as http://… because the cookie is not Secure (browser-cookie-import-policy.ts:201)
  4. so CDP's secure = secure || source_url.SchemeIsCryptographic() (network_handler.cc:453) does not fire
  5. CookieBase::IsSetPermittedInContext excludes it — EXCLUDE_SAMESITE_NONE_INSECURE (cookie_base.cc:372)
  6. the reply is {"success": false} and the write throws

The cookie is lost, not altered. This is a real user-facing failure: a reporter could not log in to a site via cookie import while the same import worked in another browser. That site's auth cookie is exactly this shape — samesite=1, secure=0, httpOnly.

Fix

Delete chromiumSameSite. Rename the already-correct firefoxSameSite to databaseSameSite and share it.

Both databases genuinely use 0=None, 1=Lax, 2=Strict — the comment's claim that they differ was itself the defect. Correcting the table in place would have left the invented numbering recoverable from history; collapsing to one decoder makes it unrepresentable, because there is no longer a second function that could disagree.

The browser-cookie-firefox-import.ts change in this diff is only the call-site update that collapsing requires — not a second fix.

Second, required change: browser-cookie-chromium-scan.ts read Number(sourceRow.samesite ?? 0). Under the old wrong table 0 fell through to unspecified — harmless. Under the corrected table 0 means None, so a NULL column would start minting SameSite=None cookies needing Secure — reproducing the very failure being fixed. The default is now -1. Without this, the fix relocates the bug instead of removing it.

No version guard: 0/1/2 have been stable since Chrome 51 and -1 since Chrome 76, and the absent-column fallback covers older firstpartyonly-era schemas.

Behaviour changes beyond the headline fix

The 135 recovered cookies are not the largest delta. Every category whose decoded SameSite changes, against the measured 1,743-cookie distribution:

Category Share Before → after Effect
raw 0, Secure 919 (53%) unspecified → None The dominant change. Over half the jar was effectively Lax-by-default inside Orca and is now cross-site-sendable again. Restores source-browser semantics; SSO and embedded flows that quietly failed will start working.
raw 1, not Secure 135 (7.7%) lost → Lax The headline fix.
raw 1, Secure 138 (0.2% of changed) None → Lax Narrowing, back to source semantics.
raw 2 70 (4%) Lax → Strict Narrowing. Top-level cross-site navigations stop sending these.
raw 3 0 observed Strict → unspecified Matches Chromium's own deprecated-EXTENDED fold.

All are a return to what the source browser actually stored, but the raw 0 row is the one users may notice, and the raw 2 row removes an accidental widening someone could be relying on.

Also disclosed: normalizeSameSite's numeric branch shares this decoder, so the JSON file-import path changes too — {sameSite: 1} previously meant None and now means Lax. This is the correct direction (the only real numeric producers are database-integer dumps; extensions, CDP and Puppeteer all emit strings), but it is a second behaviour change and is not currently pinned by a test.

Proof

A real-Electron end-to-end test imports a synthetic Chrome-shaped DB and asserts seven valid raw × Secure combinations land with exact SameSite and authored Secure. The Pulley shape (raw 1, secure false) is asserted on the full triple — present, sameSite: lax, and secure still false — because a presence-only assertion would pass on a silently altered cookie.

raw 0 + secure false is asserted absent as a rejection control — it proves rejection is observable at all, without which "the cookie landed" proves only that the assertion ran.

Correction from review: an earlier draft of this description said that shape "cannot occur in a real profile." That was too strong. Chromium normally refuses to store it and the measured distribution has zero such rows, but enterprise policy LegacySameSiteCookieBehaviorEnabledForDomainList still permits it, and pre-M80 grandfathered persistent rows can survive. For those rows this PR turns a previously successful (but mislabelled unspecified) import into a rejected write — the cookie is dropped from the live session and, with staging available, deferred to cold-start replay. Small population, but it lands inside the count-reporting defect below, so it fails silently.

Three ablations, each verified:

  • A — old decoder restored → the Pulley-shaped assertion fails (received undefined). I re-ran this independently against the committed branch; the unit tests go red on 0→no_restriction, 1→lax, 2→strict, 3→unspecified.
  • B — ?? 0 restored alongside the corrected decoder → the NULL case fails.
  • C — negative control (raw -1 + secure true) stayed green under both, so neither red came from wholesale harness failure.

Distribution: 481/1,743 (27.6%) → 1,743/1,743 (100%), including all 135 previously-rejected rows.

pnpm test src/main/browser 1,695/1,695 across 183 files · pnpm tc clean · changed-code quality gate clean.

Two things found but deliberately left alone

Import success is over-reported. With the rejection control, the import reported ok=true, 9 imported, 0 skipped while only 8 cookies were present. A rejected write is caught per-cookie so later rows still land — but the count is wrong, which is why this bug hid for months and why the user saw "success" with no session. Its own fix.

The ?? 0 twin survives on the staging path. fallbackChromiumCookieColumnValue in browser-cookie-sqlite.ts fills a missing samesite with 0 via its generic INT → 0 arm when building the cold-start staged database. Chromium's schema declares samesite INTEGER NOT NULL with no default, so the fallback is live. Reachability is tiny — it needs a pre-2016 source schema and a rejected in-memory write — but this PR's ?? -1 change prevents relocation on the direct path only.

A silent-loss class on the Firefox path, pre-existing. Firefox stores 256 (SAMESITE_UNSET) for attribute-less cookies, but legacy unset rows left by the schema-15 migration remain 0, indistinguishable from explicit None. Those decode to no_restriction, get an http:// URL, and are rejected — dropped, counted as skipped, with no per-cookie surfacing. Not introduced here; "firefoxSameSite was already correct" is true of the column's literal values, not of what Firefox means by them.

Firefox expiry units. Firefox 142 changed moz_cookies.expiry from seconds to milliseconds (schema 15→16, UPDATE moz_cookies SET expiry = expiry * 1000) and kept the column name. browser-cookie-firefox-import.ts still reads seconds, so on FF ≥142 expired cookies are never filtered and every expiry clamps to Chromium's 400-day cap. Separate browser, separate failure mode, its own fix.

Note for reviewers

Chromium's published CDP docs (pdl/domains/Network.pdl) state Network.setCookie's success return is "always set to true". It is not — the real inclusion boolean is piped into sendSuccess at network_handler.cc:2446-2451. Orca's cdpSetCookieSucceeded check is correct and load-bearing; please don't simplify it away on the strength of those docs.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 40d30e86-e528-4d45-9506-5421356afc29

📥 Commits

Reviewing files that changed from the base of the PR and between 89abc2a and 863fbb8.

📒 Files selected for processing (2)
  • src/main/browser/browser-cookie-validation.test.ts
  • src/main/browser/browser-cookie-validation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser-cookie-validation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change replaces separate Chromium and Firefox SameSite decoders with databaseSameSite. Chromium scanning now defaults missing or NULL database values to unspecified. Firefox import uses the shared decoder. Test fixtures support -1 and nullable samesite values. Unit and Electron integration tests cover decoding, Secure preservation, rejection, and NULL handling.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 863fb

The change standardizes database SameSite decoding and adds coverage for valid, rejected, and nullable values. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description gives detailed problem, cause, fix, behavior changes, testing evidence, and scope boundaries. However, it omits the required Linked Issue, Visual Proof or an explicit N/A statement, an… Add the required issue reference after “Fixes #”. Add a Visual Proof section with N/A and a reason if no visual change exists. Complete or explicitly address the required testing, review, notes, agent-boundary, and checklist sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the Chromium SameSite decoding fix and the primary user impact.
Full details: Description check

Explanation

The description gives detailed problem, cause, fix, behavior changes, testing evidence, and scope boundaries. However, it omits the required Linked Issue, Visual Proof or an explicit N/A statement, and repository checklist sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor observation inline.

Reviewed changes

  • SameSite decoder consolidation — deletes the invented chromiumSameSite decoder and renames the already-correct firefoxSameSite to a shared databaseSameSite (0=no_restriction, 1=lax, 2=strict, default unspecified), now used by both the Chromium scan and the Firefox import.
  • Null fallback correction — the Chromium scan now falls back to -1 (unspecified) instead of 0 (None) for absent/NULL samesite, so a NULL column no longer mints SameSite=None cookies that would then require Secure.
  • Test coverage — a real-Electron end-to-end fixture asserts the raw × Secure matrix with exact SameSite/Secure values plus a rejection control and a NULL case, and a unit test pins databaseSameSite including out-of-range and non-integer inputs.

The fix is correct and well-grounded: the 0/1/2 mapping matches both net::CookieSameSite and Firefox moz_cookies, the removal is clean (no stale references to chromiumSameSite/firefoxSameSite remain), and the assertions are exact rather than presence-only, so the tests genuinely fail against the old decoder.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

): 'unspecified' | 'no_restriction' | 'lax' | 'strict' {
if (typeof raw === 'number') {
return chromiumSameSite(raw)
return databaseSameSite(raw)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This folds normalizeSameSite's numeric branch onto the corrected decoder, so importCookiesFromFile now decodes numeric sameSite JSON values with the Chromium/Firefox table instead of the old invented one. That's a strict improvement, but the JSON-import tests only cover string values, so the numeric path is untested — worth a brief note or a small test pinning the numeric mapping, since it's a user-facing import surface the PR body doesn't call out.

…ault-arm inputs

Third-reviewer finding: the replacement comment reproduced the failure mode this
PR exists to kill. It said "Firefox's moz_cookies uses the same 0/1/2 values",
which is true of the overlap and silently wrong about the rest of the domain.

Firefox writes 256 (nsICookie SAMESITE_UNSET) for every cookie with no SameSite
attribute -- the most common shape in a modern profile -- NULL on pre-v10 rows,
and 0 for explicit None OR a legacy unset row the schema-15 migration left
behind, which are not distinguishable in the column. All of those must land on
unspecified, so the default arm is load-bearing for Firefox rather than
incidental. A later reader making the switch exhaustive against the old comment
would have regressed Firefox silently.

Also pins the inputs that were riding the default untested: 256, and the
non-integer arrivals (null, undefined, NaN) that the `?? -1` scan fallback and
pre-v10 Firefox rows produce. Decoder behaviour is unchanged; 11/11 pass.
@brennanb2025
brennanb2025 merged commit 6252f81 into main Sep 11, 2026
28 checks passed
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.

1 participant