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(windows): preserve literal paths when loading scan policy (#2510)

Michael D'Angeloe0de9ee32395
diff --git a/plugins/codex-security/references/core-scan.md b/plugins/codex-security/references/core-scan.md
index c22526831..e6a4fd33d 100644
--- a/plugins/codex-security/references/core-scan.md
+++ b/plugins/codex-security/references/core-scan.md
@@ -23,7 +23,7 @@ When the assigned reviews have returned, reconcile their evidence and submit the
Use an existing offline search tool. Prefer native ripgrep, with local `git grep`, `find`, or `grep` as alternatives; do not invoke download-capable wrappers or install tools. Pass a verified search command to workers when they need it.
-Resolve inherited policy with `<plugin_dir>/scripts/launch_codex_security_mcp --helper resolve-security-md --repo <repo_root> --scope <file_or_directory> --out -` (`launch_codex_security_mcp.cmd` on Windows). Reuse the result for the same directory or packet; the closest nested policy takes precedence. Apply it to reportability as well as architecture. If policy includes an example or fixture's application boundaries, assess those boundaries with synthetic impact rather than substituting the enclosing product's disclosure eligibility. Explicit user exclusions still control scope.
+Resolve inherited policy with `<plugin_dir>/scripts/launch_codex_security_mcp --helper resolve-security-md --repo <repo_root> --scope <file_or_directory> --out -`. On Windows, use the PowerShell command in `security-guidance.md` and pass it to workers that resolve policy. Reuse the result for the same directory or packet; the closest nested policy takes precedence. Apply it to reportability as well as architecture. If policy includes an example or fixture's application boundaries, assess those boundaries with synthetic impact rather than substituting the enclosing product's disclosure eligibility. Explicit user exclusions still control scope.
## Secrets Exposed In Source
diff --git a/plugins/codex-security/references/security-guidance.md b/plugins/codex-security/references/security-guidance.md
index 7bc618d97..86d60d03f 100644
--- a/plugins/codex-security/references/security-guidance.md
+++ b/plugins/codex-security/references/security-guidance.md
@@ -12,7 +12,20 @@ Compile the full `SECURITY.md` policy for a file or directory with:
<plugin_dir>/scripts/launch_codex_security_mcp --helper resolve-security-md --repo <repo_root> --scope <file_or_directory> --out <output_path_or_dash>
```
-On Windows, use `launch_codex_security_mcp.cmd` with the same arguments. The launcher reuses the plugin's configured or bundled Node runtime and preserves the working directory for relative helper paths.
+In Windows PowerShell, the SDK supplies `$env:CODEX_SECURITY_PLUGIN_ROOT` and `$env:CODEX_SECURITY_REPOSITORY`. For a standalone invocation, set them to the selected plugin and repository directories. Set `$env:scopePolicyPath` to the repository-relative file or directory without a trailing separator. Use `.` for the repository root. Run these lines in one shell command.
+
+```powershell
+$global:LASTEXITCODE = $null
+& {
+ $PSNativeCommandArgumentPassing = 'Legacy'
+ $PSNativeCommandUseErrorActionPreference = $false
+ cmd.exe /d /v:off /s /c '""%CODEX_SECURITY_PLUGIN_ROOT%\scripts\launch_codex_security_mcp.cmd" --helper resolve-security-md --repo "%CODEX_SECURITY_REPOSITORY%\." --scope "%scopePolicyPath%" --out -"'
+}
+if ($null -eq $global:LASTEXITCODE) { throw 'PowerShell did not return a cmd.exe exit code. Check PATH and PATHEXT.' }
+if ($global:LASTEXITCODE -ne 0) { exit $global:LASTEXITCODE }
+```
+
+The quoted environment variables and disabled delayed expansion preserve literal `%` and `!` in paths. For file output, put the destination in `$env:scopePolicyOutput` and use `--out "%scopePolicyOutput%"` inside the same command string. The selected launcher uses its configured or bundled Node runtime and preserves the working directory for relative output paths.
Use the full option names shown above. `--help` and `-h` show usage; abbreviated long option names are not accepted.
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index baffd734f..dc0f8a4db 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -3299,6 +3299,24 @@ export class CodexSecurity {
scopeFileCount === null
? basePrompt
: `${basePrompt}\nThe SDK's current in-scope file-count estimate is ${scopeFileCount}; use it for scan progress unless exact scoped-source enumeration establishes a different total before review begins.`;
+ if (
+ process.platform === "win32" &&
+ mode === "standard" &&
+ this.#dependencies.hostedScan === undefined
+ ) {
+ prompt += [
+ "",
+ "When the selected workflow uses its launcher to resolve SECURITY.md, set $env:scopePolicyPath to the repository-relative scope without a trailing separator (use . for the root). Run these PowerShell lines together and give them to workers that resolve inherited policy.",
+ "$global:LASTEXITCODE = $null",
+ "& {",
+ " $PSNativeCommandArgumentPassing = 'Legacy'",
+ " $PSNativeCommandUseErrorActionPreference = $false",
+ String.raw` cmd.exe /d /v:off /s /c '""%CODEX_SECURITY_PLUGIN_ROOT%\scripts\launch_codex_security_mcp.cmd" --helper resolve-security-md --repo "%CODEX_SECURITY_REPOSITORY%\." --scope "%scopePolicyPath%" --out -"'`,
+ "}",
+ "if ($null -eq $global:LASTEXITCODE) { throw 'PowerShell did not return a cmd.exe exit code. Check PATH and PATHEXT.' }",
+ "if ($global:LASTEXITCODE -ne 0) { exit $global:LASTEXITCODE }",
+ ].join("\n");
+ }
if (options.resumeScanId !== undefined) {
prompt +=
"\nResume the existing Deep Scan through its coordinator. Preserve completed workers and saved artifacts; do not recreate the scan directory or restart completed analysis. If the coordinator already finished, continue with completion of this same scan.";
diff --git a/sdk/typescript/src/custom-validation-prompt.ts b/sdk/typescript/src/custom-validation-prompt.ts
index 30a7d547b..edd7cec83 100644
--- a/sdk/typescript/src/custom-validation-prompt.ts
+++ b/sdk/typescript/src/custom-validation-prompt.ts
@@ -9,6 +9,7 @@ import { PLUGIN_NAME } from "./runtime.js";
// the ordinary validation sequence with a custom-validation request.
const SOURCES = {
"references/core-scan.md": [
+ "07abac7382a66338bfbe3def9a0e89e715a89561332c88ccb4477f97b6e84fe5",
"0e301a70d9f20acbb797f5eafcac84c09dd0513991714812d5c4f7b1f64a4a89",
"7690b6c854de07ff15984f6d2c25ddfa1f6ae65f65876cadf2f904054b4f0679",
"83bafdc4089803e631eaaa86ec57167c7da3f51794514d0dcdb62c5afdced8a7",
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 87d081bb6..5b15b5317 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -16989,6 +16989,13 @@ if __name__ == "__main__":
expect(policyCommand).toMatch(
/^<plugin_dir>\/scripts\/launch_codex_security_mcp --helper resolve-security-md /,
);
+ if (process.platform === "win32") {
+ const windowsCommand = policyReference.match(
+ /```powershell\r?\n([\s\S]+?)\r?\n```/u,
+ )?.[1];
+ expect(windowsCommand).toBeDefined();
+ expect(prompt).toContain(windowsCommand!.replaceAll("\r\n", "\n"));
+ }
const helper = shellEnvironmentReference(
"CODEX_SECURITY_PLUGIN_ROOT",
"/scripts/launch_codex_security_mcp",
diff --git a/sdk/typescript/tests-ts/mcp-launcher.test.ts b/sdk/typescript/tests-ts/mcp-launcher.test.ts
index 9368b39d1..d9259c636 100644
--- a/sdk/typescript/tests-ts/mcp-launcher.test.ts
+++ b/sdk/typescript/tests-ts/mcp-launcher.test.ts
@@ -2,6 +2,7 @@ import { spawnSync } from "node:child_process";
import {
chmod,
copyFile,
+ cp,
mkdir,
mkdtemp,
readFile,
@@ -15,6 +16,140 @@ import { expect, test } from "bun:test";
import { PLUGIN_ROOT } from "./plugin-root.js";
import { removeTemporaryDirectory } from "./support/temporary-directories.js";
+test.skipIf(process.platform !== "win32")(
+ "runs the documented policy command with long and literal paths and preserves the selected launcher's exit code",
+ async () => {
+ const root = await realpath(
+ await mkdtemp(join(tmpdir(), "policy-launch-")),
+ );
+ try {
+ const reference = await readFile(
+ join(PLUGIN_ROOT, "references", "security-guidance.md"),
+ "utf8",
+ );
+ const command = reference.match(
+ /```powershell\r?\n([\s\S]+?)\r?\n```/u,
+ )?.[1];
+ expect(command).toBeDefined();
+ const selected = join(
+ root,
+ "p".repeat(100),
+ "q".repeat(100),
+ "plugin %QA_TOKEN%",
+ );
+ const launcher = join("scripts", "launch_codex_security_mcp.cmd");
+ expect(join(selected, launcher).length).toBeGreaterThanOrEqual(260);
+ await mkdir(join(selected, "scripts"), { recursive: true });
+ await copyFile(join(PLUGIN_ROOT, launcher), join(selected, launcher));
+ await cp(join(PLUGIN_ROOT, "mcp"), join(selected, "mcp"), {
+ recursive: true,
+ });
+ const repo = join(root, "repo %QA_TOKEN% !QA_TOKEN! [1]");
+ const scope = "nested %QA_TOKEN% !QA_TOKEN! [2]";
+ await mkdir(join(repo, scope), { recursive: true });
+ await writeFile(join(repo, "SECURITY.md"), "literal repository policy\n");
+ await writeFile(
+ join(repo, scope, "SECURITY.md"),
+ "literal scope policy\n",
+ );
+ const custom = join(root, "custom launcher");
+ await mkdir(join(custom, "scripts"), { recursive: true });
+ await writeFile(
+ join(custom, launcher),
+ "@echo selected custom launcher 1>&2\r\n@exit /b 23\r\n",
+ );
+ const system = join(process.env["SystemRoot"]!, "System32");
+ const shells = [
+ join(system, "WindowsPowerShell", "v1.0", "powershell.exe"),
+ ];
+ const pwsh = Bun.which("pwsh.exe");
+ if (pwsh !== null) shells.push(pwsh);
+ for (const shell of shells) {
+ const run = (
+ plugin: string,
+ scopePath: string,
+ pathExtensions = ".COM;.EXE;.BAT;.CMD",
+ strict = false,
+ ) =>
+ spawnSync(
+ shell,
+ [
+ "-NoProfile",
+ "-NonInteractive",
+ "-EncodedCommand",
+ Buffer.from(
+ [
+ ...(strict
+ ? [
+ "$PSNativeCommandArgumentPassing = 'Standard'",
+ "$PSNativeCommandUseErrorActionPreference = $true",
+ "$ErrorActionPreference = 'Stop'",
+ ]
+ : []),
+ "$global:LASTEXITCODE = 0",
+ command,
+ 'Write-Output "after-policy $PSNativeCommandArgumentPassing/$PSNativeCommandUseErrorActionPreference/$ErrorActionPreference"',
+ ].join("\n"),
+ "utf16le",
+ ).toString("base64"),
+ ],
+ {
+ cwd: root,
+ encoding: "utf8",
+ windowsHide: true,
+ env: {
+ SystemRoot: process.env["SystemRoot"],
+ PATH: system,
+ PATHEXT: pathExtensions,
+ CODEX_MCP_NODE_PATH: Bun.which("node")!,
+ CODEX_SECURITY_PLUGIN_ROOT: plugin,
+ CODEX_SECURITY_REPOSITORY: repo,
+ scopePolicyPath: scopePath,
+ QA_TOKEN: "expanded-directory",
+ },
+ },
+ );
+ const success = run(selected, scope);
+ expect(success.status, success.stderr || success.error?.message).toBe(
+ 0,
+ );
+ expect(success.stdout, success.stderr).toContain(
+ "literal repository policy",
+ );
+ expect(success.stdout).toContain("literal scope policy");
+ expect(success.stdout).toContain("after-policy");
+ const missing = run(selected, "missing");
+ expect(missing.status).toBe(2);
+ expect(missing.stderr).toContain("scan scope does not exist");
+ expect(missing.stdout).not.toContain("after-policy");
+ const customFailure = run(custom, scope);
+ expect(customFailure.status).toBe(23);
+ expect(customFailure.stderr).toContain("selected custom launcher");
+ expect(customFailure.stdout).not.toContain("after-policy");
+ if (shell === shells[0]) {
+ const unavailable = run(custom, scope, "");
+ expect(unavailable.status).not.toBe(0);
+ expect(unavailable.stderr).toContain("cmd.exe exit code");
+ expect(unavailable.stdout).not.toContain("after-policy");
+ } else {
+ const strictSuccess = run(selected, scope, undefined, true);
+ expect(strictSuccess.status, strictSuccess.stderr).toBe(0);
+ expect(strictSuccess.stdout).toContain("literal scope policy");
+ expect(strictSuccess.stdout).toContain(
+ "after-policy Standard/True/Stop",
+ );
+ const strictFailure = run(custom, scope, undefined, true);
+ expect(strictFailure.status).toBe(23);
+ expect(strictFailure.stderr).toContain("selected custom launcher");
+ expect(strictFailure.stdout).not.toContain("after-policy");
+ }
+ }
+ } finally {
+ await removeTemporaryDirectory(root);
+ }
+ },
+);
+
test.skipIf(process.platform !== "win32")(
"launches the PATH Node executable independently of command extensions and the caller directory",
async () => {