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(artifacts): reject standalone collections inside the target (#1430)

mldangelo-oaia31898d658f0
diff --git a/plugins/codex-security/mcp-app/src/artifact-storage.ts b/plugins/codex-security/mcp-app/src/artifact-storage.ts
index 20856d906..20f6eba3e 100644
--- a/plugins/codex-security/mcp-app/src/artifact-storage.ts
+++ b/plugins/codex-security/mcp-app/src/artifact-storage.ts
@@ -67,9 +67,13 @@ export async function standaloneArtifactContext(
// the persistent collection. storageContext prepares the temporary root.
return { root: await resolveStoragePath(root), repoRoot, layout: "scan" };
}
- const existingRoot = await resolveStoragePath(scanRoot);
- if (existingRoot === repoRoot || existingRoot.startsWith(repoRoot + sep)) {
- throw new Error("Artifact storage must be outside the target repository.");
+ for (const storagePath of [scanRoot, root]) {
+ const existingRoot = await resolveStoragePath(storagePath);
+ if (existingRoot === repoRoot || existingRoot.startsWith(repoRoot + sep)) {
+ throw new Error(
+ "Artifact storage must be outside the target repository.",
+ );
+ }
}
if (create) await fs.mkdir(root, { recursive: true, mode: 0o700 });
return {
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts b/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts
index e1fc07bd7..157b68714 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_storage.ts
@@ -380,6 +380,52 @@ try {
),
);
+ const linkedScanRoot = path.join(fixture, "linked-scans");
+ await mkdir(linkedScanRoot);
+ await symlink(
+ repository,
+ path.join(linkedScanRoot, path.basename(repository)),
+ process.platform === "win32" ? "junction" : "dir",
+ );
+ const unsafeCollection = path.join(
+ repository,
+ path.basename(standalone.directory),
+ );
+ for (const scanRoot of [fixture, linkedScanRoot]) {
+ await client.close();
+ client = await connect({ CODEX_SECURITY_SCAN_ROOT: scanRoot });
+ const location = { targetPath: repository, storage: "persistent" };
+ const repositoryEntries = await readdir(repository);
+ await assert.rejects(
+ () => save(location),
+ /Artifact storage must be outside the target repository/,
+ );
+ await assert.rejects(
+ () => save({ ...location, path: "threatmodel.md", content }),
+ /Artifact storage must be outside the target repository/,
+ );
+ await assert.rejects(stat(unsafeCollection), { code: "ENOENT" });
+
+ const temporary = { ...location, storage: "temporary", path: "notes.md" };
+ const scratch = await save({ ...temporary, content });
+ temporaryDirectories.add(scratch.directory);
+ assert.ok(
+ scratch.directory.startsWith((await realpath(tmpdir())) + path.sep),
+ );
+ assert.equal((await read(temporary)).content, content);
+ assert.deepEqual(await readdir(repository), repositoryEntries);
+
+ await mkdir(unsafeCollection);
+ const retainedPath = path.join(unsafeCollection, "threatmodel.md");
+ await writeFile(retainedPath, content);
+ await assert.rejects(
+ () => read({ ...location, path: "threatmodel.md" }),
+ /Artifact storage must be outside the target repository/,
+ );
+ assert.equal(await readFile(retainedPath, "utf8"), content);
+ await rm(unsafeCollection, { recursive: true });
+ }
+
const repositoryAlias = path.join(fixture, "repository-alias");
await symlink(
repository,