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(docx): preserve manual line breaks (#186)
Dipesh Babu931ddca7b4d7
diff --git a/sdk/typescript/src/knowledge-base.ts b/sdk/typescript/src/knowledge-base.tsindex 01c146fa1..5e5e6d56a 100644--- a/sdk/typescript/src/knowledge-base.ts+++ b/sdk/typescript/src/knowledge-base.ts@@ -291,6 +291,7 @@ function extractDocx(path: string, bytes: Uint8Array): string {return decodeXml(xml.replace(/<\/(?:\w+:)?p\s*>/gu, "\n")+ .replace(/<(?:\w+:)?(?:br|cr)\b[^>]*>/gu, "\n").replace(/<(?:\w+:)?tab\b[^>]*\/>/gu, "\t").replace(/<[^>]+>/gu, ""),);diff --git a/sdk/typescript/tests-ts/knowledge-base.test.ts b/sdk/typescript/tests-ts/knowledge-base.test.tsindex 1ee96e781..ab049b7d8 100644--- a/sdk/typescript/tests-ts/knowledge-base.test.ts+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts@@ -30,10 +30,14 @@ async function extractedDocuments(path: string): Promise<string[]> {);}-function docx(text: string): Uint8Array {+function docx(+ text: string,+ secondLine?: string,+ breakElement = "<w:br/>",+): Uint8Array {return zipSync({"word/document.xml": strToU8(- `<?xml version="1.0"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>${text}</w:t></w:r></w:p></w:body></w:document>`,+ `<?xml version="1.0"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>${text}</w:t></w:r>${secondLine === undefined ? "" : `${breakElement}<w:r><w:t>${secondLine}</w:t></w:r>`}</w:p></w:body></w:document>`,),});}@@ -462,14 +466,27 @@ describe("scan knowledge bases", () => {join(root, "architecture.pdf"),pdf("Payment service boundary"),);- await writeFile(join(root, "threat-model.docx"), docx("SSRF & IDOR"));+ await writeFile(+ join(root, "threat-model.docx"),+ docx("SSRF & IDOR", "Review authentication"),+ );+ await writeFile(+ join(root, "paired-break.docx"),+ docx("Authorization", "Review permissions", "<w:br></w:br>"),+ );+ await writeFile(+ join(root, "carriage-return.docx"),+ docx("Authentication", "Review sessions", "<w:cr/>"),+ );const knowledgeBase = await prepareKnowledgeBase([root]);temporaryDirectories.track(knowledgeBase.path);const documents = await extractedDocuments(knowledgeBase.path);expect(documents).toContain("Payment service boundary");- expect(documents).toContain("SSRF & IDOR\n");+ expect(documents).toContain("SSRF & IDOR\nReview authentication\n");+ expect(documents).toContain("Authorization\nReview permissions\n");+ expect(documents).toContain("Authentication\nReview sessions\n");});test.each([