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): reject unsupported scan authentication modes (#172)

Dipesh Babue4f71f883839
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 8497fcc97..55da505f5 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -2770,6 +2770,11 @@ export function scanAuthentication(
auth: ScanAuthMode = "auto",
modelProvider?: unknown,
): ScanAuthentication {
+ if (auth !== "auto" && auth !== "chatgpt" && auth !== "api-key") {
+ throw new TypeError(
+ "Scan authentication mode must be auto, chatgpt, or api-key.",
+ );
+ }
if (modelProvider === "amazon-bedrock") {
const sources = [
"AWS_BEARER_TOKEN_BEDROCK",
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 0c547f889..a6ecd98bd 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -675,6 +675,35 @@ describe("CodexSecurity orchestration", () => {
await client.close();
});
+ test("rejects unsupported authentication modes before runtime initialization", async () => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ await mkdir(repository);
+ let runtimeStarted = false;
+ const client = new TestClient(
+ {},
+ {
+ environment: { OPENAI_API_KEY: "synthetic-openai-key" },
+ prepareRuntime: async () => {
+ runtimeStarted = true;
+ throw new Error("runtime should not initialize");
+ },
+ },
+ );
+ const options = {
+ auth: "unsupported",
+ } as unknown as ScanOptions;
+
+ await expect(client.preflight(repository, options)).rejects.toThrow(
+ "Scan authentication mode must be auto, chatgpt, or api-key.",
+ );
+ await expect(client.run(repository, options)).rejects.toThrow(
+ "Scan authentication mode must be auto, chatgpt, or api-key.",
+ );
+ expect(runtimeStarted).toBe(false);
+ await client.close();
+ });
+
test("rejects explicit API-key authentication without a configured key before runtime initialization", async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");