The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): accept a pasted ChatGPT callback URL that is missing http:// (#21750)
project516 committed
Oct 21, 2026 at 08:18 UTC
35e5d6229ba2c121b61e56cd982c6e2fb3112ef0
2 files changed
+28
-1
packages/shared/src/codexAuthHandoff.test.ts
+23
@@ -4,6 +4,7 @@ import {
4
codexAuthorizationRequest,
5
codexAuthDeliveryUrl,
6
codexAuthHandoffUrl,
7
+ codexCallbackUrl,
8
readCodexAuthDelivery,
9
readCodexAuthHandoff,
10
} from "./codexAuthHandoff.ts";
@@ -77,3 +78,25 @@ describe("Codex desktop handoff", () => {
78
expect(() => codexAuthDeliveryUrl(input, callbackUrl + "&state=another")).toThrow();
79
});
80
});
81
+
82
+describe("pasted Codex callback", () => {
83
+ const { redirectUri, state } = codexAuthorizationRequest(input.authorizationUrl);
84
+ const copied = callbackUrl.slice("http://".length);
85
+
86
+ it("accepts a callback copied without its scheme", () => {
87
+ expect(codexCallbackUrl(copied, redirectUri, state).toString()).toBe(callbackUrl);
88
+ });
89
+ it("accepts leading whitespace with or without a scheme", () => {
90
+ expect(codexCallbackUrl(` \t\n${callbackUrl}`, redirectUri, state).toString()).toBe(
91
+ callbackUrl,
92
+ );
93
+ expect(codexCallbackUrl(` \t\n${copied}`, redirectUri, state).toString()).toBe(callbackUrl);
94
+ });
95
+ it("still rejects a scheme-less callback for another address or sign-in", () => {
96
+ expect(() =>
97
+ codexCallbackUrl(copied.replace("127.0.0.1", "localhost"), redirectUri, state),
98
+ ).toThrow();
99
+ expect(() => codexCallbackUrl(copied.replace("54213", "54214"), redirectUri, state)).toThrow();
100
+ expect(() => codexCallbackUrl(`${copied}&state=another`, redirectUri, state)).toThrow();
101
+ });
102
+});
packages/shared/src/codexAuthHandoff.ts
+5
-1
@@ -56,8 +56,12 @@ export function codexAuthorizationRequest(value: string) {
56
}
57
58
export function codexCallbackUrl(value: string, redirectUri: string, state: string) {
59
- const callback = new URL(value);
59
const expected = new URL(redirectUri);
60
+ const pasted = value.trimStart();
61
+ // Browsers can hide `http://` in the address bar, so a pasted callback may lack it.
62
+ const callback = new URL(
63
+ /^[a-z][a-z\d+.-]*:\/\//iu.test(pasted) ? pasted : `${expected.protocol}//${pasted}`,
64
+ );
65
const states = callback.searchParams.getAll("state");
66
const codes = callback.searchParams.getAll("code");
67
const errors = callback.searchParams.getAll("error");