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(config): accept UTF-8 BOM in JSON project files (#980)

Dipesh Babu7bd7e2ba98f6
diff --git a/sdk/typescript/src/project-config.ts b/sdk/typescript/src/project-config.ts
index de96005c0..0ca1950a4 100644
--- a/sdk/typescript/src/project-config.ts
+++ b/sdk/typescript/src/project-config.ts
@@ -147,7 +147,7 @@ export async function readProjectConfig(
let value: unknown;
try {
if (extension === ".json") {
- value = JSON.parse(text);
+ value = JSON.parse(text.replace(/^\uFEFF/u, ""));
} else {
const document = parseDocument(text, { prettyErrors: false });
if (document.errors.length > 0) throw document.errors[0];
diff --git a/sdk/typescript/tests-ts/project-config.test.ts b/sdk/typescript/tests-ts/project-config.test.ts
index 42fabe322..7660a7bf1 100644
--- a/sdk/typescript/tests-ts/project-config.test.ts
+++ b/sdk/typescript/tests-ts/project-config.test.ts
@@ -249,7 +249,7 @@ describe("project configuration input contract", () => {
).toEqual(DEFAULT_DEEP_SCAN_SETTINGS);
});
- test("YAML and JSON load the same literal data without adding defaults", async () => {
+ test("YAML, JSON, and BOM-prefixed JSON load literal data without adding defaults", async () => {
const root = await temporaryDirectory();
const yaml = join(root, "scan.yaml");
const json = join(root, "scan.json");
@@ -264,6 +264,10 @@ describe("project configuration input contract", () => {
await writeFile(json, JSON.stringify(input));
expect((await readProjectConfig(yaml)).input).toEqual(input);
expect((await readProjectConfig(json)).input).toEqual(input);
+
+ const marked = { codex: { synthetic_setting: "preserve\uFEFFthis" } };
+ await writeFile(json, `\uFEFF${JSON.stringify(marked)}`);
+ expect((await readProjectConfig(json)).input).toEqual(marked);
});
test.each([