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): ignore URL parameters when reading device codes (#979)

Dipesh Babu607298fca7a2
diff --git a/sdk/typescript/src/auth.ts b/sdk/typescript/src/auth.ts
index 933ba35fb..65257b0c2 100644
--- a/sdk/typescript/src/auth.ts
+++ b/sdk/typescript/src/auth.ts
@@ -330,7 +330,7 @@ function preferredAuthUrl(value: string): string | null {
}
function userCodeFromOutput(value: string): string | null {
- const output = plainTerminalText(value);
+ const output = plainTerminalText(value).replace(/https?:\/\/[^\s<>"']+/g, "");
return (
output.match(/(?:code|user code)\s*[:=]\s*([A-Z0-9-]{4,})/i)?.[1] ??
output.match(/\b[A-Z0-9]{4,}(?:-[A-Z0-9]{4,})+\b/)?.[0] ??
diff --git a/sdk/typescript/tests-ts/auth.test.ts b/sdk/typescript/tests-ts/auth.test.ts
index 1aca9a3fb..0d6facb84 100644
--- a/sdk/typescript/tests-ts/auth.test.ts
+++ b/sdk/typescript/tests-ts/auth.test.ts
@@ -164,6 +164,33 @@ describe("Codex authentication process boundary", () => {
expect(succeeded).toBe(true);
});
+ test.each(["User code: RIGHT-CODE", "Code: RIGHT-CODE", "RIGHT-CODE"])(
+ "ignores URL parameters when reading device instructions: %s",
+ async (instruction) => {
+ const root = await mkdtemp(join(tmpdir(), "codex-security-auth-code-"));
+ temporaryDirectories.push(root);
+ const script = join(root, "login.mjs");
+ const url = "https://auth.example.test/device?code=WRONG-CODE";
+ await writeFile(
+ script,
+ `process.stderr.write(${JSON.stringify(`Open ${url}\n${instruction}\n`)}, () => process.exit(0));\n`,
+ );
+ const command = execFileSync("node", ["-p", "process.execPath"], {
+ encoding: "utf8",
+ }).trim();
+ const handle = new CodexLoginHandle(
+ { command },
+ [script],
+ process.env,
+ () => {},
+ );
+
+ await expect(handle.wait()).resolves.toMatchObject({ success: true });
+ expect(handle.verificationUrl).toBe(url);
+ expect(handle.userCode).toBe("RIGHT-CODE");
+ },
+ );
+
test("retains large interactive output and login instructions", async () => {
const root = await mkdtemp(join(tmpdir(), "codex-security-auth-output-"));
temporaryDirectories.push(root);