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(knowledge-base): skip Office owner files in knowledge-base folders (#1913)

12af27eccd6462
diff --git a/sdk/typescript/src/knowledge-base.ts b/sdk/typescript/src/knowledge-base.ts
index 4b0bebddb..2f9e93536 100644
--- a/sdk/typescript/src/knowledge-base.ts
+++ b/sdk/typescript/src/knowledge-base.ts
@@ -226,6 +226,8 @@ async function discover(
documents.push(document);
}
} else if (entry.isFile()) {
+ // Office keeps a "~$" owner file next to each open document.
+ if (entry.name.startsWith("~$")) continue;
if (!DOCUMENT_EXTENSIONS.has(extname(path).toLowerCase())) {
const bytes = await readFile(path, {
flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
diff --git a/sdk/typescript/tests-ts/knowledge-base.test.ts b/sdk/typescript/tests-ts/knowledge-base.test.ts
index f2683ef29..8cdb8f63a 100644
--- a/sdk/typescript/tests-ts/knowledge-base.test.ts
+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts
@@ -820,6 +820,19 @@ describe("scan knowledge bases", () => {
expect(documents).toContain("Boundary � case.\n");
});
+ test("skips Office owner files while a document is open", async () => {
+ const root = await temporaryDirectory();
+ await writeFile(join(root, "policy.docx"), docx("Access policy."));
+ await writeFile(join(root, "~$policy.docx"), new Uint8Array(162).fill(1));
+
+ const knowledgeBase = await prepareKnowledgeBase([root]);
+ temporaryDirectories.track(knowledgeBase.path);
+
+ expect(await extractedDocuments(knowledgeBase.path)).toEqual([
+ "Access policy.\n",
+ ]);
+ });
+
test("cleans up documents and rediscovers directory contents on later runs", async () => {
const root = await temporaryDirectory();
const source = join(root, "scope.md");