Skip to content

Commit 78b3328

Browse files
committed
revert(clerk-js): remove cookie write monotonic guard
The cookie write guard at AuthCookieService.updateSessionCookie was causing integration test failures across handshake, sessions, and multiple framework matrices. The guard would reject token writes when oiat+iat matched, but two tokens with identical timestamps can still differ in OTHER claims (azp added in a recent token-format rollout, org_id, etc.). Backend then logged 'Session token from cookie is missing the azp claim' and treated the session as invalid, redirecting to /sign-in. The broadcast handler (tokenCache.ts:292) and Session resource (Session.ts:463, :526) keep the monotonic enforcement at the layers where it works correctly. The cookie chokepoint was too aggressive. The cookie path deserves a guard but with a different shape (e.g., raw-string equality or signature compare), not the claim-timestamp shape.
1 parent d265058 commit 78b3328

1 file changed

Lines changed: 0 additions & 23 deletions

File tree

packages/clerk-js/src/core/auth/AuthCookieService.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import type { Clerk, InstanceType } from '@clerk/shared/types';
1313
import { noop } from '@clerk/shared/utils';
1414

1515
import { debugLogger } from '@/utils/debug';
16-
import { decode } from '@/utils/jwt';
1716

1817
import { clerkMissingDevBrowser } from '../errors';
1918
import { eventBus, events } from '../events';
2019
import type { FapiClient } from '../fapiClient';
2120
import { Environment } from '../resources/Environment';
22-
import { pickFreshestJwt } from '../tokenFreshness';
2321
import { createActiveContextCookie } from './cookies/activeContext';
2422
import type { ClientUatCookieHandler } from './cookies/clientUat';
2523
import { createClientUatCookie } from './cookies/clientUat';
@@ -196,27 +194,6 @@ export class AuthCookieService {
196194
return;
197195
}
198196

199-
// Monotonic freshness guard: don't regress the cookie within the same session.
200-
if (token) {
201-
const currentRaw = this.sessionCookie.get();
202-
if (currentRaw) {
203-
try {
204-
const current = decode(currentRaw);
205-
const incoming = decode(token);
206-
const currentSid = current.claims.sid;
207-
const incomingSid = incoming.claims.sid;
208-
// Only apply within the same session. Different sessions always allowed.
209-
if (currentSid && incomingSid && currentSid === incomingSid) {
210-
if (pickFreshestJwt(current, incoming) === current) {
211-
return;
212-
}
213-
}
214-
} catch {
215-
// If decode fails, allow the write (don't block on malformed tokens)
216-
}
217-
}
218-
}
219-
220197
if (!token && !isValidBrowserOnline()) {
221198
debugLogger.warn('Removing session cookie (offline)', { sessionId: this.clerk.session?.id }, 'authCookieService');
222199
}

0 commit comments

Comments
 (0)