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(cli): report local failures from mock scans (#2567)

Michael D'Angelo770d369c127e
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 22c35c36f..8016dc431 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -10472,6 +10472,7 @@ async function executeScan(
let patchDaybreakFeatures: JsonObject = {};
let selectedAuthentication: ScanAuthentication | null = null;
let repository = "";
+ let runningMockScan = false;
let failed = false;
let failure: unknown;
try {
@@ -11115,7 +11116,9 @@ async function executeScan(
if (arguments_.dryRun) {
preflight = await security.preflight(repository, options);
} else {
+ runningMockScan = arguments_.mock === true;
result = await security.run(repository, options);
+ runningMockScan = false;
scanDir = result.scanDir;
repository = resolve(dependencies.currentDirectory(), repository);
if (arguments_.validate) {
@@ -11313,7 +11316,9 @@ async function executeScan(
if (failed) {
const costLimitFailure =
failure instanceof ScanCostLimitExceededError ? failure : undefined;
- const classification = classifyScanFailure(failure);
+ const classification = runningMockScan
+ ? "local"
+ : classifyScanFailure(failure);
const message =
failure instanceof OutputInsideProtectedRootError
? errorMessage(protectedRootErrorMessage(failure))
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 5f2f31284..c8872c4e1 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -5049,6 +5049,25 @@ describe("CLI", () => {
}
});
+ test("reports an unreadable mock scan artifact as a local failure", async () => {
+ const message =
+ "Could not save the mock scan: scan-manifest.json: [Errno 13] Permission denied";
+ const { stdout, stderr, runCli } = createCliTest(main);
+ const deps = dependencies();
+ deps.createSecurity = () => failingSecurity(message);
+
+ expect(
+ await runCli(["scan", ".", "--mock", "--json", "--verbose"], deps),
+ ).toBe(2);
+ expect(JSON.parse(stdout.text())).toEqual({
+ status: "failed",
+ code: "SCAN_FAILED",
+ message,
+ });
+ expect(stderr.text()).toContain(message);
+ expect(stderr.text()).toContain('scan.failed classification="local"');
+ });
+
test("keeps model authorization advice for genuine transport failures", async () => {
// The bypass must not swallow real 401/403 handling, and the advice must
// still replace upstream text that can name the organization or project.