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: surface actual security scan failures (#76)

ianw-oai8e833fadd97d
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index b2df80421..34333df0b 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -2496,9 +2496,7 @@ function scanFailureMessage(
case "rate_limited":
return "The configured account reached its rate limit. Wait and retry.";
case "network_error":
- return "The model service could not be reached. Check your network connection and try again.";
case "timeout":
- return "The connection timed out. Check your network connection and try again.";
case "unknown":
return cliErrorMessage(error);
}
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 0d15be35c..f8d91509f 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -1677,13 +1677,11 @@ describe("CLI", () => {
expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
});
- test("turns provider-specific scan failures into actionable safe messages", async () => {
+ test("turns authentication and rate-limit failures into actionable safe messages", async () => {
for (const [message, expected] of [
["401 invalid API key for org-private", "provide a valid API key"],
["403 model access denied for org-private", "model access"],
["429 rate limit reached for org-private", "rate limit"],
- ["network failure ECONNRESET for org-private", "network connection"],
- ["request timed out for org-private", "connection timed out"],
] as const) {
const stdout = capture();
const stderr = capture();
@@ -1702,6 +1700,58 @@ describe("CLI", () => {
}
});
+ test("surfaces underlying scanner errors instead of inventing a model outage", async () => {
+ for (const message of [
+ "Could not save the Codex Security scan: UNIQUE constraint failed: scans.scan_dir",
+ "sandbox-exec: sandbox_apply: Operation not permitted during network setup.",
+ "network failure ECONNRESET while connecting to the model.",
+ "request timed out while reading the scanner response.",
+ ]) {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async () => {
+ throw new CodexSecurityError(message);
+ },
+ preflight: async () => fakePreflight(),
+ close: async () => {},
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(2);
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain(`codex-security: ${message}\n`);
+ expect(stderr.text()).not.toContain("model service could not be reached");
+ }
+ });
+
+ test("redacts credentials in underlying network errors", async () => {
+ const stdout = capture();
+ const stderr = capture();
+ const deps = dependencies();
+ deps.createSecurity = () => ({
+ run: async () => {
+ throw new CodexSecurityError(
+ `network failure ECONNRESET ${SYNTHETIC_CREDENTIALS}`,
+ );
+ },
+ preflight: async () => fakePreflight(),
+ close: async () => {},
+ });
+
+ expect(
+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),
+ ).toBe(2);
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain(
+ `network failure ECONNRESET ${REDACTED_CREDENTIALS}`,
+ );
+ expect(stderr.text()).not.toContain("SYNTHETIC_KEY_123");
+ expect(stderr.text()).not.toContain("model service could not be reached");
+ });
+
test("reports database connection failures without claiming the model network failed", async () => {
const stdout = capture();
const stderr = capture();