The best way to control Claude Code, Codex and more from any computer or phone
fix(server): ChatGPT sign-in keeps listening after a stray callback request (#34533)
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
maria committed
Nov 12, 2026 at 00:27 UTC
2bcbdae06a495cd9faa9d216b765deb075ae7913
2 files changed
+26
-7
apps/server/src/provider/CodexChatGptAuth.test.ts
+12
-4
@@ -401,8 +401,8 @@ const makeHarnessFor = Effect.fnUntraced(function* (
401
setIdentityFailure: (value: "issuer" | "audience" | "signature") => {
402
identityFailure = value;
403
},
404
- mismatchCallbackState: () => {
405
- mismatchedState = true;
404
+ mismatchCallbackState: (value = true) => {
405
+ mismatchedState = value;
406
},
407
setCallbackClientId: (value: string) => {
408
callbackClientId = value;
@@ -871,16 +871,24 @@ it.effect(
871
),
872
);
873
874
-it.effect("rejects mismatched callback state before any token exchange or credential write", () =>
874
+it.effect("rejects mismatched callback state and keeps waiting for the real redirect", () =>
875
provision(
876
Effect.gen(function* () {
877
const h = yield* makeHarness;
878
h.mismatchCallbackState();
879
yield* h.signIn;
880
- assert.include((yield* h.phase("failed")).message!, "could not be verified");
880
+ assert.include(h.callbackResponses[0]!.body, "does not belong to the active sign-in");
881
assert.strictEqual(h.exchanges.length, 0);
882
assert.deepEqual(h.storedRecords(), []);
883
assert.isTrue(Option.isNone(yield* h.auth.read));
884
+ h.mismatchCallbackState(false);
885
+ const waiting = yield* h.phase("waiting");
886
+ const redirectUri = new URL(waiting.authorizationUrl!).searchParams.get("redirect_uri")!;
887
+ const unparsable = yield* Effect.promise(() => fetch(`${new URL(redirectUri).origin}//`));
888
+ assert.strictEqual(unparsable.status, 404);
889
+ yield* h.finishCallback(waiting);
890
+ yield* h.phase("succeeded");
891
+ assert.strictEqual(h.exchanges.length, 1);
892
}),
893
),
894
);
apps/server/src/provider/CodexChatGptAuth.ts
+14
-3
@@ -549,9 +549,10 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
549
Effect.tryPromise({
550
try: () =>
551
new Promise<NodeHttp.Server>((resolve, reject) => {
552
+ const callbackBase = "http://127.0.0.1/auth/callback";
553
const server = NodeHttp.createServer((request, response) => {
553
- const url = new URL(request.url ?? "/", "http://127.0.0.1");
554
- if (request.method !== "GET" || url.pathname !== "/auth/callback") {
554
+ const url = URL.parse(request.url ?? "/", callbackBase);
555
+ if (request.method !== "GET" || url?.pathname !== "/auth/callback") {
556
response.writeHead(404).end();
557
return;
558
}
@@ -559,8 +560,18 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
560
response.writeHead(410).end("Sign-in is no longer active.");
561
return;
562
}
563
+ // Reject a stray request without ending the sign-in, so the real redirect still lands.
564
+ let returned: URL;
565
+ try {
566
+ returned = codexCallbackUrl(url.toString(), callbackBase, state);
567
+ } catch {
568
+ response
569
+ .writeHead(400)
570
+ .end("This response does not belong to the active sign-in.");
571
+ return;
572
+ }
573
used = true;
563
- callback.resolve({ url, response });
574
+ callback.resolve({ url: returned, response });
575
});
576
server.once("error", reject);
577
server.listen(0, "127.0.0.1", () => resolve(server));