My cookie kept losing a race with Chrome
NVX Session gives every tab its own logins. The hardest bug was a sign-in redirect that leaves before my cookie arrives, and the fix was to stop racing Chrome at all. Plus Chrome's two-minute exception to SameSite=Lax.
By Ojas KekreCyber security, Monash University
Work Google in one tab, personal Google in the next, same window, both signed in. That's NVX Session, a browser extension I built that gives every tab its own cookies.
- Unit tests
- 760
- Sign-in scenarios
- 26 / 26
- The whole download
- 437 KB
NVX Session never lets a session's cookies into Chrome's cookie jar. It writes the Cookie header on every request itself.
In Manifest V3 an extension can't touch a request mid-flight. You hand Chrome rules ahead of time (declarativeNetRequest) and Chrome applies them. That's fast and private, but the rule has to exist before the request leaves.
Sign-in redirects
- 01302 +
Set-Cookie+Location: next - 02Follows the redirect in ~ms, no cookie
- 03Here's that cookie, by the way
- 04Installs a rule. Too late.
- 01Sign-in serverChrome302 +
Set-Cookie+Location: next - 02ChromeSign-in serverFollows the redirect in ~ms, no cookie
- 03ChromeMy extensionHere's that cookie, by the way
- 04My extensionInstalls a rule. Too late.
The site sees a stranger. You're signed out or stuck in a loop.
The worst case was a university Moodle behind Okta, where every hop sets a new cookie. It raced forever, and I spent all of 3 October on it.
- 12:43
3 of 18 sign-in scenarios working
- 12:49
12 of 18
- 12:59
15 of 18
- 13:08
18 of 18, but only 7 clean
The rest needed a retry. Still racing.
- 19:11
26 of 26, isolation checks 20 of 20
Stopped racing
Holding the redirect
A rule strips Location from any page response that also sets a cookie. The page stays put while I install the cookie, then I send the tab on myself with location.replace(next), so Back doesn't hit an empty page.
- 39%Clean
- 61%Needed a retry
- 81%Clean on the first try
- 19%Not clean on the first try
- 01
Fake sign-in chain
OAuth, SAML, popups, hidden iframes, meta refresh, QR polling, changing cookies
- 02
Plain Chrome first
Proves the scenario works
- 03
Two sessions at once
- 04
Ask each session
Who it's signed in as
.test hosts.The test bed also caught me out. My retries were counting toward my own sign-in loop detector, which then decided Okta was broken and released it for everyone.
A Chrome cookie quirk
| The spec | Chrome | |
|---|---|---|
| Default | Lax | Lax |
| Sent on a cross-site POST | Yes, for the cookie's first two minutes |
- 1Window closes120 sThe extension schedules a recompile for this second
- Lax cookie sent on cross-site POST0 s to 120 s
Following the spec to the letter, a SAML login POST went out with no cookies and Moodle replied invalidsesskey. So the extension copies Chrome's two-minute window too. A compiled rule is a photo of an answer, so it recompiles for the exact second that answer expires.
Two more traps in MV3
- 01Chrome kills the extension's service worker after about 30 s idle, and everything in memory goes with it. Service worker: idle ~30 s, killed.
- 02q to w: Request. The worker usually wakes up because of a request. Service worker: awake.
- 03It clears the old rules, then installs the new ones a few awaits later. Session rules: old rules cleared.
- 04That same request leaves in the gap, with Chrome's own cookies. A request: wrong cookies.
Swap old rules for new in the same updateSessionRules call. One call, no gap.
- 01
Block the tab
A rule that blocks every request from that tab
- 02
Swap the rules
- 03
Remove the block
Requests from that tab wait a few milliseconds instead of going out with another account's cookies.
Editions
| Edition | What it has |
|---|---|
| Free | Open source (GPL-3.0), unlimited sessions, no account, Chromium 128+ and Opera GX |
| Pro (A$6.99/month or A$69.99/year) | Adds what free is upfront about not doing: IndexedDB isolation, fail-closed mode, cache suppression, a separate fingerprint per session, encrypted sync of settings |
| Licence | One licence covers all the NVX apps |
Still unfixed
A 307 that carries a POST body. You can hold a redirect, but you can't resend a body Chrome already threw away.