Skip to content

Commit 71f22cd

Browse files
committed
fix(worker): honor terminal ticket session/tab when X-User-Id is set
Pages proxy sends X-User-Id; WS URL only has ?ticket=. requireTerminalIdentity returned early with userId-only identity so session/tab defaulted to main and the wrong Durable Object/container was targeted (1006). Made-with: Cursor
1 parent 4f46b81 commit 71f22cd

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

worker/effect/services.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,33 @@ const AuthServiceLive = Layer.effect(
265265
requireTerminalIdentity: ({ userIdHeader, ticket }) =>
266266
Effect.gen(function* () {
267267
const userId = userIdHeader?.trim();
268+
const token = ticket?.trim();
269+
270+
// Pages proxy sends X-User-Id + cookie auth but WS URL only has ?ticket= (no sessionId query).
271+
// Still verify the ticket and take session/tab from the payload so we attach the right container.
272+
if (userId && token) {
273+
const payload = yield* Effect.tryPromise({
274+
try: () => verifyTerminalTicket(token, env.TERMINAL_TICKET_SECRET),
275+
catch: () => new Unauthorized({ message: 'Authentication required' }),
276+
});
277+
278+
if (!payload || payload.userId !== userId) {
279+
return yield* Effect.fail(
280+
new Unauthorized({ message: 'Authentication required' })
281+
);
282+
}
283+
284+
return {
285+
userId: payload.userId,
286+
sessionId: payload.sessionId,
287+
tabId: payload.tabId,
288+
};
289+
}
290+
268291
if (userId) {
269292
return { userId };
270293
}
271294

272-
const token = ticket?.trim();
273295
if (!token) {
274296
return yield* Effect.fail(
275297
new Unauthorized({ message: 'Authentication required' })

0 commit comments

Comments
 (0)