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): preserve permission errors from plugin installation (#2247)

Michael D'Angelo4ba18abafd4e
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 951ea9e89..9112520e1 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -217,6 +217,7 @@ import {
LocalPluginBootstrapError,
OutputDirectoryError,
OutputInsideProtectedRootError,
+ PluginBootstrapError,
PluginPythonUnavailableError,
SandboxUnavailableError,
errorMessage,
@@ -10364,21 +10365,19 @@ async function executeScan(
if (failed) {
const costLimitFailure =
failure instanceof ScanCostLimitExceededError ? failure : undefined;
+ const classification = classifyScanFailure(failure);
const message =
failure instanceof OutputInsideProtectedRootError
? errorMessage(protectedRootErrorMessage(failure))
: scanFailureMessage(
failure,
+ classification,
selectedAuthentication,
providerOptions.provider,
);
diagnostic("scan.failed", {
classification:
- costLimitFailure !== undefined
- ? "cost_limit_exceeded"
- : isLocalScanFailure(failure)
- ? "local"
- : classifyConnectionFailure(failure),
+ costLimitFailure !== undefined ? "cost_limit_exceeded" : classification,
max_cost_usd: costLimitFailure?.maxCostUsd,
estimated_usd: costLimitFailure?.cost.estimatedUsd,
cost_estimate:
@@ -10672,6 +10671,15 @@ function isLocalScanFailure(error: unknown): boolean {
);
}
+function classifyScanFailure(error: unknown) {
+ if (isLocalScanFailure(error)) return "local";
+ const classification = classifyConnectionFailure(error);
+ // Installing the plugin can be denied filesystem access before any model request.
+ if (classification === "forbidden" && error instanceof PluginBootstrapError)
+ return "plugin_bootstrap";
+ return classification;
+}
+
function authenticationFailureMessage(
authentication: ScanAuthentication | null,
): string {
@@ -10714,14 +10722,14 @@ function authenticationFailureMessage(
function scanFailureMessage(
error: unknown,
+ classification: ReturnType<typeof classifyScanFailure>,
authentication: ScanAuthentication | null,
provider?: string,
): string {
// A local failure keeps its own message. Classification matches bare words
// such as "permission denied" anywhere in the text, so an EACCES from a
// read-only TMPDIR would otherwise be reported as a credential problem.
- if (isLocalScanFailure(error)) return diagnosticValue(error);
- const classification = classifyConnectionFailure(error);
+ if (classification === "local") return diagnosticValue(error);
if (
provider === "amazon-bedrock" ||
authentication?.method === "aws_credentials"
@@ -10796,6 +10804,7 @@ function scanFailureMessage(
case "rate_limited":
return `${detail}The configured account reached its rate limit. Wait and retry.`;
case "network_error":
+ case "plugin_bootstrap":
case "timeout":
case "unknown":
return diagnosticValue(error);
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 877f9409f..ea9d880bc 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -231,6 +231,47 @@ describe("CLI", () => {
}
});
+ test.each([
+ ["--auth", "chatgpt"],
+ ["--auth", "api-key"],
+ ["--codex", 'model_provider="amazon-bedrock"'],
+ ])(
+ "reports plugin installation permission errors with %s %s",
+ async (flag, value) => {
+ const message =
+ "Codex plugin bootstrap failed: failed to create plugin cache directory: Permission denied (os error 13)";
+ const deps = dependencies({
+ environment: { OPENAI_API_KEY: "synthetic-key" },
+ onRun: () => {
+ throw new PluginBootstrapError(message);
+ },
+ });
+ for (const json of [false, true]) {
+ const { stdout, stderr, runCli } = createCliTest(main);
+ expect(
+ await runCli(
+ [
+ "scan",
+ ".",
+ flag,
+ value,
+ "--verbose",
+ ...(json ? ["--json"] : []),
+ ],
+ deps,
+ ),
+ ).toBe(2);
+ expect(stderr.text()).toContain(message);
+ expect(stderr.text()).toContain(
+ 'scan.failed classification="plugin_bootstrap"',
+ );
+ expect(stderr.text()).not.toContain("cannot access the configured");
+ if (json) expect(JSON.parse(stdout.text()).message).toBe(message);
+ else expect(stdout.text()).toBe("");
+ }
+ },
+ );
+
test("passes the safety identifier as a per-scan option", async () => {
const onTurn = mock<(repository: string, options: unknown) => void>();
const stderr = captureCli(main, "stderr");