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(plugin): preserve carriage-return inventory filenames (#1327)

mldangelo-oai5376d6a2137c
diff --git a/github-action/README.md b/github-action/README.md
index 20a377a0c..31ce6832e 100644
--- a/github-action/README.md
+++ b/github-action/README.md
@@ -249,6 +249,8 @@ audits the Action and CLI dependency locks. The `@openai/codex-security` depende
pin and regenerate `runtime/package-lock.json`, rebuild the bundles, and run
validation. Verify report compatibility when adopting a new release.
+<!-- prettier-ignore-start -->
+
<!-- action-reference:start -->
## Inputs
@@ -301,3 +303,5 @@ All outputs are strings. An empty cost or count means unavailable, not zero.
| `estimated-cost` | Estimated USD cost reported by the CLI. Empty means unavailable, not zero. |
<!-- action-reference:end -->
+
+<!-- prettier-ignore-end -->
diff --git a/plugins/codex-security/mcp-app/package.json b/plugins/codex-security/mcp-app/package.json
index f58b65729..061bd21db 100644
--- a/plugins/codex-security/mcp-app/package.json
+++ b/plugins/codex-security/mcp-app/package.json
@@ -1,6 +1,6 @@
{
"name": "codex-security-mcp-app",
- "version": "0.1.159",
+ "version": "0.1.160",
"type": "module",
"private": true,
"scripts": {
diff --git a/plugins/codex-security/mcp-app/src/helpers/normalize-candidates.ts b/plugins/codex-security/mcp-app/src/helpers/normalize-candidates.ts
index d7cfe29da..16b42f6e5 100644
--- a/plugins/codex-security/mcp-app/src/helpers/normalize-candidates.ts
+++ b/plugins/codex-security/mcp-app/src/helpers/normalize-candidates.ts
@@ -121,9 +121,66 @@ function readScope(
root: string,
allowMissing: boolean,
): Set<string> {
- const lines = decodeUtf8(readFile(path)).split(/\r?\n/u);
+ const contents = decodeUtf8(readFile(path));
+ const lines = contents.split("\n");
+ const listedRows = new Set(lines);
+ const isScopeFile = (value: string): boolean => {
+ try {
+ relativeFile(value, root);
+ return true;
+ } catch {
+ return false;
+ }
+ };
+ const carriageRows = new Map<string, [boolean, boolean]>();
+ if (!windows) {
+ for (const line of lines) {
+ if (line.endsWith("\r") && line !== "\r") {
+ carriageRows.set(line, [
+ isScopeFile(line),
+ isScopeFile(line.slice(0, -1)),
+ ]);
+ }
+ }
+ }
+ const crlfEvidence = lines.slice(0, -1).some((line) => {
+ if (line === "\r") return true;
+ const paths = carriageRows.get(line);
+ return paths !== undefined && paths[1] && !paths[0];
+ });
+ const literalEvidence = [...carriageRows.values()].some(
+ ([literal, stripped]) => literal && !stripped,
+ );
const scope = new Set<string>();
- for (const [index, line] of lines.entries()) {
+ for (const [index, row] of lines.entries()) {
+ let line = row;
+ const finalLiteral = index === lines.length - 1;
+ if (!finalLiteral && (windows || line === "\r")) {
+ if (line.endsWith("\r")) line = line.slice(0, -1);
+ } else if (!finalLiteral && line.endsWith("\r")) {
+ const [literal, stripped] = carriageRows.get(line)!;
+ const trimmed = line.slice(0, -1);
+ if (allowMissing && literal && !stripped && !listedRows.has(trimmed)) {
+ throw new Error(
+ `in-scope file row ${index + 1}: ambiguous carriage-return paths`,
+ );
+ }
+ if (stripped && !literal) {
+ line = trimmed;
+ } else if (stripped && literal) {
+ if (!listedRows.has(trimmed)) {
+ if (crlfEvidence && !literalEvidence) {
+ line = trimmed;
+ } else if (!literalEvidence || crlfEvidence) {
+ throw new Error(
+ `in-scope file row ${index + 1}: ambiguous carriage-return paths`,
+ );
+ }
+ }
+ } else if (!literal && crlfEvidence) {
+ line = trimmed;
+ }
+ }
if (line === "") continue;
try {
scope.add(relativeFile(line, root)[0]);
diff --git a/plugins/codex-security/mcp-app/tests/test_normalize_candidates.ts b/plugins/codex-security/mcp-app/tests/test_normalize_candidates.ts
new file mode 100644
index 000000000..cec244078
--- /dev/null
+++ b/plugins/codex-security/mcp-app/tests/test_normalize_candidates.ts
@@ -0,0 +1,154 @@
+import assert from "node:assert/strict";
+import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { test } from "node:test";
+import { importSource } from "./import-module.ts";
+import { temporaryDirectory } from "./support/temporary-directories.ts";
+
+const { normalizeCandidatesCommand } = await importSource(
+ join(import.meta.dirname, "../src/helpers/normalize-candidates.ts"),
+);
+
+const cases = [
+ {
+ name: "preserves a literal trailing carriage return",
+ files: ["file\r"],
+ inventory: "file\r\n",
+ candidate: "file\r",
+ },
+ {
+ name: "accepts CRLF inventories",
+ files: ["file", "other"],
+ inventory: "\r\nfile\r\nother\r\n",
+ candidate: "file",
+ },
+ {
+ name: "uses independent CRLF evidence when filenames collide",
+ files: ["file", "file\r", "other"],
+ inventory: "file\r\nother\r\n",
+ candidate: "file",
+ },
+ {
+ name: "preserves separately listed carriage-return filenames",
+ files: ["file", "file\r"],
+ inventory: "file\nfile\r\n",
+ candidate: "file\r",
+ },
+ {
+ name: "preserves an unterminated final literal filename",
+ files: ["file", "file\r", "other"],
+ inventory: "other\r\nfile\r",
+ candidate: "file\r",
+ },
+ {
+ name: "uses independent literal filename evidence",
+ files: ["file", "file\r", "literal\r"],
+ inventory: "file\r\nliteral\r\n",
+ candidate: "file\r",
+ },
+ {
+ name: "does not strip an unterminated missing literal filename",
+ files: ["file"],
+ inventory: "file\r",
+ candidate: "file",
+ error: /ENOENT/,
+ },
+ {
+ name: "keeps an unterminated missing literal outside a diff scope",
+ files: ["file"],
+ inventory: "file\r",
+ candidate: "file",
+ allowMissing: true,
+ error: /expected at least one in-scope file/,
+ },
+ {
+ name: "does not infer CRLF from an unterminated row",
+ files: ["file", "file\r", "other"],
+ inventory: "file\r\nother\r",
+ candidate: "file",
+ error: /ambiguous carriage-return paths/,
+ },
+ {
+ name: "rejects an ambiguous inventory without selecting another file",
+ files: ["file", "file\r"],
+ inventory: "file\r\n",
+ candidate: "file",
+ error: /ambiguous carriage-return paths/,
+ },
+ {
+ name: "keeps CRLF normalization for missing diff-scope files",
+ files: ["file"],
+ inventory: "file\r\ndeleted\r\n",
+ candidate: "file",
+ allowMissing: true,
+ },
+ {
+ name: "does not replace a missing CRLF path with its literal sibling",
+ files: ["file\r", "other"],
+ inventory: "file\r\nother\r\n",
+ candidate: "file\r",
+ allowMissing: true,
+ error: /ambiguous carriage-return paths/,
+ },
+ {
+ name: "preserves explicitly listed literal siblings in a diff scope",
+ files: ["file\r"],
+ inventory: "file\nfile\r\n",
+ candidate: "file\r",
+ allowMissing: true,
+ },
+];
+
+for (const fixture of cases) {
+ test(fixture.name, { skip: process.platform === "win32" }, async (t) => {
+ const root = await temporaryDirectory("normalize-candidates-");
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const repo = join(root, "repo");
+ await mkdir(repo);
+ for (const name of fixture.files)
+ await writeFile(join(repo, name), "source\n");
+ const inventory = join(root, "inventory.txt");
+ await writeFile(inventory, fixture.inventory);
+ const input = join(root, "input.jsonl");
+ await writeFile(
+ input,
+ JSON.stringify({
+ cwe_ids: ["CWE-20"],
+ locations: [
+ {
+ path: fixture.candidate,
+ start_line: 1,
+ end_line: 1,
+ role: "entrypoint",
+ },
+ ],
+ summary: "Synthetic candidate",
+ evidence: "Synthetic evidence",
+ }) + "\n",
+ );
+ const output = join(root, "output.jsonl");
+ const errors: string[] = [];
+ t.mock.method(console, "log", () => {});
+ t.mock.method(console, "error", (message: string) => errors.push(message));
+ const status = normalizeCandidatesCommand([
+ "--input",
+ input,
+ "--out",
+ output,
+ "--repo-root",
+ repo,
+ "--in-scope-files",
+ inventory,
+ ...(fixture.allowMissing ? ["--allow-missing-in-scope"] : []),
+ ]);
+ if (fixture.error) {
+ assert.equal(status, 2);
+ assert.match(errors.join("\n"), fixture.error);
+ await assert.rejects(readFile(output), { code: "ENOENT" });
+ } else {
+ assert.equal(status, 0, errors.join("\n"));
+ const normalized = JSON.parse(await readFile(output, "utf8"));
+ assert.equal(normalized.locations[0].path, fixture.candidate);
+ }
+ });
+}