Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(auth): preserve IPv6 verification URL brackets (#232)

Dipesh Babuad6ec65ad135
diff --git a/sdk/typescript/src/auth.ts b/sdk/typescript/src/auth.ts
index 1c07eede6..b81de4028 100644
--- a/sdk/typescript/src/auth.ts
+++ b/sdk/typescript/src/auth.ts
@@ -336,7 +336,14 @@ function preferredAuthUrl(value: string): string | null {
for (const match of plainTerminalText(value).matchAll(
/https?:\/\/[^\s<>"']+/g,
)) {
- const url = match[0].replace(/[.,;:!?)\]}]+$/, "");
+ // A bracket ending an IPv6 authority belongs to the URL, even in prose.
+ const candidate = match[0];
+ const ipv6Authority =
+ candidate.match(/^https?:\/\/(?:[^\\/?#]*@)?\[[\da-fA-F:.]+\]/)?.[0] ??
+ "";
+ const url =
+ ipv6Authority +
+ candidate.slice(ipv6Authority.length).replace(/[.,;:!?)\]}]+$/, "");
try {
const parsed = new URL(url);
const hostname = parsed.hostname.toLowerCase().replace(/\.$/, "");
diff --git a/sdk/typescript/tests-ts/auth.test.ts b/sdk/typescript/tests-ts/auth.test.ts
index 54ae5db68..9860c9022 100644
--- a/sdk/typescript/tests-ts/auth.test.ts
+++ b/sdk/typescript/tests-ts/auth.test.ts
@@ -185,6 +185,41 @@ describe("Codex authentication process boundary", () => {
expect(observeSucceeded).toHaveBeenCalled();
});
+ test.each([
+ ["Open https://[2001:db8::1].", "https://[2001:db8::1]"],
+ [
+ "Open [https://auth.example.test/device]",
+ "https://auth.example.test/device",
+ ],
+ ["Open [https://[2001:db8::]]", "https://[2001:db8::]"],
+ [
+ "Open [https://auth.example.test/device.]",
+ "https://auth.example.test/device",
+ ],
+ ["Open [https://[2001:db8::3].]", "https://[2001:db8::3]"],
+ [
+ "Open [https://[2001:db8::4]/device?challenge=ABCD.]",
+ "https://[2001:db8::4]/device?challenge=ABCD",
+ ],
+ ["Open [https://[2001:db8::5]:8443]", "https://[2001:db8::5]:8443"],
+ ["Open [https://[::1]]", null],
+ ["Open [https://[::ffff:127.0.0.1]]", null],
+ ["Open http://[2001:db8::1]", null],
+ ] as const)(
+ "distinguishes IPv6 host brackets from surrounding punctuation: %s",
+ async (output, expected) => {
+ const handle = new CodexLoginHandle(
+ nodeCommand(),
+ ["-e", "console.error(process.argv[1])", output],
+ {},
+ () => {},
+ );
+
+ await expect(handle.wait()).resolves.toMatchObject({ success: true });
+ expect(handle.verificationUrl).toBe(expected);
+ },
+ );
+
test.each(["sync", "async"])(
"rejects wait when required login completion fails: %s",
async (mode) => {