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(scan): accept a UTF-8 byte order mark in imported findings JSON (#856)

kevinb45e332f44da
diff --git a/sdk/typescript/src/findings-import.ts b/sdk/typescript/src/findings-import.ts
index aa66322f9..6ca87b12b 100644
--- a/sdk/typescript/src/findings-import.ts
+++ b/sdk/typescript/src/findings-import.ts
@@ -116,7 +116,9 @@ export async function parseImportedFindings(
let payload: unknown;
try {
- payload = JSON.parse(source);
+ // Exported findings files often start with a UTF-8 byte order mark, which
+ // the CSV parser already skips.
+ payload = JSON.parse(source.replace(/^\uFEFF/u, ""));
} catch (error) {
throw new CodexSecurityError("Findings JSON could not be parsed.", {
cause: error,
diff --git a/sdk/typescript/tests-ts/findings-import.test.ts b/sdk/typescript/tests-ts/findings-import.test.ts
index 4fd96f461..6c4ba695f 100644
--- a/sdk/typescript/tests-ts/findings-import.test.ts
+++ b/sdk/typescript/tests-ts/findings-import.test.ts
@@ -8,6 +8,14 @@ import {
import type { Finding, FindingsDocument } from "../src/models.js";
import { PLUGIN_ROOT } from "./plugin-root.js";
+const BYTE_ORDER_MARK = "\uFEFF";
+const CSV_SOURCE =
+ "occurrence_id,finding_id,title,summary,severity,confidence,status," +
+ "close_reason,note,remediation,path,start_line,end_line\r\n" +
+ "occ_000000000000000000000001,csf_000000000000000000000001," +
+ "Reported CSV import issue,Reported summary,high,high,open,,," +
+ "Validate archive entry destinations.,src/extract.ts,41,44\r\n";
+
async function sourceDocument(): Promise<FindingsDocument> {
return JSON.parse(
await readFile(
@@ -37,6 +45,24 @@ describe("findings import formats", () => {
).toEqual([]);
});
+ test("accepts a UTF-8 byte order mark in either import format", async () => {
+ const document = await sourceDocument();
+ expect(
+ await parseImportedFindings(
+ `${BYTE_ORDER_MARK}${JSON.stringify(document)}`,
+ "json",
+ PLUGIN_ROOT,
+ ),
+ ).toEqual(document.findings);
+ const csv = await parseImportedFindings(
+ `${BYTE_ORDER_MARK}${CSV_SOURCE}`,
+ "csv",
+ PLUGIN_ROOT,
+ );
+ expect(csv).toHaveLength(1);
+ expect(csv[0]!.title).toBe("Reported CSV import issue");
+ });
+
test("binds separate source occurrences and retains source metadata without following report paths", async () => {
const document = await sourceDocument();
const finding = document.findings[0]!;