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: warn when environment keys override access-token login (#23)

Dane Schneiderc877c3f71381
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index f829130a6..9a7b0c82d 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -1446,16 +1446,16 @@ export async function main(
name.toUpperCase() === "CODEX_API_KEY"),
)
.map(([name]) => name);
- const loginKind = options.withAccessToken
- ? "Access-token"
- : "ChatGPT";
- const credential = options.withAccessToken
- ? "access token"
- : "ChatGPT sign-in";
+ const loginWarning = options.withAccessToken
+ ? `Access-token login succeeded, but noninteractive scans will use ${authentication.source}.\n`
+ : "ChatGPT login succeeded. Interactive scans will ask which account to use; " +
+ `noninteractive scans will use ${authentication.source}.\n`;
+ const storedCredentials = options.withAccessToken
+ ? "your stored credentials"
+ : "your ChatGPT sign-in";
errorOutput.write(
- `${loginKind} login succeeded. Interactive scans will ask which account to use; ` +
- `noninteractive scans will use ${authentication.source}.\n` +
- `To use your ${credential}, pass '--auth chatgpt' or run ` +
+ loginWarning +
+ `To use ${storedCredentials}, pass '--auth chatgpt' or run ` +
`'unset ${configuredApiKeyVariables.join(" ")}'.\n`,
);
}
diff --git a/sdk/typescript/tests-ts/cli-authentication.test.ts b/sdk/typescript/tests-ts/cli-authentication.test.ts
index 3b5654c2b..210848b4c 100644
--- a/sdk/typescript/tests-ts/cli-authentication.test.ts
+++ b/sdk/typescript/tests-ts/cli-authentication.test.ts
@@ -119,7 +119,7 @@ describe("CLI authentication", () => {
}
});
- test("explains when an environment API key overrides an access-token login", async () => {
+ test("warns when an environment API key overrides a successful access-token login", async () => {
for (const [environment, source, unsetCommand] of [
[
{ OPENAI_API_KEY: "sk-proj-SYNTHETIC_SECRET_123" },
@@ -153,13 +153,13 @@ describe("CLI authentication", () => {
).toBe(0);
expect(stdout.text()).toBe("");
expect(stderr.text()).toContain(
- "Access-token login succeeded. Interactive scans will ask which account to use;",
+ `Access-token login succeeded, but noninteractive scans will use ${source}.`,
);
expect(stderr.text()).toContain(
- `noninteractive scans will use ${source}.`,
+ "To use your stored credentials, pass '--auth chatgpt' or run ",
);
- expect(stderr.text()).toContain("--auth chatgpt");
expect(stderr.text()).toContain(`'${unsetCommand}'`);
+ expect(stderr.text()).not.toContain("ChatGPT login succeeded");
expect(stderr.text()).not.toContain("SYNTHETIC_SECRET");
}
});
@@ -188,6 +188,22 @@ describe("CLI authentication", () => {
}
});
+ test("does not warn after access-token login without an overriding API key", async () => {
+ const stdout = capture();
+ const stderr = capture();
+
+ expect(
+ await main(
+ ["login", "--with-access-token"],
+ stdout.stream,
+ stderr.stream,
+ dependencies({ environment: {} }),
+ ),
+ ).toBe(0);
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toBe("");
+ });
+
test("forwards explicit and automatic scan authentication selection", async () => {
for (const [argv, expected] of [
[["scan", "--auth", "chatgpt"], "chatgpt"],