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: keep unusable DOCX numeric references as literal text (#123)
Michael8cf407034956
diff --git a/sdk/typescript/src/knowledge-base.ts b/sdk/typescript/src/knowledge-base.tsindex 83534f112..01c146fa1 100644--- a/sdk/typescript/src/knowledge-base.ts+++ b/sdk/typescript/src/knowledge-base.ts@@ -314,9 +314,17 @@ function decodeXml(value: string): string {(entity, name: string) => {if (!name.startsWith("#")) return entities[name.toLowerCase()] ?? entity;const hexadecimal = name[1]?.toLowerCase() === "x";- return String.fromCodePoint(- Number.parseInt(name.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10),+ const codePoint = Number.parseInt(+ name.slice(hexadecimal ? 2 : 1),+ hexadecimal ? 16 : 10,);+ if (+ codePoint > 0x10ffff ||+ (codePoint >= 0xd800 && codePoint <= 0xdfff)+ ) {+ return entity;+ }+ return String.fromCodePoint(codePoint);},);}diff --git a/sdk/typescript/tests-ts/knowledge-base.test.ts b/sdk/typescript/tests-ts/knowledge-base.test.tsindex 4435fb0bc..1ee96e781 100644--- a/sdk/typescript/tests-ts/knowledge-base.test.ts+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts@@ -472,6 +472,49 @@ describe("scan knowledge bases", () => {expect(documents).toContain("SSRF & IDOR\n");});+ test.each([+ ["�", "�"],+ ["�", "�"],+ ["�", "�"],+ ["�", "�"],+ ["�", "�"],+ ["�", "�"],+ ["퟿", "\uD7FF"],+ ["", "\uE000"],+ ["A", "A"],+ ["😀", "\u{1F600}"],+ ["", "\u{10FFFF}"],+ ["�", "\0"],+ ["", "\x01"],+ ])(+ "decodes DOCX Unicode scalar references and preserves unusable ones: %s",+ async (reference, expected) => {+ const root = await temporaryDirectory();+ await writeFile(join(root, "reference.docx"), docx(`Text ${reference}.`));+ const knowledgeBase = await prepareKnowledgeBase([root]);+ temporaryDirectories.track(knowledgeBase.path);+ const documents = await extractedDocuments(knowledgeBase.path);+ expect(documents).toEqual([`Text ${expected}.\n`]);+ },+ );++ test("keeps one unusable reference from failing the other knowledge-base documents", async () => {+ const root = await temporaryDirectory();+ await writeFile(join(root, "notes.md"), "Authentication boundary notes");+ await writeFile(+ join(root, "threat-model.docx"),+ docx("Boundary � case."),+ );++ const knowledgeBase = await prepareKnowledgeBase([root]);+ temporaryDirectories.track(knowledgeBase.path);+ const documents = await extractedDocuments(knowledgeBase.path);++ expect(documents).toHaveLength(2);+ expect(documents).toContain("Authentication boundary notes");+ expect(documents).toContain("Boundary � case.\n");+ });+test("cleans up documents and rediscovers directory contents on later runs", async () => {const root = await temporaryDirectory();const source = join(root, "scope.md");