Repository navigation
fix(browser): decode Chromium SameSite storage values (135 cookies silently lost per profile) - #20076
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change replaces separate Chromium and Firefox SameSite decoders with Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor observation inline.
Reviewed changes
- SameSite decoder consolidation — deletes the invented
chromiumSameSitedecoder and renames the already-correctfirefoxSameSiteto a shareddatabaseSameSite(0=no_restriction,1=lax,2=strict, defaultunspecified), now used by both the Chromium scan and the Firefox import. - Null fallback correction — the Chromium scan now falls back to
-1(unspecified) instead of0(None) for absent/NULLsamesite, so a NULL column no longer mintsSameSite=Nonecookies that would then requireSecure. - Test coverage — a real-Electron end-to-end fixture asserts the
raw × Securematrix with exactSameSite/Securevalues plus a rejection control and a NULL case, and a unit test pinsdatabaseSameSiteincluding 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| ): 'unspecified' | 'no_restriction' | 'lax' | 'strict' { | ||
| if (typeof raw === 'number') { | ||
| return chromiumSameSite(raw) | ||
| return databaseSameSite(raw) |
There was a problem hiding this comment.
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.

Problem
Orca decodes Chromium's stored
SameSiteinteger with a numbering that does not exist.chromiumSameSite()read1=None, 2=Lax, 3=Strict, citing an enum calledCookieSameSiteForStorage.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 storesnet::CookieSameSitevalues unchanged:net/extras/sqlite/sqlite_persistent_cookie_store.ccconfirms the storage encoding is an identity mapping, with the deprecated3folded toUNSPECIFIED. So Orca's table was off by one, and onlyUNSPECIFIEDdecoded correctly — by accident, via thedefaultarm.What that does, measured against a real 1,743-cookie Chrome profile
Only 27.6% decoded correctly.
The 135 are the worst case, and they fail through a complete chain:
chromiumSameSite(1)→no_restrictioncdpSameSite('no_restriction')→'None'http://…because the cookie is not Secure (browser-cookie-import-policy.ts:201)secure = secure || source_url.SchemeIsCryptographic()(network_handler.cc:453) does not fireCookieBase::IsSetPermittedInContextexcludes it —EXCLUDE_SAMESITE_NONE_INSECURE(cookie_base.cc:372){"success": false}and the write throwsThe 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-correctfirefoxSameSitetodatabaseSameSiteand 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.tschange in this diff is only the call-site update that collapsing requires — not a second fix.Second, required change:
browser-cookie-chromium-scan.tsreadNumber(sourceRow.samesite ?? 0). Under the old wrong table0fell through to unspecified — harmless. Under the corrected table0meansNone, so a NULL column would start mintingSameSite=Nonecookies needingSecure— 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/2have been stable since Chrome 51 and-1since Chrome 76, and the absent-column fallback covers olderfirstpartyonly-era schemas.Behaviour changes beyond the headline fix
The 135 recovered cookies are not the largest delta. Every category whose decoded
SameSitechanges, against the measured 1,743-cookie distribution:raw 0, Secureraw 1, not Secureraw 1, Secureraw 2raw 3All are a return to what the source browser actually stored, but the
raw 0row is the one users may notice, and theraw 2row 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 × Securecombinations land with exactSameSiteand authoredSecure. The Pulley shape (raw 1,secure false) is asserted on the full triple — present,sameSite: lax, andsecurestillfalse— because a presence-only assertion would pass on a silently altered cookie.raw 0 + secure falseis 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
LegacySameSiteCookieBehaviorEnabledForDomainListstill permits it, and pre-M80 grandfathered persistent rows can survive. For those rows this PR turns a previously successful (but mislabelledunspecified) 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:
received undefined). I re-ran this independently against the committed branch; the unit tests go red on0→no_restriction,1→lax,2→strict,3→unspecified.?? 0restored alongside the corrected decoder → the NULL case fails.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/browser1,695/1,695 across 183 files ·pnpm tcclean · 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 skippedwhile 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
?? 0twin survives on the staging path.fallbackChromiumCookieColumnValueinbrowser-cookie-sqlite.tsfills a missingsamesitewith0via its genericINT → 0arm when building the cold-start staged database. Chromium's schema declaressamesite INTEGER NOT NULLwith 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?? -1change 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 remain0, indistinguishable from explicit None. Those decode tono_restriction, get anhttp://URL, and are rejected — dropped, counted as skipped, with no per-cookie surfacing. Not introduced here; "firefoxSameSitewas already correct" is true of the column's literal values, not of what Firefox means by them.Firefox
expiryunits. Firefox 142 changedmoz_cookies.expiryfrom seconds to milliseconds (schema 15→16,UPDATE moz_cookies SET expiry = expiry * 1000) and kept the column name.browser-cookie-firefox-import.tsstill 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) stateNetwork.setCookie's success return is "always set to true". It is not — the real inclusion boolean is piped intosendSuccessatnetwork_handler.cc:2446-2451. Orca'scdpSetCookieSucceededcheck is correct and load-bearing; please don't simplify it away on the strength of those docs.