OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(plugin): build the native runtime without the SDK (#965)
mldangelo-oai0a98de884b36
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex f35c37671..a4056f263 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -421,6 +421,37 @@ jobs:if-no-files-found: warnretention-days: 14+ plugin-host:+ name: standalone plugin / ${{ matrix.os }}+ needs: validate-title+ if: needs.validate-title.outputs.ci-mode == 'full'+ runs-on: ${{ matrix.os }}+ timeout-minutes: 20+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, macos-latest, windows-latest]+ steps:+ - name: Checkout plugin source without the SDK+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ persist-credentials: false+ sparse-checkout: plugins/codex-security+ - name: Set up pnpm+ uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0+ with:+ package_json_file: package.json+ cache: true+ cache_dependency_path: plugins/codex-security/mcp-app/pnpm-lock.yaml+ - name: Set up Node.js+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ with:+ node-version: "22.13.0"+ - name: Install plugin dependencies+ run: pnpm --dir plugins/codex-security/mcp-app install --frozen-lockfile+ - name: Build and test the standalone host runtime+ run: node --test plugins/codex-security/mcp-app/scripts/test_host_build.mjs+plugin-source:name: plugin source contractsneeds: validate-title@@ -491,6 +522,7 @@ jobs:test,compatibility,mcp,+ plugin-host,plugin-source,]if: always()@@ -501,7 +533,7 @@ jobs:os: [ubuntu-latest, macos-latest]steps:- name: Require every Unix coverage job- if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.static-checks.result != 'success' || needs.package.result != 'success' || needs.test.result != 'success' || needs.compatibility.result != 'success' || needs.mcp.result != 'success' || needs.plugin-source.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')+ if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.static-checks.result != 'success' || needs.package.result != 'success' || needs.test.result != 'success' || needs.compatibility.result != 'success' || needs.mcp.result != 'success' || needs.plugin-host.result != 'success' || needs.plugin-source.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')run: exit 1windows-test:@@ -617,12 +649,13 @@ jobs:name: windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}runs-on: ubuntu-latestif: always()- needs: [validate-title, static-checks, windows-test, windows-verify]+ needs:+ [validate-title, static-checks, plugin-host, windows-test, windows-verify]strategy:fail-fast: falsematrix:node: ["22.13.0", "24"]steps:- name: Require every Windows coverage job- if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.static-checks.result != 'success' || needs.windows-test.result != 'success' || needs.windows-verify.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')+ if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.static-checks.result != 'success' || needs.plugin-host.result != 'success' || needs.windows-test.result != 'success' || needs.windows-verify.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')run: exit 1diff --git a/plugins/codex-security/.gitignore b/plugins/codex-security/.gitignorenew file mode 100644index 000000000..4afa1f3a6--- /dev/null+++ b/plugins/codex-security/.gitignore@@ -0,0 +1 @@+/mcp/diff --git a/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs b/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjsindex 94022da4f..7d0ddb8fb 100644--- a/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs+++ b/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs@@ -9,8 +9,22 @@ import { build } from "esbuild";const root = resolve(import.meta.dirname, "..");const maxChunkBytes = 140_000;-export async function buildMcpApp({ output }) {+export async function buildMcpApp({ output, native = "universal" }) {+ if (native !== "universal" && native !== "host") {+ throw new Error("Native packaging must be universal or host.");+ }const mcpDir = resolve(output);+ const nativeRoot = join(root, "../native", native === "host" ? "dist" : "prebuilt");+ const hostTarget = native === "host"+ ? (await import("../../native/platform.mjs")).nativeTarget+ : undefined;+ const contract = JSON.parse(await readFile(join(root, "../plugin-files.json"), "utf8"));+ const nativeFiles = contract.shippedExact.filter((path) => path.startsWith("mcp/native/"));+ if (hostTarget && !nativeFiles.some((path) =>+ path.startsWith(`mcp/native/${hostTarget}/`) && path.endsWith(".node")+ )) {+ throw new Error(`Unsupported native target: ${hostTarget}.`);+ }execFileSync(process.execPath, ["--run", "build"], {cwd: root,@@ -20,12 +34,14 @@ export async function buildMcpApp({ output }) {await mkdir(mcpDir, { recursive: true });await writeRuntime("server", "main.ts");- const contract = JSON.parse(await readFile(join(root, "../plugin-files.json"), "utf8"));- for (const file of contract.shippedExact.filter((path) => path.startsWith("mcp/native/"))) {+ for (const file of nativeFiles) {const path = file.slice("mcp/native/".length);+ if (hostTarget && path.endsWith(".node") && !path.startsWith(`${hostTarget}/`)) {+ continue;+ }const destination = join(mcpDir, "native", path);await mkdir(dirname(destination), { recursive: true });- await copyFile(join(root, "../native/prebuilt", path), destination);+ await copyFile(join(nativeRoot, path), destination);}await writeRuntime("helpers", "helpers-main.ts");@@ -72,11 +88,14 @@ if (&& pathToFileURL(resolve(invokedPath)).href === import.meta.url) {const args = process.argv.slice(2);- if (args.length !== 2 || args[0] !== "--output") {- console.error("Usage: node scripts/build_mcp_app.mjs --output <directory>");+ if (+ args[0] !== "--output"+ || (args.length !== 2 && !(args.length === 4 && args[2] === "--native"))+ ) {+ console.error("Usage: node scripts/build_mcp_app.mjs --output <directory> [--native universal|host]");process.exitCode = 1;} else {- buildMcpApp({ output: args[1] }).catch((error) => {+ buildMcpApp({ output: args[1], native: args[3] }).catch((error) => {console.error(error instanceof Error ? error.message : error);process.exitCode = 1;});diff --git a/plugins/codex-security/mcp-app/scripts/build_native.mjs b/plugins/codex-security/mcp-app/scripts/build_native.mjsnew file mode 100644index 000000000..fb510d87a--- /dev/null+++ b/plugins/codex-security/mcp-app/scripts/build_native.mjs@@ -0,0 +1,28 @@+#!/usr/bin/env node+import { execFileSync } from "node:child_process";+import { join, resolve } from "node:path";+import { build } from "esbuild";++const root = resolve(import.meta.dirname, "../../native");++await build({+ absWorkingDir: root,+ entryPoints: ["*.mts"],+ outdir: root,+ outExtension: { ".js": ".mjs" },+ format: "esm",+ platform: "node",+ target: "node20"+});++execFileSync("cargo", ["fetch", "--locked"], {+ cwd: root,+ stdio: "inherit"+});++for (const script of ["build.mjs", "notices.mjs"]) {+ execFileSync(process.execPath, [join(root, script)], {+ cwd: root,+ stdio: "inherit"+ });+}diff --git a/plugins/codex-security/mcp-app/scripts/test_host_build.mjs b/plugins/codex-security/mcp-app/scripts/test_host_build.mjsnew file mode 100644index 000000000..1520e28ed--- /dev/null+++ b/plugins/codex-security/mcp-app/scripts/test_host_build.mjs@@ -0,0 +1,158 @@+import assert from "node:assert/strict";+import { execFileSync } from "node:child_process";+import {+ copyFile,+ mkdir,+ mkdtemp,+ readFile,+ readdir,+ rm,+ writeFile,+} from "node:fs/promises";+import { tmpdir } from "node:os";+import { join, relative, resolve, sep } from "node:path";+import test from "node:test";++const plugin = resolve(import.meta.dirname, "../..");++function runNode(args, options = {}) {+ return execFileSync(process.execPath, args, {+ cwd: plugin,+ stdio: "inherit",+ ...options,+ });+}++test("builds and loads the host runtime from standalone plugin source", async (t) => {+ const output = await mkdtemp(join(tmpdir(), "codex-security-host-build-"));+ const mcp = join(output, "mcp");+ t.after(() => rm(output, { recursive: true, force: true }));++ runNode(["mcp-app/scripts/build_native.mjs"]);+ runNode([+ "mcp-app/scripts/build_mcp_app.mjs",+ "--output",+ mcp,+ "--native",+ "host",+ ]);++ const { nativeTarget } = await import("../../native/platform.mjs");+ const contract = JSON.parse(+ await readFile(join(plugin, "plugin-files.json"), "utf8"),+ );+ const actual = (await readdir(mcp, { recursive: true, withFileTypes: true }))+ .filter((entry) => entry.isFile())+ .map((entry) =>+ relative(output, join(entry.parentPath, entry.name)).split(sep).join("/"),+ );+ const expected = contract.shippedExact.filter(+ (path) =>+ path.startsWith("mcp/") &&+ (!path.endsWith(".node") ||+ path.startsWith(`mcp/native/${nativeTarget}/`)),+ );+ assert.deepEqual(actual.sort(), expected.sort());++ const emptyPathEnvironment = {+ ...Object.fromEntries(+ Object.entries(process.env).filter(+ ([key]) => key.toLowerCase() !== "path",+ ),+ ),+ PATH: "",+ };+ const nativeFile = expected.find((path) => path.endsWith(".node"));+ runNode(+ [+ "-e",+ `const assert = require("node:assert/strict");+ const os = require("node:os");+ const native = require(process.argv[1]);+ if (process.platform === "win32") {+ assert.ok(native.windowsArguments().length);+ } else {+ const { username, homedir } = os.userInfo();+ assert.equal(native.userHome(Buffer.from(username)).value.toString(), homedir);+ }`,+ join(output, nativeFile),+ ],+ { env: emptyPathEnvironment },+ );++ const proof =+ process.platform === "win32" ? "proof-windows.mjs" : "proof.mjs";+ runNode(["--expose-gc", join("native", proof)], {+ env: emptyPathEnvironment,+ });++ const windows = process.platform === "win32";+ const launcher = `launch_codex_security_mcp${windows ? ".cmd" : ""}`;+ await mkdir(join(output, "scripts"));+ await copyFile(+ join(plugin, "scripts", launcher),+ join(output, "scripts", launcher),+ );+ const helperArgs = [+ "--helper",+ "resolve-security-md",+ "--repo",+ ".",+ "--list",+ ];+ const launcherOutput = execFileSync(+ windows ? (process.env.ComSpec ?? "cmd.exe") : "sh",+ windows+ ? ["/d", "/s", "/c", `scripts\\${launcher} ${helperArgs.join(" ")}`]+ : [`scripts/${launcher}`, ...helperArgs],+ {+ cwd: output,+ encoding: "utf8",+ env: { ...process.env, CODEX_MCP_NODE_PATH: process.execPath },+ },+ );+ assert.equal(launcherOutput, "[]\n");+});++test("rejects an unsupported native host before replacing existing output", async (t) => {+ const output = await mkdtemp(join(tmpdir(), "codex-security-unsupported-"));+ t.after(() => rm(output, { recursive: true, force: true }));+ const marker = join(output, "keep");+ await writeFile(marker, "previous output");++ const loader = `export function resolve(specifier, context, nextResolve) {+ if (specifier === "../../native/platform.mjs") {+ return {+ url: "data:text/javascript," + encodeURIComponent('export const nativeTarget = "unsupported-platform";'),+ shortCircuit: true,+ };+ }+ return nextResolve(specifier, context);+ }`;+ const register = `import { register } from "node:module";+ register(new URL(${JSON.stringify(`data:text/javascript,${encodeURIComponent(loader)}`)}));`;+ assert.throws(+ () =>+ runNode(+ [+ "--import",+ `data:text/javascript,${encodeURIComponent(register)}`,+ "mcp-app/scripts/build_mcp_app.mjs",+ "--output",+ output,+ "--native",+ "host",+ ],+ { stdio: "pipe", encoding: "utf8" },+ ),+ (error) => {+ assert.equal(error.status, 1);+ assert.equal(+ error.stderr.trim(),+ "Unsupported native target: unsupported-platform.",+ );+ return true;+ },+ );+ assert.equal(await readFile(marker, "utf8"), "previous output");+});diff --git a/plugins/codex-security/native/README.md b/plugins/codex-security/native/README.mdindex 12e50e601..bf2dd46d9 100644--- a/plugins/codex-security/native/README.md+++ b/plugins/codex-security/native/README.md@@ -61,11 +61,23 @@ The build also compiles the test-only `windows-wide-launcher` Rust example. It s## Package inputs-The `native-artifacts` workflow calls all three platform workflows and combines their eight verified payloads into `native-universal-<commit>`. PR validation jobs share one artifact assembled by `node-ci`; release and standalone validation runs assemble their own. The standalone MCP builder and npm package include the same complete `mcp/native` tree; neither compiles nor downloads code at runtime.+With the pinned Rust toolchain installed, build the plugin on its own:++```sh+pnpm --dir plugins/codex-security/mcp-app install --frozen-lockfile+node plugins/codex-security/mcp-app/scripts/build_native.mjs+node plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs --output plugins/codex-security/mcp --native host+```++`build_native.mjs` uses the MCP app's dependencies to compile the TypeScript tools, fetches the locked Cargo dependencies, and writes the host binary and license notices to `native/dist`. `--native host` packages those files for the current platform and architecture under `mcp/`, where the plugin launcher expects them. CI tests this build without the SDK on Linux, macOS, and Windows.++For plugin and npm releases, use the default `--native universal`. It requires all eight verified binaries in `native/prebuilt`.++The `native-artifacts` workflow calls all three platform workflows and combines their eight verified payloads into `native-universal-<commit>`. PR validation jobs share one artifact assembled by `node-ci`; release and standalone validation runs assemble their own. By default, the standalone MCP builder and npm package include the same complete `mcp/native` tree; neither compiles nor downloads code at runtime.The GNU x64 job also runs `notices.mjs` against the locked Cargo metadata. It collects crate licenses and the pinned Rust standard-library notices for both package surfaces. The NAPI crates omit license files from their registry archives, so `licenses/napi.txt` preserves their [pinned upstream license](https://github.com/napi-rs/napi-rs/blob/956e4525fea6a676ea3680b711382f167b899af9/LICENSE). Review that override when upgrading those dependencies.-Before local plugin builds, tests, or Docker builds, select a successful run for the checkout's native sources. You can run `native-artifacts` manually on a pushed branch. Use the artifact name shown by that run; pull-request artifacts use the tested merge commit. From the repository root:+For universal builds, SDK tests, or Docker builds, select a successful run for the checkout's native sources. You can run `native-artifacts` manually on a pushed branch. Use the artifact name shown by that run; pull-request artifacts use the tested merge commit. From the repository root:```shgh run download <run-id> --name native-universal-<commit> --dir plugins/codex-security/native/prebuiltdiff --git a/sdk/typescript/tests-ts/cli-patch.test.ts b/sdk/typescript/tests-ts/cli-patch.test.tsindex 92f3f2645..374e588fe 100644--- a/sdk/typescript/tests-ts/cli-patch.test.ts+++ b/sdk/typescript/tests-ts/cli-patch.test.ts@@ -145,7 +145,7 @@ async function runWorkflow(describe("scan and patch workflow", () => {test.each([false, true])(- "shows progress during baseline preparation and cleans up on failure: %s",+ "shows progress during baseline preparation and cleans up on failure: %p",async (failSnapshot) => {const result = resultWithFindings(["high"]);const stdout = capture();diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 4c1b82f35..02be19530 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -3932,6 +3932,7 @@ describe("GitHub release workflow safeguards", () => {"test","compatibility","mcp",+ "plugin-host","plugin-source","windows-test","windows-verify",@@ -3969,6 +3970,7 @@ describe("GitHub release workflow safeguards", () => {] as const) {const values = {"needs.static-checks.result": upstream,+ "needs.plugin-host.result": upstream,"needs.plugin-source.result": upstream,"needs.package.result": upstream,"needs.compatibility.result": upstream,@@ -3997,9 +3999,15 @@ describe("GitHub release workflow safeguards", () => {"test","compatibility","mcp",+ "plugin-host","plugin-source",],- windows: ["static-checks", "windows-test", "windows-verify"],+ windows: [+ "static-checks",+ "plugin-host",+ "windows-test",+ "windows-verify",+ ],})) {for (const dependency of dependencies) {for (const result of ["failure", "cancelled", "skipped"]) {diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.tsindex 58d4791ae..dc1e83bbd 100644--- a/sdk/typescript/tests-ts/skeleton.test.ts+++ b/sdk/typescript/tests-ts/skeleton.test.ts@@ -172,11 +172,13 @@ describe("TypeScript package skeleton", () => {"test","compatibility","mcp",+ "plugin-host","plugin-source",]);expect(jobs["windows"]?.needs).toEqual(["validate-title","static-checks",+ "plugin-host","windows-test","windows-verify",]);