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 LibreOffice lock files in knowledge-base folders (#2291)

Lanre Shittuebac5c04c6f5
diff --git a/sdk/typescript/src/knowledge-base.ts b/sdk/typescript/src/knowledge-base.ts
index bbbb04745..b2a27df89 100644
--- a/sdk/typescript/src/knowledge-base.ts
+++ b/sdk/typescript/src/knowledge-base.ts
@@ -230,6 +230,8 @@ async function discover(
if (entry.name.startsWith("~$")) continue;
// macOS writes "._" metadata files when copying to other filesystems.
if (entry.name.startsWith("._")) continue;
+ // LibreOffice keeps a ".~lock.<name>#" file next to each open document.
+ if (/^\.~lock\..+#$/s.test(entry.name)) 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 03611b724..9dd571abf 100644
--- a/sdk/typescript/tests-ts/knowledge-base.test.ts
+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts
@@ -847,16 +847,22 @@ describe("scan knowledge bases", () => {
expect(documents).toContain("Boundary &#x110000; case.\n");
});
- test("skips Office owner files while a document is open", async () => {
+ test("skips Office owner files and LibreOffice lock files during discovery", 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));
+ await writeFile(
+ join(root, ".~lock.policy.docx#"),
+ ",Example User,example-host,01.01.2026 09:00,file:///home/example/.config/libreoffice/4;",
+ );
+ await writeFile(join(root, ".~lock.#"), "Named document");
const knowledgeBase = await prepareKnowledgeBase([root]);
temporaryDirectories.track(knowledgeBase.path);
- expect(await extractedDocuments(knowledgeBase.path)).toEqual([
+ expect((await extractedDocuments(knowledgeBase.path)).sort()).toEqual([
"Access policy.\n",
+ "Named document",
]);
});