Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/typescript/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ function preferredAuthUrl(value: string): string | null {
)) {
const url = match[0].replace(/[.,;:!?)\]}]+$/, "");
try {
const hostname = new URL(url).hostname.toLowerCase().replace(/\.$/, "");
const parsed = new URL(url);
if (parsed.protocol !== "https:") continue;
const hostname = parsed.hostname.toLowerCase().replace(/\.$/, "");
if (
hostname !== "localhost" &&
!hostname.endsWith(".localhost") &&
Expand Down
33 changes: 33 additions & 0 deletions sdk/typescript/tests-ts/auth-http-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, test } from "bun:test";
import { CodexLoginHandle } from "../src/auth.js";

test("skips external plaintext HTTP authentication URLs", async () => {
const root = await mkdtemp(join(tmpdir(), "codex-security-auth-http-"));
const script = join(root, "login.mjs");
try {
await writeFile(
script,
`
console.error("Open http://auth.example.test/insecure");
console.error("Open https://auth.example.test/device");
console.error("User code: ABCD-EFGH");
process.exit(0);
`,
);
const handle = new CodexLoginHandle(
{ command: process.execPath },
[script],
process.env,
() => {},
);

await expect(handle.wait()).resolves.toMatchObject({ success: true });
expect(handle.verificationUrl).toBe("https://auth.example.test/device");
expect(handle.userCode).toBe("ABCD-EFGH");
} finally {
await rm(root, { recursive: true, force: true });
}
});
Loading