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(imports): skip Cloud replay projections for local Wiz findings (#2236)

Michael D'Angeloaeee7f2e9e21
diff --git a/sdk/typescript/src/external-findings-read.ts b/sdk/typescript/src/external-findings-read.ts
index deb567cb2..803a16d48 100644
--- a/sdk/typescript/src/external-findings-read.ts
+++ b/sdk/typescript/src/external-findings-read.ts
@@ -18,6 +18,7 @@ import { readBlackDuckFindings } from "./blackduck-findings.js";
import { readInspectorFindings } from "./inspector-findings.js";
import { isRecord } from "./record.js";
import {
+ readLocalWizFindings,
readVendorFindingsForPublication,
wizFindingRepository,
} from "./wiz-findings.js";
@@ -165,16 +166,16 @@ export async function readExternalFindings(
}
// A new reader must choose its parser before reaching the Wiz replay path.
options.provider satisfies "wiz";
- const publication = await readVendorFindingsForPublication(path, target);
- const sourceRepositories = publication.current.findings.flatMap((finding) =>
+ const wiz =
+ target === "local"
+ ? await readLocalWizFindings(path)
+ : await readVendorFindingsForPublication(path, target);
+ const sourceRepositories = wiz.current.findings.flatMap((finding) =>
localFindingRepositories("wiz", finding),
);
return {
- findings: publication.current,
- publication,
- sourceRepositories: [
- ...publication.sourceRepositories,
- ...sourceRepositories,
- ],
+ findings: wiz.current,
+ ...("legacy" in wiz && { publication: wiz }),
+ sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],
};
}
diff --git a/sdk/typescript/src/wiz-findings.ts b/sdk/typescript/src/wiz-findings.ts
index 06155c308..aa43169dc 100644
--- a/sdk/typescript/src/wiz-findings.ts
+++ b/sdk/typescript/src/wiz-findings.ts
@@ -484,6 +484,27 @@ export async function readVendorFindings(
return normalizeFindings(await readFindingInput(path), target);
}
+function inventorySources(input: FindingInput, current: VendorFindings) {
+ return current.findings.flatMap(({ evidence }) => {
+ const repository = evidence.details?.repository;
+ const inventory = input.repositories.get(repository?.id ?? "");
+ // Forward provenance only for selected findings that match the inventory.
+ // Use the emitted spelling so typed evidence and reader hints share it.
+ return repository &&
+ inventory?.platform === "GITHUB" &&
+ inventoryRepositoryUrlKey(repository.url, inventory.platform) ===
+ inventoryRepositoryUrlKey(inventory.url, inventory.platform)
+ ? [{ url: repository.url, platform: "github" as const }]
+ : [];
+ });
+}
+
+export async function readLocalWizFindings(path: string) {
+ const input = await readFindingInput(path);
+ const current = normalizeFindings(input, "local");
+ return { current, sourceRepositories: inventorySources(input, current) };
+}
+
/** @internal Preserve older inventory projections only for saved publication replay. */
export async function readVendorFindingsForPublication(
path: string,
@@ -540,18 +561,7 @@ export async function readVendorFindingsForPublication(
legacy,
currentIdentity,
legacyIdentity: legacy === current ? currentIdentity : identity(legacy),
- sourceRepositories: current.findings.flatMap(({ evidence }) => {
- const repository = evidence.details?.repository;
- const inventory = input.repositories.get(repository?.id ?? "");
- // Forward provenance only for selected findings that match the inventory.
- // Use the emitted spelling so typed evidence and reader hints share it.
- return repository &&
- inventory?.platform === "GITHUB" &&
- inventoryRepositoryUrlKey(repository.url, inventory.platform) ===
- inventoryRepositoryUrlKey(inventory.url, inventory.platform)
- ? [{ url: repository.url, platform: "github" as const }]
- : [];
- }),
+ sourceRepositories: inventorySources(input, current),
};
}
diff --git a/sdk/typescript/tests-ts/wiz-findings.test.ts b/sdk/typescript/tests-ts/wiz-findings.test.ts
index 01d3f4fe8..f8105bba2 100644
--- a/sdk/typescript/tests-ts/wiz-findings.test.ts
+++ b/sdk/typescript/tests-ts/wiz-findings.test.ts
@@ -30,6 +30,8 @@ import {
readVendorFindings,
readVendorFindingsForPublication,
} from "../src/wiz-findings.js";
+import { prepareLocalExternalImport } from "../src/external-findings-import.js";
+import { localFindingsFixture } from "./external-findings-local-helpers.js";
import { capture, dependencies } from "./cli-fixtures.js";
import { createCliTest } from "./support/cli-run.js";
import previewCheckpoint from "./fixtures/wiz-preview-checkpoint.json" with { type: "json" };
@@ -180,6 +182,32 @@ test.each(["local", "cloud"] as const)(
current.findings.map((finding) => finding.source_finding_id),
).toEqual(["package"]);
expect(current.excluded.map((finding) => finding.position)).toEqual([2, 3]);
+ if (target === "local") {
+ await using local = await localFindingsFixture();
+ const prepare = () =>
+ prepareLocalExternalImport(
+ file,
+ {
+ repository: local.repository,
+ sourceKey: "synthetic-project",
+ provider: "wiz",
+ },
+ { environment: local.environment },
+ );
+ const prepared = await prepare();
+ expect(prepared.preview.findings).toEqual(current.findings);
+ expect(prepared.preview.excluded).toEqual(current.excluded);
+ expect((await prepared.import()).counts).toEqual({
+ created: 1,
+ updated: 0,
+ unchanged: 0,
+ });
+ expect((await (await prepare()).import()).counts).toEqual({
+ created: 0,
+ updated: 0,
+ unchanged: 1,
+ });
+ }
await expect(
readVendorFindingsForPublication(file, target),
).rejects.toThrow('Duplicate source finding id "sast:occurrence-1"');