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(artifacts): handle filesystem-root target containment (#1750)
Michael D'Angelobf4a1968536f
diff --git a/plugins/codex-security/mcp-app/src/artifact-storage.ts b/plugins/codex-security/mcp-app/src/artifact-storage.tsindex 82af29711..82d5ae2a1 100644--- a/plugins/codex-security/mcp-app/src/artifact-storage.ts+++ b/plugins/codex-security/mcp-app/src/artifact-storage.ts@@ -65,7 +65,12 @@ export async function standaloneArtifactContext(}for (const storagePath of [scanRoot, root]) {const existingRoot = await resolveStoragePath(storagePath);- if (existingRoot === repoRoot || existingRoot.startsWith(repoRoot + sep)) {+ const relativeRoot = relative(repoRoot, existingRoot);+ if (+ !isAbsolute(relativeRoot) &&+ relativeRoot !== ".." &&+ !relativeRoot.startsWith(".." + sep)+ ) {throw new Error("Artifact storage must be outside the target repository.",);diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_storage_regressions.ts b/plugins/codex-security/mcp-app/tests/test_artifact_storage_regressions.tsindex 697e68220..7e709f3e5 100644--- a/plugins/codex-security/mcp-app/tests/test_artifact_storage_regressions.ts+++ b/plugins/codex-security/mcp-app/tests/test_artifact_storage_regressions.ts@@ -113,6 +113,89 @@ async function connect(overrides: Record<string, string | undefined> = {}) {}try {+ await test("standalone persistent storage rejects filesystem-root and contained targets", async () => {+ const scanRoot = path.join(repository, "root-target-scans");+ const entries = await fs.readdir(repository);+ for (const [targetPath, selectedRoot] of [+ [path.parse(repository).root, scanRoot],+ [repository, repository],+ [repository, scanRoot],+ ]) {+ for (const create of [true, false]) {+ await assert.rejects(+ standaloneArtifactContext(+ targetPath,+ workbench,+ create,+ selectedRoot,+ "persistent",+ ),+ /Artifact storage must be outside the target repository/,+ );+ }+ }+ await assert.rejects(fs.stat(scanRoot), { code: "ENOENT" });+ assert.deepEqual(await fs.readdir(repository), entries);+ });++ await test("filesystem-root targets retain temporary artifact storage", async () => {+ const scanRoot = path.join(fixture, "root-temporary-scans");+ const context = await standaloneArtifactContext(+ path.parse(repository).root,+ workbench,+ true,+ scanRoot,+ "temporary",+ );+ const saved = await saveCodexSecurityArtifact(+ context,+ { storage: "temporary", path: "notes.md", content: "temporary evidence" },+ workbench,+ );+ temporaryDirectories.push(saved.directory);+ const read = await readCodexSecurityArtifact(+ context,+ { storage: "temporary", path: "notes.md", encoding: "utf8" },+ workbench,+ );+ assert.equal(read.content, "temporary evidence");+ await assert.rejects(fs.stat(scanRoot), { code: "ENOENT" });+ });++ await test("standalone persistent storage allows sibling-prefix directories", async () => {+ const scanRoot = repository + "-scans";+ const context = await standaloneArtifactContext(+ repository,+ workbench,+ true,+ scanRoot,+ "persistent",+ );+ const saved = await saveCodexSecurityArtifact(+ context,+ {+ storage: "persistent",+ path: "threatmodel.md",+ content: "retained evidence",+ },+ workbench,+ );+ assert.equal(path.dirname(path.dirname(saved.directory)), scanRoot);+ const readContext = await standaloneArtifactContext(+ repository,+ workbench,+ false,+ scanRoot,+ "persistent",+ );+ const read = await readCodexSecurityArtifact(+ readContext,+ { storage: "persistent", path: "threatmodel.md", encoding: "utf8" },+ workbench,+ );+ assert.equal(read.content, "retained evidence");+ });+await test("temporary artifact operations reject a collection owned by another user",{ skip: typeof process.geteuid !== "function" },