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(config): honor selected profile approval policy (#530)

Sylvester Kaczmarekf8aeff233d6a
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
index cbcc0d11f..a996327d3 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
@@ -1706,10 +1706,12 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,
mergeProfileTelemetry
? {
profile: "selected",
+ approval_policy: "never",
profiles: {
...profiles,
selected: {
...profiles.selected,
+ approval_policy: "on-request",
...(index === 4 || mergeProfileTelemetry
? { skills }
: {}),
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index 606c65d47..3bdd2d0f3 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -637,6 +637,8 @@ The scan profile allows reads across the local filesystem and writes to workspac
roots. Execution approvals are reviewed automatically and may grant extra
permissions for an operation. Set `codexOverrides.approval_policy: "never"`
(or CLI `--codex 'approval_policy="never"'`) to deny permission requests.
+If you select a Codex profile, its explicit `approval_policy` takes precedence
+over the root setting.
Host and network restrictions still apply.
Repository contents, model output, and imported artifacts do not authorize
diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.ts
index ee4b71f9d..57513b6fa 100644
--- a/sdk/typescript/src/config.ts
+++ b/sdk/typescript/src/config.ts
@@ -178,10 +178,10 @@ export function inlineToml(value: JsonValue): string {
export function scanApprovalPolicy(
config: Readonly<JsonObject>,
): "never" | "on-request" {
- return config["approval_policy"] === "never" ||
- selectedScanProfile(config)?.["approval_policy"] === "never"
- ? "never"
- : "on-request";
+ const configured =
+ selectedScanProfile(config)?.["approval_policy"] ??
+ config["approval_policy"];
+ return configured === "never" ? "never" : "on-request";
}
function selectedScanProfile(
diff --git a/sdk/typescript/tests-ts/api-credentials.test.ts b/sdk/typescript/tests-ts/api-credentials.test.ts
index 0b50f8ca0..ee91b4dc1 100644
--- a/sdk/typescript/tests-ts/api-credentials.test.ts
+++ b/sdk/typescript/tests-ts/api-credentials.test.ts
@@ -29,7 +29,7 @@ describe("CodexSecurity orchestration", () => {
"profile-providers-ambient",
"profile-inherited-cwd",
"profile-overridden-cwd",
- "profile-strict",
+ "profile-policy-override",
"null optional args",
"null optional cwd",
])(
@@ -40,7 +40,7 @@ describe("CodexSecurity orchestration", () => {
const profileProviders = profile && selection !== "profile";
const inheritedCwd = selection === "profile-inherited-cwd";
const overriddenCwd = selection === "profile-overridden-cwd";
- const strict = selection === "profile-strict";
+ const policyOverride = selection === "profile-policy-override";
const root = await temporaryDirectory();
const repository = join(root, "repository");
const home = join(root, "model-home");
@@ -85,7 +85,7 @@ describe("CodexSecurity orchestration", () => {
}
: definition;
const overrides = {
- ...(strict ? { approval_policy: "never" } : {}),
+ ...(policyOverride ? { approval_policy: "never" } : {}),
...(profile
? {
profile: "review",
@@ -93,7 +93,7 @@ describe("CodexSecurity orchestration", () => {
review: {
model_provider: "synthetic.provider",
service_tier: "fast",
- ...(strict ? { approval_policy: "on-request" } : {}),
+ ...(policyOverride ? { approval_policy: "on-request" } : {}),
...(profileProviders
? {
model_providers: {
@@ -217,8 +217,8 @@ describe("CodexSecurity orchestration", () => {
"synthetic.provider",
);
expect(captured?.config?.["service_tier"]).toBe("fast");
- if (strict)
- expect(captured?.config?.["approval_policy"]).toBe("never");
+ if (policyOverride)
+ expect(captured?.config?.["approval_policy"]).toBe("on-request");
} else {
const saved = parseToml(
await readFile(join(runtimeHome, "config.toml"), "utf8"),
diff --git a/sdk/typescript/tests-ts/api-preflight-config.test.ts b/sdk/typescript/tests-ts/api-preflight-config.test.ts
index 903015757..ca9a77587 100644
--- a/sdk/typescript/tests-ts/api-preflight-config.test.ts
+++ b/sdk/typescript/tests-ts/api-preflight-config.test.ts
@@ -261,23 +261,30 @@ describe("CodexSecurity preflight configuration", () => {
});
});
- test("preserves a strict approval policy from the selected profile", () => {
- const config = {
- approval_policy: "on-request",
- profile: "strict",
- profiles: {
- strict: { approval_policy: "never", model: "profile-model" },
- other: { approval_policy: "on-request" },
- },
- };
+ test.each([
+ ["on-request", "never"],
+ ["never", "on-request"],
+ ] as const)(
+ "lets root %s use the selected profile's %s approval policy",
+ (rootPolicy, profilePolicy) => {
+ const config = {
+ approval_policy: rootPolicy,
+ profile: "selected",
+ profiles: {
+ selected: { approval_policy: profilePolicy, model: "profile-model" },
+ other: { approval_policy: rootPolicy },
+ },
+ };
- expect(scanRuntimeCodexConfig(config)).toMatchObject({
- approval_policy: "never",
- approvals_reviewer: "auto_review",
- profiles: { strict: { model: "profile-model" }, other: {} },
- });
- expect(config.profiles.strict.approval_policy).toBe("never");
- });
+ expect(scanRuntimeCodexConfig(config)).toMatchObject({
+ approval_policy: profilePolicy,
+ approvals_reviewer: "auto_review",
+ profiles: { selected: { model: "profile-model" }, other: {} },
+ });
+ expect(config.approval_policy).toBe(rootPolicy);
+ expect(config.profiles.selected.approval_policy).toBe(profilePolicy);
+ },
+ );
test("removes execution and permission overrides from every configured profile", () => {
const original = {
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 34eba77a2..0f0155dcd 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -990,9 +990,9 @@ describe("CodexSecurity orchestration", () => {
);
test.each([
- ["root configuration", { approval_policy: "never" }],
+ ["root configuration", { approval_policy: "never" }, "never"],
[
- "selected profile",
+ "selected never profile",
{
approval_policy: "on-request",
profile: "strict",
@@ -1000,10 +1000,22 @@ describe("CodexSecurity orchestration", () => {
strict: { approval_policy: "never", model: "profile-model" },
},
},
+ "never",
+ ],
+ [
+ "selected on-request profile",
+ {
+ approval_policy: "never",
+ profile: "review",
+ profiles: {
+ review: { approval_policy: "on-request", model: "profile-model" },
+ },
+ },
+ "on-request",
],
] as const)(
- "preserves strict approvals from %s in scan threads and saved recipes",
- async (_source, codexOverrides) => {
+ "preserves approvals from %s in scan threads and saved recipes",
+ async (_source, codexOverrides, approvalPolicy) => {
const { root, repository, codexHome } = await runtimeDirectories();
let threadOptions: Record<string, unknown> | undefined;
let recipe: Record<string, unknown> | undefined;
@@ -1023,8 +1035,11 @@ describe("CodexSecurity orchestration", () => {
}
return mockWorkbench(args, input);
},
- createCodex: () => ({
+ createCodex: (codexOptions) => ({
startThread: (options: Record<string, unknown>) => {
+ expect(codexOptions.config).toMatchObject({
+ approval_policy: approvalPolicy,
+ });
threadOptions = options;
return {
id: null,
@@ -1038,9 +1053,9 @@ describe("CodexSecurity orchestration", () => {
await expect(
client.run(repository, { outputDir: join(root, "scan") }),
).rejects.toThrow("scan approval policy captured");
- expect(threadOptions).toMatchObject({ approvalPolicy: "never" });
+ expect(threadOptions).toMatchObject({ approvalPolicy });
expect(recipe).toMatchObject({
- config: { approval_policy: "never" },
+ config: { approval_policy: approvalPolicy },
});
await client.close();
},
diff --git a/sdk/typescript/tests-ts/config-approval-policy.test.ts b/sdk/typescript/tests-ts/config-approval-policy.test.ts
new file mode 100644
index 000000000..650dcebd4
--- /dev/null
+++ b/sdk/typescript/tests-ts/config-approval-policy.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, test } from "bun:test";
+import { scanApprovalPolicy } from "../src/config.js";
+
+describe("scan approval policy", () => {
+ test("lets the selected profile override the root approval policy", () => {
+ expect(
+ scanApprovalPolicy({
+ approval_policy: "never",
+ profile: "review",
+ profiles: {
+ review: { approval_policy: "on-request" },
+ },
+ }),
+ ).toBe("on-request");
+
+ expect(
+ scanApprovalPolicy({
+ approval_policy: "on-request",
+ profile: "unattended",
+ profiles: {
+ unattended: { approval_policy: "never" },
+ },
+ }),
+ ).toBe("never");
+ });
+
+ test.each([undefined, null])(
+ "falls back to the root policy when the profile policy is %p",
+ (policy) => {
+ expect(
+ scanApprovalPolicy({
+ approval_policy: "never",
+ profile: "review",
+ profiles: {
+ review: policy === undefined ? {} : { approval_policy: policy },
+ },
+ }),
+ ).toBe("never");
+ },
+ );
+
+ test("ignores unselected profiles and preserves the default policy", () => {
+ expect(
+ scanApprovalPolicy({
+ profiles: { unattended: { approval_policy: "never" } },
+ }),
+ ).toBe("on-request");
+ });
+});