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 macOS metadata files in knowledge-base folders (#2270)

Lanre Shittu4816a83a1e6e
diff --git a/sdk/typescript/src/knowledge-base.ts b/sdk/typescript/src/knowledge-base.ts
index 5733a676b..38d3dda36 100644
--- a/sdk/typescript/src/knowledge-base.ts
+++ b/sdk/typescript/src/knowledge-base.ts
@@ -228,6 +228,8 @@ async function discover(
} else if (entry.isFile()) {
// Office keeps a "~$" owner file next to each open document.
if (entry.name.startsWith("~$")) continue;
+ // macOS writes "._" metadata files when copying to other filesystems.
+ 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 0116e743e..a73699f4c 100644
--- a/sdk/typescript/tests-ts/knowledge-base.test.ts
+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts
@@ -855,6 +855,24 @@ describe("scan knowledge bases", () => {
]);
});
+ test("skips macOS metadata files copied next to documents", async () => {
+ const root = await temporaryDirectory();
+ await writeFile(join(root, "guide.md"), "Rotate admin keys monthly.");
+ await writeFile(join(root, "policy.pdf"), pdf("Access policy."));
+ const appleDouble = Buffer.alloc(82);
+ appleDouble.write("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", "latin1");
+ await writeFile(join(root, "._guide.md"), appleDouble);
+ await writeFile(join(root, "._policy.pdf"), appleDouble);
+
+ const knowledgeBase = await prepareKnowledgeBase([root]);
+ temporaryDirectories.track(knowledgeBase.path);
+
+ expect((await extractedDocuments(knowledgeBase.path)).sort()).toEqual([
+ "Access policy.",
+ "Rotate admin keys monthly.",
+ ]);
+ });
+
test("cleans up documents and rediscovers directory contents on later runs", async () => {
const root = await temporaryDirectory();
const source = join(root, "scope.md");