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

Validate knowledge-base documents during dry-run scans (#284)

Kyle Brown442e5936a217
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 9754159eb..3e94f2ddb 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -335,6 +335,13 @@ export class CodexSecurity {
await realpath(tmpdir()),
"temporary",
);
+ if (options.knowledgeBasePaths?.length) {
+ const knowledgeBase = await prepareKnowledgeBase(
+ options.knowledgeBasePaths,
+ options.signal,
+ );
+ await knowledgeBase.cleanup();
+ }
const configuration = await mergedCodexConfig(this.config);
const model = scanModelConfiguration(configuration);
const modelProvider = scanModelProvider(configuration);
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index bd2de2ebc..c8045b47a 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -541,9 +541,13 @@ describe("CodexSecurity orchestration", () => {
const repository = join(root, "repository");
const knowledgeBase = join(root, "threat-model.md");
const invalidDocument = join(root, "broken.pdf");
+ const unsupportedDocument = join(root, "unsupported.exe");
+ const emptyDirectory = join(root, "empty");
await mkdir(repository);
+ await mkdir(emptyDirectory);
await writeFile(knowledgeBase, "# Threat model\nPublic API is in scope.\n");
await writeFile(invalidDocument, "not a PDF");
+ await writeFile(unsupportedDocument, "not a supported document");
let runtimeStarted = false;
const client = new TestClient(
{},
@@ -559,6 +563,28 @@ describe("CodexSecurity orchestration", () => {
await expect(
client.preflight(repository, { knowledgeBasePaths: [knowledgeBase] }),
).resolves.toMatchObject({ knowledgeBasePaths: [knowledgeBase] });
+ const invalidDocuments: Array<[string, string]> = [
+ [join(root, "missing.md"), "ENOENT"],
+ [unsupportedDocument, "Unsupported knowledge base document"],
+ [invalidDocument, "Cannot extract text from knowledge base PDF"],
+ [
+ emptyDirectory,
+ "Knowledge base directory contains no supported documents",
+ ],
+ ];
+ if (process.platform !== "win32") {
+ const linkedDocument = join(root, "linked.md");
+ await symlink(knowledgeBase, linkedDocument);
+ invalidDocuments.push([
+ linkedDocument,
+ "Knowledge base paths cannot be symbolic links",
+ ]);
+ }
+ for (const [path, message] of invalidDocuments) {
+ await expect(
+ client.preflight(repository, { knowledgeBasePaths: [path] }),
+ ).rejects.toThrow(message);
+ }
await expect(
client.run(repository, {
knowledgeBasePaths: [join(root, "missing.md")],