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

test(windows): verify worker ACLs with a host-built plugin (#2127)

Michael D'Angelof7a09d9f08f2
diff --git a/plugins/codex-security/mcp-app/scripts/test_host_build.mts b/plugins/codex-security/mcp-app/scripts/test_host_build.mts
index 8d75c34b4..385669605 100644
--- a/plugins/codex-security/mcp-app/scripts/test_host_build.mts
+++ b/plugins/codex-security/mcp-app/scripts/test_host_build.mts
@@ -120,20 +120,30 @@ test("builds and loads the host runtime from standalone plugin source", async (t
await mkdir(dirname(join(output, file)), { recursive: true });
await copyFile(join(plugin, file), join(output, file));
}
+ const env = {
+ ...process.env,
+ NODE_TEST_CONTEXT: undefined,
+ CODEX_SECURITY_TEST_PLUGIN_ROOT: output,
+ };
runNode(
[
"--experimental-strip-types",
"--test",
"mcp-app/tests/test_plugin_bytecode.ts",
],
- {
- env: {
- ...process.env,
- NODE_TEST_CONTEXT: undefined,
- CODEX_SECURITY_TEST_PLUGIN_ROOT: output,
- },
- },
+ { env },
);
+ if (windows) {
+ runNode(
+ [
+ "--experimental-strip-types",
+ "--test",
+ "--test-name-pattern=^Deep worker runtime settings at the child-process boundary$",
+ "mcp-app/tests/test_deep_scan_executor.ts",
+ ],
+ { env },
+ );
+ }
});
test("rejects an unsupported native host before replacing existing output", async (t) => {
diff --git a/plugins/codex-security/mcp-app/tests/support/windows-output-fixture.ts b/plugins/codex-security/mcp-app/tests/support/windows-output-fixture.ts
index 906a9bd30..4bba03a75 100644
--- a/plugins/codex-security/mcp-app/tests/support/windows-output-fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/support/windows-output-fixture.ts
@@ -1,52 +1,45 @@
import assert from "node:assert/strict";
-import { spawnSync } from "node:child_process";
+import { execFileSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { realpath } from "node:fs/promises";
import { createRequire } from "node:module";
+import { tmpdir } from "node:os";
import path from "node:path";
-import { fileURLToPath } from "node:url";
-export function windowsAcl(directory: string): string {
- const system = path.join(process.env.SystemRoot ?? "C:\\Windows", "System32");
- const result = spawnSync(
- path.join(system, "WindowsPowerShell", "v1.0", "powershell.exe"),
- [
- "-NoLogo",
- "-NoProfile",
- "-NonInteractive",
- "-Command",
- "$ErrorActionPreference = 'Stop'; Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $env:CODEX_SECURITY_TEST_ACL_PATH | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl",
- ],
- {
- encoding: "utf8",
- env: {
- ...process.env,
- CODEX_SECURITY_TEST_ACL_PATH: directory,
- PSModulePath: path.join(system, "WindowsPowerShell", "v1.0", "Modules"),
- },
- },
- );
- assert.equal(result.status, 0, result.stderr);
- return result.stdout.trim();
+const icacls = path.join(
+ process.env.SystemRoot ?? "C:\\Windows",
+ "System32",
+ "icacls.exe",
+);
+
+export function windowsAcl(target: string): string {
+ const work = mkdtempSync(path.join(tmpdir(), "codex-security-acl-"));
+ try {
+ const aclFile = path.join(work, "dacl.txt");
+ execFileSync(icacls, [target, "/save", aclFile, "/q"]);
+ // icacls writes the relative path followed by its SDDL, in UTF-16LE.
+ const dacl = readFileSync(aclFile, "utf16le")
+ .trimEnd()
+ .split(/\r?\n/u)
+ .at(-1);
+ assert.ok(dacl && dacl.startsWith("D:"));
+ return dacl;
+ } finally {
+ rmSync(work, { recursive: true, force: true });
+ }
}
export async function privateWindowsOutputRoot(root: string): Promise<string> {
- const icacls = path.join(
- process.env.SystemRoot ?? "C:\\Windows",
- "System32",
- "icacls.exe",
- );
- assert.equal(
- spawnSync(icacls, [root, "/grant", "*S-1-1-0:(OI)(CI)R"]).status,
- 0,
- );
+ execFileSync(icacls, [root, "/grant", "*S-1-1-0:(OI)(CI)R"]);
assert.ok(windowsAcl(root).includes(";;;WD)"));
root = path.join(root, "private scan artifacts");
// Use the same existing atomic creator as SDK scan-output preparation.
+ const pluginRoot = process.env.CODEX_SECURITY_TEST_PLUGIN_ROOT;
+ const nativeRoot = pluginRoot
+ ? path.resolve(pluginRoot, "mcp/native")
+ : path.resolve(import.meta.dirname, "../../../native/prebuilt");
const native = createRequire(import.meta.url)(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- `../../../native/prebuilt/win32-${process.arch}/windows.node`,
- ),
+ path.join(nativeRoot, `win32-${process.arch}`, "windows.node"),
) as { createPrivateWindowsDirectory(path: Buffer): number };
assert.equal(
native.createPrivateWindowsDirectory(
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 dd97f60e3..31052d7aa 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
@@ -122,10 +122,14 @@ try {
}
});
+ await test(
+ "Deep worker runtime settings at the child-process boundary",
+ testWorkerRuntimeSettings,
+ );
+
await test("Deep worker runtime settings", async (t) => {
await check(t, testLargeScopeTransport);
await check(t, testOpenAiCredentialsReachWorker);
- await check(t, testWorkerRuntimeSettings);
await check(t, testUnsupportedProviderSnapshotFailsBeforeLaunch);
await check(
t,