@openai/codex-security 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.md +151 -36
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
  6. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  15. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  16. package/_bundled_plugin/references/access-advisory.md +11 -0
  17. package/_bundled_plugin/references/core-scan.md +30 -77
  18. package/_bundled_plugin/references/final-report.md +45 -189
  19. package/_bundled_plugin/references/scan-contract.md +2 -0
  20. package/_bundled_plugin/references/scan-prologue.md +1 -1
  21. package/_bundled_plugin/references/scan-runtime.md +1 -5
  22. package/_bundled_plugin/references/threat-model.md +33 -41
  23. package/_bundled_plugin/schemas/coverage.schema.json +12 -1
  24. package/_bundled_plugin/schemas/scan-manifest.schema.json +1 -0
  25. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
  26. package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
  27. package/_bundled_plugin/scripts/deep_scan_workbench.py +145 -85
  28. package/_bundled_plugin/scripts/finalize_scan_contract.py +189 -57
  29. package/_bundled_plugin/scripts/report_projection.py +44 -15
  30. package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
  31. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
  32. package/_bundled_plugin/scripts/workbench/retained_coverage.py +3218 -0
  33. package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
  34. package/_bundled_plugin/scripts/workbench/saved_coverage.py +644 -1
  35. package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
  36. package/_bundled_plugin/scripts/workbench/saved_sources.py +712 -0
  37. package/_bundled_plugin/scripts/workbench_cli.py +3 -0
  38. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
  39. package/_bundled_plugin/scripts/workbench_db.py +51 -22
  40. package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
  41. package/_bundled_plugin/scripts/workbench_finding_workflows.py +53 -9
  42. package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +641 -2387
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +72 -7
  45. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
  47. package/_bundled_plugin/scripts/workbench_target.py +142 -17
  48. package/_bundled_plugin/scripts/workbench_validation.py +9 -2
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +44 -0
  51. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
  52. package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
  53. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
  54. package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
  56. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
  57. package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
  58. package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
  59. package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -30
  60. package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
  61. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
  62. package/_bundled_plugin/skills/publish-findings/SKILL.md +134 -0
  63. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +6 -0
  64. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
  65. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
  66. package/_bundled_plugin/skills/security-scan/SKILL.md +28 -16
  67. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
  68. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
  69. package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
  70. package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
  71. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
  72. package/_bundled_plugin/skills/validation/SKILL.md +42 -104
  73. package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
  74. package/_bundled_plugin/skills/verify-fix/SKILL.md +8 -4
  75. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
  76. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
  77. package/dist/api.d.ts +8 -3
  78. package/dist/api.d.ts.map +1 -1
  79. package/dist/api.js +414 -72
  80. package/dist/api.js.map +1 -1
  81. package/dist/auth.d.ts.map +1 -1
  82. package/dist/auth.js +4 -1
  83. package/dist/auth.js.map +1 -1
  84. package/dist/classify-severity-records.d.ts +5 -2
  85. package/dist/classify-severity-records.d.ts.map +1 -1
  86. package/dist/classify-severity-records.js +40 -34
  87. package/dist/classify-severity-records.js.map +1 -1
  88. package/dist/classify-severity.d.ts +5 -1
  89. package/dist/classify-severity.d.ts.map +1 -1
  90. package/dist/classify-severity.js +20 -30
  91. package/dist/classify-severity.js.map +1 -1
  92. package/dist/cli-help.d.ts.map +1 -1
  93. package/dist/cli-help.js +1 -0
  94. package/dist/cli-help.js.map +1 -1
  95. package/dist/cli.d.ts +9 -2
  96. package/dist/cli.d.ts.map +1 -1
  97. package/dist/cli.js +802 -149
  98. package/dist/cli.js.map +1 -1
  99. package/dist/cloud-endpoint.d.ts +6 -0
  100. package/dist/cloud-endpoint.d.ts.map +1 -0
  101. package/dist/cloud-endpoint.js +51 -0
  102. package/dist/cloud-endpoint.js.map +1 -0
  103. package/dist/cloud-publish.d.ts.map +1 -1
  104. package/dist/cloud-publish.js +7 -5
  105. package/dist/cloud-publish.js.map +1 -1
  106. package/dist/component-scan.d.ts +8 -2
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +2 -0
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/contract.d.ts +2 -0
  111. package/dist/contract.d.ts.map +1 -1
  112. package/dist/contract.js +67 -33
  113. package/dist/contract.js.map +1 -1
  114. package/dist/cost.d.ts +18 -0
  115. package/dist/cost.d.ts.map +1 -1
  116. package/dist/cost.js +107 -12
  117. package/dist/cost.js.map +1 -1
  118. package/dist/coverage-presentation.d.ts +6 -0
  119. package/dist/coverage-presentation.d.ts.map +1 -0
  120. package/dist/coverage-presentation.js +34 -0
  121. package/dist/coverage-presentation.js.map +1 -0
  122. package/dist/custom-validation-prompt.js +3 -3
  123. package/dist/custom-validation-prompt.js.map +1 -1
  124. package/dist/custom-validation.d.ts.map +1 -1
  125. package/dist/custom-validation.js +30 -4
  126. package/dist/custom-validation.js.map +1 -1
  127. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  128. package/dist/deduplication/checkpointed-review.js +3 -1
  129. package/dist/deduplication/checkpointed-review.js.map +1 -1
  130. package/dist/deduplication/scan.d.ts.map +1 -1
  131. package/dist/deduplication/scan.js +7 -5
  132. package/dist/deduplication/scan.js.map +1 -1
  133. package/dist/default-severity-rubric.d.ts +3 -0
  134. package/dist/default-severity-rubric.d.ts.map +1 -0
  135. package/dist/default-severity-rubric.js +67 -0
  136. package/dist/default-severity-rubric.js.map +1 -0
  137. package/dist/endor-findings.d.ts +8 -0
  138. package/dist/endor-findings.d.ts.map +1 -0
  139. package/dist/endor-findings.js +238 -0
  140. package/dist/endor-findings.js.map +1 -0
  141. package/dist/external-findings-import.d.ts +5 -0
  142. package/dist/external-findings-import.d.ts.map +1 -0
  143. package/dist/external-findings-import.js +46 -0
  144. package/dist/external-findings-import.js.map +1 -0
  145. package/dist/external-findings-local.d.ts +63 -0
  146. package/dist/external-findings-local.d.ts.map +1 -0
  147. package/dist/external-findings-local.js +344 -0
  148. package/dist/external-findings-local.js.map +1 -0
  149. package/dist/external-findings-publish.d.ts +73 -0
  150. package/dist/external-findings-publish.d.ts.map +1 -0
  151. package/dist/external-findings-publish.js +721 -0
  152. package/dist/external-findings-publish.js.map +1 -0
  153. package/dist/external-findings-read.d.ts +16 -0
  154. package/dist/external-findings-read.d.ts.map +1 -0
  155. package/dist/external-findings-read.js +97 -0
  156. package/dist/external-findings-read.js.map +1 -0
  157. package/dist/external-findings.d.ts +21 -0
  158. package/dist/external-findings.d.ts.map +1 -0
  159. package/dist/external-findings.js +2 -0
  160. package/dist/external-findings.js.map +1 -0
  161. package/dist/external-import-contract.d.ts +15 -0
  162. package/dist/external-import-contract.d.ts.map +1 -0
  163. package/dist/external-import-contract.js +262 -0
  164. package/dist/external-import-contract.js.map +1 -0
  165. package/dist/external-import-models.d.ts +362 -0
  166. package/dist/external-import-models.d.ts.map +1 -0
  167. package/dist/external-import-models.js +3 -0
  168. package/dist/external-import-models.js.map +1 -0
  169. package/dist/external-imports-feature.d.ts +6 -0
  170. package/dist/external-imports-feature.d.ts.map +1 -0
  171. package/dist/external-imports-feature.js +51 -0
  172. package/dist/external-imports-feature.js.map +1 -0
  173. package/dist/finding-workflow.d.ts +23 -6
  174. package/dist/finding-workflow.d.ts.map +1 -1
  175. package/dist/finding-workflow.js +23 -10
  176. package/dist/finding-workflow.js.map +1 -1
  177. package/dist/github-advisories.d.ts +386 -0
  178. package/dist/github-advisories.d.ts.map +1 -0
  179. package/dist/github-advisories.js +133 -0
  180. package/dist/github-advisories.js.map +1 -0
  181. package/dist/github-findings.d.ts +11 -0
  182. package/dist/github-findings.d.ts.map +1 -0
  183. package/dist/github-findings.js +258 -0
  184. package/dist/github-findings.js.map +1 -0
  185. package/dist/hosted-remediation-protocol.d.ts +2 -1
  186. package/dist/hosted-remediation-protocol.d.ts.map +1 -1
  187. package/dist/hosted-remediation-protocol.js +17 -11
  188. package/dist/hosted-remediation-protocol.js.map +1 -1
  189. package/dist/hosted-remediation.d.ts +4 -0
  190. package/dist/hosted-remediation.d.ts.map +1 -1
  191. package/dist/hosted-remediation.js +22 -3
  192. package/dist/hosted-remediation.js.map +1 -1
  193. package/dist/hosted-scan.d.ts +16 -0
  194. package/dist/hosted-scan.d.ts.map +1 -1
  195. package/dist/hosted-scan.js +9 -2
  196. package/dist/hosted-scan.js.map +1 -1
  197. package/dist/import-scan.js +1 -1
  198. package/dist/import-scan.js.map +1 -1
  199. package/dist/index.d.ts +16 -3
  200. package/dist/index.d.ts.map +1 -1
  201. package/dist/index.js +9 -1
  202. package/dist/index.js.map +1 -1
  203. package/dist/knowledge-base.d.ts +1 -0
  204. package/dist/knowledge-base.d.ts.map +1 -1
  205. package/dist/knowledge-base.js +17 -8
  206. package/dist/knowledge-base.js.map +1 -1
  207. package/dist/models.d.ts +1 -0
  208. package/dist/models.d.ts.map +1 -1
  209. package/dist/models.js.map +1 -1
  210. package/dist/owner-evidence.d.ts +2 -0
  211. package/dist/owner-evidence.d.ts.map +1 -1
  212. package/dist/owner-evidence.js +2 -1
  213. package/dist/owner-evidence.js.map +1 -1
  214. package/dist/project-config-schema.d.ts +2 -0
  215. package/dist/project-config-schema.d.ts.map +1 -1
  216. package/dist/project-config-schema.js +1 -0
  217. package/dist/project-config-schema.js.map +1 -1
  218. package/dist/project-config.d.ts +1 -0
  219. package/dist/project-config.d.ts.map +1 -1
  220. package/dist/project-config.js +2 -0
  221. package/dist/project-config.js.map +1 -1
  222. package/dist/publish.d.ts +2 -0
  223. package/dist/publish.d.ts.map +1 -1
  224. package/dist/publish.js +1 -1
  225. package/dist/publish.js.map +1 -1
  226. package/dist/remediation.d.ts +7 -25
  227. package/dist/remediation.d.ts.map +1 -1
  228. package/dist/remediation.js +18 -28
  229. package/dist/remediation.js.map +1 -1
  230. package/dist/result.d.ts +4 -0
  231. package/dist/result.d.ts.map +1 -1
  232. package/dist/result.js +10 -0
  233. package/dist/result.js.map +1 -1
  234. package/dist/runtime.d.ts +1 -0
  235. package/dist/runtime.d.ts.map +1 -1
  236. package/dist/runtime.js +10 -8
  237. package/dist/runtime.js.map +1 -1
  238. package/dist/scan-dashboard.d.ts +5 -3
  239. package/dist/scan-dashboard.d.ts.map +1 -1
  240. package/dist/scan-dashboard.js +79 -26
  241. package/dist/scan-dashboard.js.map +1 -1
  242. package/dist/scan-history-renderer.d.ts.map +1 -1
  243. package/dist/scan-history-renderer.js +8 -2
  244. package/dist/scan-history-renderer.js.map +1 -1
  245. package/dist/scan-owner-suggestions.d.ts +8 -0
  246. package/dist/scan-owner-suggestions.d.ts.map +1 -0
  247. package/dist/scan-owner-suggestions.js +33 -0
  248. package/dist/scan-owner-suggestions.js.map +1 -0
  249. package/dist/scan-settings.d.ts +1 -0
  250. package/dist/scan-settings.d.ts.map +1 -1
  251. package/dist/scan-settings.js +4 -0
  252. package/dist/scan-settings.js.map +1 -1
  253. package/dist/scan-usage-display.d.ts +8 -0
  254. package/dist/scan-usage-display.d.ts.map +1 -0
  255. package/dist/scan-usage-display.js +46 -0
  256. package/dist/scan-usage-display.js.map +1 -0
  257. package/dist/scanner-import.d.ts +20 -0
  258. package/dist/scanner-import.d.ts.map +1 -0
  259. package/dist/scanner-import.js +208 -0
  260. package/dist/scanner-import.js.map +1 -0
  261. package/dist/security-policy-diff.d.ts +2 -0
  262. package/dist/security-policy-diff.d.ts.map +1 -0
  263. package/dist/security-policy-diff.js +197 -0
  264. package/dist/security-policy-diff.js.map +1 -0
  265. package/dist/security-policy.d.ts +7 -3
  266. package/dist/security-policy.d.ts.map +1 -1
  267. package/dist/security-policy.js +11 -76
  268. package/dist/security-policy.js.map +1 -1
  269. package/dist/semgrep-findings.d.ts +10 -0
  270. package/dist/semgrep-findings.d.ts.map +1 -0
  271. package/dist/semgrep-findings.js +293 -0
  272. package/dist/semgrep-findings.js.map +1 -0
  273. package/dist/severity-review.d.ts +3 -0
  274. package/dist/severity-review.d.ts.map +1 -1
  275. package/dist/severity-review.js +19 -0
  276. package/dist/severity-review.js.map +1 -1
  277. package/dist/severity-store.js +7 -2
  278. package/dist/severity-store.js.map +1 -1
  279. package/dist/skill-authentication.d.ts +18 -0
  280. package/dist/skill-authentication.d.ts.map +1 -0
  281. package/dist/skill-authentication.js +82 -0
  282. package/dist/skill-authentication.js.map +1 -0
  283. package/dist/snyk-findings.d.ts +10 -0
  284. package/dist/snyk-findings.d.ts.map +1 -0
  285. package/dist/snyk-findings.js +350 -0
  286. package/dist/snyk-findings.js.map +1 -0
  287. package/dist/suggest-owners.d.ts +4 -1
  288. package/dist/suggest-owners.d.ts.map +1 -1
  289. package/dist/suggest-owners.js +53 -21
  290. package/dist/suggest-owners.js.map +1 -1
  291. package/dist/targets.d.ts +2 -2
  292. package/dist/targets.d.ts.map +1 -1
  293. package/dist/targets.js +16 -3
  294. package/dist/targets.js.map +1 -1
  295. package/dist/wiz-csv.d.ts +9 -0
  296. package/dist/wiz-csv.d.ts.map +1 -0
  297. package/dist/wiz-csv.js +116 -0
  298. package/dist/wiz-csv.js.map +1 -0
  299. package/dist/wiz-findings.d.ts +5 -0
  300. package/dist/wiz-findings.d.ts.map +1 -0
  301. package/dist/wiz-findings.js +464 -0
  302. package/dist/wiz-findings.js.map +1 -0
  303. package/docs/classify-severity-records.md +30 -13
  304. package/docs/cli.md +835 -47
  305. package/docs/findings-service.md +119 -118
  306. package/docs/hosted-remediation.md +43 -24
  307. package/docs/hosted-scans.md +38 -0
  308. package/package.json +11 -9
  309. package/schemas/external-findings.schema.json +1421 -0
  310. package/schemas/project-config.schema.json +4 -0
  311. package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
  312. package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
  313. package/_bundled_plugin/scripts/rank_preview.py +0 -129
@@ -0,0 +1,116 @@
1
+ import Papa from "papaparse";
2
+ import { validateExternalEvidence } from "./external-import-contract.js";
3
+ const profile = "wiz-code-vulnerability-csv";
4
+ const requiredHeaders = [
5
+ "ID",
6
+ "Name",
7
+ "DetailedName",
8
+ "AssetID",
9
+ "WizURL",
10
+ "CloudPlatform",
11
+ "CloudProviderURL",
12
+ ];
13
+ function text(value) {
14
+ return typeof value === "string" && value.trim() ? value : null;
15
+ }
16
+ /** Recognize the supported Wiz vulnerability CSV columns, retaining every cell. */
17
+ export function readWizCsv(contents) {
18
+ // JSONL can retain CSV column names in its evidence. Recognize the first
19
+ // JSON value before interpreting all of its quoted records as CSV.
20
+ try {
21
+ JSON.parse(contents.trimStart().split(/\r?\n/u, 1)[0]);
22
+ return undefined;
23
+ }
24
+ catch {
25
+ // A CSV header is not a JSON value.
26
+ }
27
+ // Read arrays so duplicate headers cannot be silently renamed, and unknown
28
+ // columns (including object-prototype names) remain ordinary source data.
29
+ const parsed = Papa.parse(contents, {
30
+ delimiter: ",",
31
+ skipEmptyLines: true,
32
+ });
33
+ const [headers, ...rows] = parsed.data;
34
+ if (!headers || !requiredHeaders.every((name) => headers.includes(name)))
35
+ return undefined;
36
+ if (parsed.errors.length)
37
+ throw new Error(`Invalid Wiz CSV: ${parsed.errors[0].message}`);
38
+ if (new Set(headers).size !== headers.length)
39
+ throw new Error("Wiz CSV contains duplicate column names.");
40
+ return rows.map((cells, index) => {
41
+ if (cells.length !== headers.length)
42
+ throw new Error(`Wiz CSV row ${index + 2} has the wrong column count.`);
43
+ return Object.fromEntries(headers.map((name, i) => [name, cells[i]]));
44
+ });
45
+ }
46
+ function repositoryUrl(row) {
47
+ if (text(row["CloudPlatform"])?.trim().toLowerCase() !== "github")
48
+ throw new Error("Wiz CSV imports require GitHub repository-branch findings. Workload and other provider CSV reports need an explicit normalized JSONL mapping.");
49
+ const value = text(row["CloudProviderURL"]);
50
+ const url = value ? new URL(value) : undefined;
51
+ const origin = value?.match(/^(https?:\/\/[^/?#]+)/iu)?.[1];
52
+ const path = url?.pathname.match(/^\/([^/]+)\/([^/]+)\/tree\/(.+)$/u);
53
+ if (!url ||
54
+ !origin ||
55
+ !["http:", "https:"].includes(url.protocol) ||
56
+ url.username ||
57
+ url.password ||
58
+ !path)
59
+ throw new Error("Wiz CSV finding requires a GitHub repository-branch URL.");
60
+ // URL.origin removes explicit default ports, which the Cloud contract keeps.
61
+ return `${origin}/${path[1]}/${path[2]}`;
62
+ }
63
+ /** Keep repository binding available after a normalized JSONL round trip. */
64
+ export function wizCsvRepositoryUrl(evidence) {
65
+ const source = evidence.source_data;
66
+ if (source?.["format"] !== profile)
67
+ return undefined;
68
+ const row = source["row"];
69
+ if (!row || typeof row !== "object" || Array.isArray(row))
70
+ throw new Error("Wiz CSV source evidence is missing its original row.");
71
+ return repositoryUrl(row);
72
+ }
73
+ export function wizCsvFinding(row, sourceFindingId, target = "cloud") {
74
+ repositoryUrl(row);
75
+ const name = text(row["Name"]);
76
+ const packageName = text(row["DetailedName"]);
77
+ if (!name || !packageName || !text(row["AssetID"]))
78
+ throw new Error("Wiz CSV finding requires Name, DetailedName, and AssetID.");
79
+ const path = text(text(row["LocationPath"])?.replace(/^\/+/, ""));
80
+ const fixedVersion = text(row["FixedVersion"]);
81
+ const severity = (text(row["Severity"]) ??
82
+ text(row["VendorSeverity"]) ??
83
+ text(row["CVSSSeverity"]))
84
+ ?.trim()
85
+ .toLowerCase();
86
+ return {
87
+ source_finding_id: sourceFindingId,
88
+ evidence: validateExternalEvidence({
89
+ title: [packageName, text(row["Version"]), name]
90
+ .filter(Boolean)
91
+ .join(" "),
92
+ description: text(row["Description"]),
93
+ severity: severity === "none" ? "unknown" : severity,
94
+ url: text(row["WizURL"]),
95
+ advisory_ids: [name],
96
+ packages: [
97
+ {
98
+ name: packageName,
99
+ ecosystem: null,
100
+ installed_version: text(row["Version"]),
101
+ manifest_path: path,
102
+ fixed_versions: fixedVersion ? [fixedVersion] : [],
103
+ },
104
+ ],
105
+ locations: path ? [{ path }] : [],
106
+ // A tree URL does not distinguish a slash-containing ref from a directory.
107
+ branch: null,
108
+ code_revision: null,
109
+ source_scan_id: null,
110
+ source_updated_at: null,
111
+ image_digests: [],
112
+ source_data: { format: profile, row },
113
+ }, target),
114
+ };
115
+ }
116
+ //# sourceMappingURL=wiz-csv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wiz-csv.js","sourceRoot":"","sources":["../src/wiz-csv.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAIzE,MAAM,OAAO,GAAG,4BAA4B,CAAC;AAC7C,MAAM,eAAe,GAAG;IACtB,IAAI;IACJ,MAAM;IACN,cAAc;IACd,SAAS;IACT,QAAQ;IACR,eAAe;IACf,kBAAkB;CACnB,CAAC;AAEF,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,UAAU,CACxB,QAAgB;IAEhB,yEAAyE;IACzE,mEAAmE;IACnE,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;QACxD,OAAO,SAAS,CAAC;IACnB,CAAC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AQ;YACpD,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,YAAY,EAAE,CAAC,IAAI,CAAC;YACpB,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,WAAW;oBACjB,SAAS,EAAE,IAAI;oBACf,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBACvC,aAAa,EAAE,IAAI;oBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;iBACnD;aACF;YACD,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;YACjC,2EAA2E;YAC3E,MAAM,EAAE,IAAI;YACZ,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,IAAI;YACpB,iBAAiB,EAAE,IAAI;YACvB,aAAa,EAAE,EAAE;YACjB,WAAW,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;SACtC,EACD,MAAM,CACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport Papa from \"papaparse\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindingEvidence } from \"./external-import-models.js\";\nimport type { VendorFinding } from \"./wiz-findings.js\";\n\nconst profile = \"wiz-code-vulnerability-csv\";\nconst requiredHeaders = [\n \"ID\",\n \"Name\",\n \"DetailedName\",\n \"AssetID\",\n \"WizURL\",\n \"CloudPlatform\",\n \"CloudProviderURL\",\n];\n\nfunction text(value: unknown): string | null {\n return typeof value === \"string\" && value.trim() ? value : null;\n}\n\n/** Recognize the supported Wiz vulnerability CSV columns, retaining every cell. */\nexport function readWizCsv(\n contents: string,\n): Record<string, string>[] | undefined {\n // JSONL can retain CSV column names in its evidence. Recognize the first\n // JSON value before interpreting all of its quoted records as CSV.\n try {\n JSON.parse(contents.trimStart().split(/\\r?\\n/u, 1)[0]!);\n return undefined;\n } catch {\n // A CSV header is not a JSON value.\n }\n // Read arrays so duplicate headers cannot be silently renamed, and unknown\n // columns (including object-prototype names) remain ordinary source data.\n const parsed = Papa.parse<string[]>(contents, {\n delimiter: \",\",\n skipEmptyLines: true,\n });\n const [headers, ...rows] = parsed.data;\n if (!headers || !requiredHeaders.every((name) => headers.includes(name)))\n return undefined;\n if (parsed.errors.length)\n throw new Error(`Invalid Wiz CSV: ${parsed.errors[0]!.message}`);\n if (new Set(headers).size !== headers.length)\n throw new Error(\"Wiz CSV contains duplicate column names.\");\n return rows.map((cells, index) => {\n if (cells.length !== headers.length)\n throw new Error(`Wiz CSV row ${index + 2} has the wrong column count.`);\n return Object.fromEntries(headers.map((name, i) => [name, cells[i]!]));\n });\n}\n\nfunction repositoryUrl(row: Record<string, unknown>): string {\n if (text(row[\"CloudPlatform\"])?.trim().toLowerCase() !== \"github\")\n throw new Error(\n \"Wiz CSV imports require GitHub repository-branch findings. Workload and other provider CSV reports need an explicit normalized JSONL mapping.\",\n );\n const value = text(row[\"CloudProviderURL\"]);\n const url = value ? new URL(value) : undefined;\n const origin = value?.match(/^(https?:\\/\\/[^/?#]+)/iu)?.[1];\n const path = url?.pathname.match(/^\\/([^/]+)\\/([^/]+)\\/tree\\/(.+)$/u);\n if (\n !url ||\n !origin ||\n ![\"http:\", \"https:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n !path\n )\n throw new Error(\"Wiz CSV finding requires a GitHub repository-branch URL.\");\n // URL.origin removes explicit default ports, which the Cloud contract keeps.\n return `${origin}/${path[1]}/${path[2]}`;\n}\n\n/** Keep repository binding available after a normalized JSONL round trip. */\nexport function wizCsvRepositoryUrl(\n evidence: ExternalFindingEvidence,\n): string | undefined {\n const source = evidence.source_data;\n if (source?.[\"format\"] !== profile) return undefined;\n const row = source[\"row\"];\n if (!row || typeof row !== \"object\" || Array.isArray(row))\n throw new Error(\"Wiz CSV source evidence is missing its original row.\");\n return repositoryUrl(row as Record<string, unknown>);\n}\n\nexport function wizCsvFinding(\n row: Record<string, unknown>,\n sourceFindingId: string,\n target: ExternalImportTarget = \"cloud\",\n): VendorFinding {\n repositoryUrl(row);\n const name = text(row[\"Name\"]);\n const packageName = text(row[\"DetailedName\"]);\n if (!name || !packageName || !text(row[\"AssetID\"]))\n throw new Error(\n \"Wiz CSV finding requires Name, DetailedName, and AssetID.\",\n );\n const path = text(text(row[\"LocationPath\"])?.replace(/^\\/+/, \"\"));\n const fixedVersion = text(row[\"FixedVersion\"]);\n const severity = (\n text(row[\"Severity\"]) ??\n text(row[\"VendorSeverity\"]) ??\n text(row[\"CVSSSeverity\"])\n )\n ?.trim()\n .toLowerCase();\n return {\n source_finding_id: sourceFindingId,\n evidence: validateExternalEvidence(\n {\n title: [packageName, text(row[\"Version\"]), name]\n .filter(Boolean)\n .join(\" \"),\n description: text(row[\"Description\"]),\n severity: severity === \"none\" ? \"unknown\" : severity,\n url: text(row[\"WizURL\"]),\n advisory_ids: [name],\n packages: [\n {\n name: packageName,\n ecosystem: null,\n installed_version: text(row[\"Version\"]),\n manifest_path: path,\n fixed_versions: fixedVersion ? [fixedVersion] : [],\n },\n ],\n locations: path ? [{ path }] : [],\n // A tree URL does not distinguish a slash-containing ref from a directory.\n branch: null,\n code_revision: null,\n source_scan_id: null,\n source_updated_at: null,\n image_digests: [],\n source_data: { format: profile, row },\n },\n target,\n ),\n };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { type ExternalImportTarget } from "./external-import-contract.js";
2
+ import type { ExternalFindings as VendorFindings } from "./external-findings.js";
3
+ export type { ExternalFinding as VendorFinding, ExternalFindings as VendorFindings, } from "./external-findings.js";
4
+ export declare function readVendorFindings(path: string, target?: ExternalImportTarget): Promise<VendorFindings>;
5
+ //# sourceMappingURL=wiz-findings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wiz-findings.d.ts","sourceRoot":"","sources":["../src/wiz-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAEV,gBAAgB,IAAI,cAAc,EAEnC,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,eAAe,IAAI,aAAa,EAChC,gBAAgB,IAAI,cAAc,GACnC,MAAM,wBAAwB,CAAC;AA0bhC,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,cAAc,CAAC,CAEzB"}
@@ -0,0 +1,464 @@
1
+ import { CodexSecurityError } from "./errors.js";
2
+ import { repositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
3
+ import { parseJsonOrJsonl, readScannerText } from "./scanner-import.js";
4
+ import { readWizCsv, wizCsvFinding } from "./wiz-csv.js";
5
+ function object(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value)
7
+ ? value
8
+ : undefined;
9
+ }
10
+ function text(value) {
11
+ return typeof value === "string" && value.trim() ? value : null;
12
+ }
13
+ function sourceFindingId(value, target) {
14
+ const id = text(value);
15
+ if (!id ||
16
+ id.includes("\0") ||
17
+ (target === "cloud" && Buffer.byteLength(id) > 512))
18
+ throw new Error(target === "cloud"
19
+ ? "Source finding id must contain 1–512 UTF-8 bytes and no NUL characters."
20
+ : "Source finding id must be nonempty and contain no NUL characters.");
21
+ return id;
22
+ }
23
+ /** Keep a Wiz vulnerability occurrence intact; advisory names are not identities. */
24
+ function wizFinding(record, target) {
25
+ if (record["detectionMethod"] === "EXTERNAL_NETWORK_SCAN")
26
+ throw new Error("Wiz external network findings are not supported by the package vulnerability mapping.");
27
+ const id = sourceFindingId(record["id"], target);
28
+ const name = text(record["name"]);
29
+ const packageName = text(record["detailedName"]);
30
+ const version = text(record["version"]);
31
+ const severity = (text(record["vendorSeverity"]) ?? text(record["severity"]))?.toLowerCase();
32
+ const asset = object(record["vulnerableAsset"]);
33
+ const artifact = object(record["artifactType"]);
34
+ if (!name || !packageName || !text(asset?.["id"])) {
35
+ throw new Error("Expected a Wiz package vulnerability finding with name, detailedName, and vulnerableAsset.id. Other finding classes need a separate mapping.");
36
+ }
37
+ const assetType = text(asset?.["type"]);
38
+ const repositoryAsset = assetType === "REPOSITORY_BRANCH" ||
39
+ asset?.["nativeType"] === "github#repositoryBranch";
40
+ // Wiz repository reports prefix root-relative paths with '/'. Workload paths
41
+ // are not source locations and must remain only in the original evidence.
42
+ const locationPath = text(record["locationPath"]);
43
+ const repositoryPath = repositoryAsset && locationPath ? locationPath.replace(/^\/+/, "") : null;
44
+ const digest = text(asset?.["imageDigest"]) ??
45
+ text(record["imageDigest"]) ??
46
+ (assetType === null ||
47
+ assetType === "CONTAINER_IMAGE" ||
48
+ assetType === "CONTAINER"
49
+ ? (text(asset?.["imageId"]) ??
50
+ text(asset?.["containerImageId"]) ??
51
+ text(asset?.["ImageExternalId"]))
52
+ : null);
53
+ // lastDetectedAt is not proof that the entire vendor record was updated.
54
+ const evidence = {
55
+ title: text(record["title"]) ??
56
+ [packageName, version, name].filter(Boolean).join(" "),
57
+ description: text(record["description"]),
58
+ severity: severity === "none" ? "unknown" : severity,
59
+ url: text(record["portalUrl"]),
60
+ advisory_ids: [text(record["vulnerabilityExternalId"]) ?? name],
61
+ packages: [
62
+ {
63
+ name: packageName,
64
+ ecosystem: text(record["packageManager"]) ??
65
+ text(artifact?.["osPackageManager"]) ??
66
+ text(artifact?.["codeLibraryLanguage"]) ??
67
+ text(record["codeLibraryLanguage"]),
68
+ installed_version: version,
69
+ manifest_path: repositoryPath,
70
+ fixed_versions: text(record["fixedVersion"])
71
+ ? [record["fixedVersion"]]
72
+ : [],
73
+ },
74
+ ],
75
+ locations: repositoryPath ? [{ path: repositoryPath }] : [],
76
+ branch: null,
77
+ code_revision: null,
78
+ source_scan_id: null,
79
+ image_digests: digest ? [digest] : [],
80
+ source_updated_at: updatedAt(record["updatedAt"], "updatedAt"),
81
+ source_data: record,
82
+ };
83
+ return {
84
+ source_finding_id: id,
85
+ evidence: validateExternalEvidence(evidence, target),
86
+ };
87
+ }
88
+ // Wiz's documented inventory platform establishes custom GitHub host semantics.
89
+ // Keep this context separate from the repository metadata published as evidence.
90
+ function inventoryRepositoryUrlKey(value, platform) {
91
+ const key = repositoryUrlKey(value);
92
+ return platform === "GITHUB" ? key.toLowerCase() : key;
93
+ }
94
+ function sourceRepository(repository, repositories) {
95
+ const id = text(repository?.["id"]);
96
+ const inventory = id ? repositories.get(id) : undefined;
97
+ const suppliedUrl = text(repository?.["url"]);
98
+ if (suppliedUrl &&
99
+ inventory &&
100
+ inventoryRepositoryUrlKey(suppliedUrl, inventory.platform) !==
101
+ inventoryRepositoryUrlKey(inventory.url, inventory.platform))
102
+ throw new Error("The finding and repository inventory have conflicting repository URLs.");
103
+ const url = suppliedUrl ?? inventory?.url;
104
+ if (!url)
105
+ throw new Error("A verified source repository URL is required. Include repository.url or the matching repository.id and repository.url from data.versionControlResources.nodes; names and Wiz IDs are not Cloud repository IDs.");
106
+ return {
107
+ id,
108
+ name: text(repository?.["name"]) ?? inventory?.name ?? null,
109
+ url,
110
+ };
111
+ }
112
+ function sourceBranch(branch, repository, legacy = false) {
113
+ const name = text(branch?.["name"]);
114
+ if (!name)
115
+ return null;
116
+ // Repository names and URL paths can both be literal branch prefixes. Keep
117
+ // the old mapping only for an already approved publication checkpoint.
118
+ if (!legacy)
119
+ return name;
120
+ const qualifiers = repository.name ? [repository.name] : [];
121
+ // Include the URL qualifier before selecting the longest repository prefix.
122
+ // Keep URL normalization and the branch suffix's original case and slashes.
123
+ const repositoryKey = repositoryUrlKey(repository.url).toLowerCase();
124
+ const url = /^(https?:\/\/[^/?#]+)\/([^?#]+)$/iu.exec(repositoryKey);
125
+ if (url) {
126
+ const prefixParts = url[2].split("/").length;
127
+ const parts = name.split("/");
128
+ const qualifier = parts.slice(0, prefixParts).join("/");
129
+ if (parts.length > prefixParts &&
130
+ repositoryUrlKey(url[1] + "/" + qualifier).toLowerCase() === repositoryKey)
131
+ qualifiers.push(qualifier);
132
+ }
133
+ for (const qualifier of qualifiers.sort((left, right) => right.length - left.length)) {
134
+ const prefix = qualifier + "/";
135
+ if (name.toLowerCase().startsWith(prefix.toLowerCase()))
136
+ return name.slice(prefix.length) || null;
137
+ }
138
+ return url || repository.name ? name : null;
139
+ }
140
+ function updatedAt(value, field) {
141
+ const timestamp = text(value);
142
+ if (!timestamp)
143
+ return null;
144
+ const seconds = Date.parse(timestamp) / 1000;
145
+ if (!Number.isFinite(seconds) || seconds < 0)
146
+ throw new Error(`Wiz ${field} is not a valid timestamp.`);
147
+ return Math.floor(seconds);
148
+ }
149
+ // Empty code and configuration strings are meaningful vendor evidence.
150
+ function content(value) {
151
+ return typeof value === "string" ? value : null;
152
+ }
153
+ /** Map only explicitly identified repository finding collections. */
154
+ function repositoryFinding(kind, record, repositories, legacy = false, target = "cloud") {
155
+ const id = sourceFindingId(record["id"], target);
156
+ const resource = object(record["resource"]);
157
+ if (kind === "secret" && resource?.["type"] !== "REPOSITORY_BRANCH")
158
+ throw new Error("Only repository-branch secret findings can be published to a repository. Workload secrets require a resource-scoped import and are not supported.");
159
+ const suppliedRepository = kind === "secret"
160
+ ? object(object(resource?.["typedProperties"])?.["repository"])
161
+ : object(record["repository"]);
162
+ const repository = sourceRepository(suppliedRepository, repositories);
163
+ const branch = kind === "secret"
164
+ ? resource
165
+ : object(record[kind === "sast" ? "repositoryBranch" : "branch"]);
166
+ const rule = object(record["rule"]);
167
+ const path = text(record[kind === "secret" ? "path" : "filePath"]);
168
+ const line = record[kind === "secret" ? "lineNumber" : "startLine"];
169
+ const details = {
170
+ kind,
171
+ repository,
172
+ source_status: text(record["status"]),
173
+ scanner_origin: kind === "sast" ? text(record["origin"]) : null,
174
+ scanner_verdict: kind === "sast" ? text(object(record["aiAnalysis"])?.["verdict"]) : null,
175
+ rule: rule
176
+ ? {
177
+ id: text(rule["id"]),
178
+ short_id: text(rule["shortId"]),
179
+ name: text(rule["name"]),
180
+ }
181
+ : null,
182
+ weakness_ids: kind === "sast" && Array.isArray(record["weaknesses"])
183
+ ? record["weaknesses"].map((weakness) => object(weakness)?.["id"])
184
+ : [],
185
+ remediation_instructions: text(record["remediationInstructions"]) ??
186
+ text(rule?.["remediationInstructions"]),
187
+ code: path && kind !== "secret"
188
+ ? {
189
+ end_line: record["endLine"] ?? null,
190
+ snippet: content(record[kind === "sast" ? "snippet" : "matchContent"]),
191
+ }
192
+ : null,
193
+ secret: kind === "secret"
194
+ ? {
195
+ type: text(record["type"]),
196
+ confidence: text(record["confidence"]),
197
+ validation_status: text(record["validationStatus"]),
198
+ is_encrypted: record["isEncrypted"] ?? null,
199
+ is_managed: record["isManaged"] ?? null,
200
+ introduced_commit: text(object(record["vcsDetails"])?.["initialCommitHash"]),
201
+ }
202
+ : null,
203
+ configuration: kind === "iac"
204
+ ? {
205
+ platform: text(record["platform"]),
206
+ cloud_platform: text(record["cloudPlatform"]),
207
+ expected: content(record["expectedContent"]),
208
+ actual: content(record["foundContent"]),
209
+ }
210
+ : null,
211
+ file_url: text(record["fileURL"]),
212
+ };
213
+ return {
214
+ // Existing package occurrence IDs remain unchanged. New families cannot
215
+ // collide with one another when the same tenant source key is used.
216
+ source_finding_id: sourceFindingId(`${kind}:${id}`, target),
217
+ evidence: validateExternalEvidence({
218
+ title: text(record["name"]) ?? text(rule?.["name"]),
219
+ severity: text(record["severity"])?.toLowerCase(),
220
+ description: text(record["description"]) ?? text(rule?.["description"]),
221
+ url: text(record["wizUrl"]) ?? text(record["portalUrl"]),
222
+ locations: path ? [{ path, line: line ?? null }] : [],
223
+ branch: sourceBranch(branch, repository, legacy),
224
+ code_revision: null,
225
+ source_scan_id: null,
226
+ source_updated_at: kind === "secret"
227
+ ? updatedAt(record["lastUpdatedAt"], "lastUpdatedAt")
228
+ : kind === "iac"
229
+ ? updatedAt(record["updatedAt"], "updatedAt")
230
+ : null,
231
+ source_data: record,
232
+ details,
233
+ }, target),
234
+ };
235
+ }
236
+ function records(payload) {
237
+ const repositories = new Map();
238
+ const legacyRepositories = new Map();
239
+ if (Array.isArray(payload))
240
+ return { records: payload.map((value) => ({ value })), repositories };
241
+ const envelope = object(payload);
242
+ if (!envelope)
243
+ throw new Error("Expected finding objects or a named Wiz finding collection.");
244
+ if (object(envelope["scannersRunStatuses"]) &&
245
+ object(envelope["codeAnalyzerDetails"]))
246
+ throw new Error("This is a Wiz Code & Build Scan event, which contains scan metadata rather than vulnerability records. In Vulnerability Findings, filter the repository and selection, then choose Save as → Report with JSON format and Detailed columns. Download that report instead of Raw Event.");
247
+ if (Array.isArray(envelope["errors"]) && envelope["errors"].length > 0)
248
+ throw new Error("Wiz returned GraphQL errors. Resolve them before publishing this response.");
249
+ if (envelope["source_finding_id"] !== undefined ||
250
+ envelope["id"] !== undefined)
251
+ return { records: [{ value: envelope }], repositories };
252
+ const data = object(envelope["data"]) ?? envelope;
253
+ const inventory = object(data["versionControlResources"]);
254
+ if (object(inventory?.["pageInfo"])?.["hasNextPage"] === true)
255
+ throw new Error("Wiz repository inventory has another page. Finish the selected inventory before publishing.");
256
+ if (Array.isArray(inventory?.["nodes"])) {
257
+ const entries = inventory["nodes"].flatMap((entry) => {
258
+ const node = object(entry);
259
+ const repository = object(node?.["repository"]);
260
+ const id = text(repository?.["id"]);
261
+ const url = text(repository?.["url"]);
262
+ return id && url
263
+ ? [
264
+ {
265
+ id,
266
+ name: text(repository?.["name"]),
267
+ url,
268
+ platform: text(node?.["platform"]),
269
+ },
270
+ ]
271
+ : [];
272
+ });
273
+ // Resolve provider hints before comparing URLs, so duplicate row order cannot
274
+ // discard a known platform or reject a case variant before its GITHUB hint.
275
+ for (const entry of entries) {
276
+ const previous = repositories.get(entry.id);
277
+ if (previous?.platform &&
278
+ entry.platform &&
279
+ previous.platform !== entry.platform)
280
+ throw new Error(`Repository inventory contains conflicting platforms for ${JSON.stringify(entry.id)}.`);
281
+ repositories.set(entry.id, {
282
+ ...entry,
283
+ // Equivalent inventory aliases must produce the same evidence when the
284
+ // export reorders its rows. Keep a stable supplied URL and nonempty name.
285
+ url: previous && previous.url < entry.url ? previous.url : entry.url,
286
+ name: previous?.name && (!entry.name || previous.name < entry.name)
287
+ ? previous.name
288
+ : entry.name,
289
+ platform: entry.platform ?? previous?.platform ?? null,
290
+ });
291
+ legacyRepositories.set(entry.id, {
292
+ ...entry,
293
+ platform: entry.platform ?? previous?.platform ?? null,
294
+ });
295
+ }
296
+ for (const entry of entries) {
297
+ const resolved = repositories.get(entry.id);
298
+ if (inventoryRepositoryUrlKey(entry.url, resolved.platform) !==
299
+ inventoryRepositoryUrlKey(resolved.url, resolved.platform))
300
+ throw new Error(`Repository inventory contains conflicting URLs for ${JSON.stringify(entry.id)}.`);
301
+ }
302
+ }
303
+ const collections = {
304
+ vulnerabilityFindings: "sca",
305
+ sastFindings: "sast",
306
+ secretInstances: "secret",
307
+ iacFindings: "iac",
308
+ configurationFindings: "cloud_configuration",
309
+ };
310
+ const selected = [];
311
+ let found = false;
312
+ for (const [root, kind] of Object.entries(collections)) {
313
+ const collection = object(data[root]);
314
+ if (!collection)
315
+ continue;
316
+ found = true;
317
+ if (!Array.isArray(collection["nodes"]))
318
+ throw new Error(`Wiz ${root}.nodes must be an array.`);
319
+ if (object(collection["pageInfo"])?.["hasNextPage"] === true)
320
+ throw new Error("Wiz response has another page. Complete the requested pages or save the explicitly selected records in their named collection before publishing.");
321
+ for (const value of collection["nodes"])
322
+ selected.push({ value, kind });
323
+ }
324
+ if (found)
325
+ return {
326
+ records: selected,
327
+ repositories,
328
+ legacyRepositories,
329
+ };
330
+ throw new Error("Unsupported Wiz export. Supply repository vulnerability CSV, vulnerability finding objects, named sastFindings/secretInstances/iacFindings collections, or normalized JSONL. Other CSV reports need an explicit normalized JSONL mapping.");
331
+ }
332
+ export async function readVendorFindings(path, target = "cloud") {
333
+ return normalizeFindings(await readFindingInput(path), target);
334
+ }
335
+ /** @internal Preserve older inventory projections only for saved publication replay. */
336
+ export async function readVendorFindingsForPublication(path, target = "cloud") {
337
+ const input = await readFindingInput(path);
338
+ const normalized = new WeakSet();
339
+ const current = normalizeFindings(input, target, normalized);
340
+ const legacy = normalizeFindings({ ...input, repositories: input.legacyRepositories ?? input.repositories }, target, normalized, true);
341
+ const identity = (parsed) => parsed.findings.map((finding) => {
342
+ if (normalized.has(finding))
343
+ return finding;
344
+ const repository = finding.evidence.details?.repository;
345
+ return {
346
+ source_finding_id: finding.source_finding_id,
347
+ evidence: {
348
+ // Raw vendor records retain every original branch/ref and source field.
349
+ // Inventory display aliases must not change an outstanding request's identity.
350
+ source_data: finding.evidence.source_data,
351
+ repository: repository
352
+ ? {
353
+ id: repository.id,
354
+ // Publication targets use Cloud's GitHub URL semantics. Input
355
+ // joins above still require provenance for custom-host folding.
356
+ url: repositoryUrlKey(repository.url).toLowerCase(),
357
+ }
358
+ : null,
359
+ },
360
+ };
361
+ });
362
+ return {
363
+ current,
364
+ legacy,
365
+ currentIdentity: identity(current),
366
+ legacyIdentity: identity(legacy),
367
+ sourceRepositories: current.findings.flatMap(({ evidence }) => {
368
+ const repository = evidence.details?.repository;
369
+ const inventory = input.repositories.get(repository?.id ?? "");
370
+ // Forward provenance only for selected findings that match the inventory.
371
+ // Use the emitted spelling so typed evidence and reader hints share it.
372
+ return repository &&
373
+ inventory?.platform === "GITHUB" &&
374
+ inventoryRepositoryUrlKey(repository.url, inventory.platform) ===
375
+ inventoryRepositoryUrlKey(inventory.url, inventory.platform)
376
+ ? [{ url: repository.url, platform: "github" }]
377
+ : [];
378
+ }),
379
+ };
380
+ }
381
+ async function readFindingInput(path) {
382
+ try {
383
+ const contents = await readScannerText(path);
384
+ let payload;
385
+ try {
386
+ payload = JSON.parse(contents);
387
+ }
388
+ catch {
389
+ const csv = readWizCsv(contents);
390
+ if (csv)
391
+ return {
392
+ records: csv.map((value) => ({ value, kind: "sca_csv" })),
393
+ repositories: new Map(),
394
+ };
395
+ payload = parseJsonOrJsonl(contents);
396
+ }
397
+ return records(payload);
398
+ }
399
+ catch (cause) {
400
+ throw new CodexSecurityError(`Could not read vendor findings as UTF-8 JSON, JSONL, or Wiz CSV: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
401
+ }
402
+ }
403
+ function normalizeFindings(input, target, normalized, legacy = false) {
404
+ const result = {
405
+ read: input.records.length,
406
+ findings: [],
407
+ excluded: [],
408
+ };
409
+ const identities = new Set();
410
+ for (const [index, item] of input.records.entries()) {
411
+ const record = object(item.value);
412
+ try {
413
+ if (!record)
414
+ throw new Error("Finding must be an object.");
415
+ let finding;
416
+ if (item.kind === "sca_csv") {
417
+ finding = wizCsvFinding(record, sourceFindingId(record["ID"], target), target);
418
+ }
419
+ else if ("source_finding_id" in record) {
420
+ if (Object.keys(record).some((key) => !["source_finding_id", "evidence"].includes(key))) {
421
+ throw new Error("Normalized input permits only source_finding_id and evidence.");
422
+ }
423
+ finding = {
424
+ source_finding_id: sourceFindingId(record["source_finding_id"], target),
425
+ evidence: validateExternalEvidence(record["evidence"], target),
426
+ };
427
+ }
428
+ else if (item.kind === "cloud_configuration") {
429
+ throw new Error("Cloud configuration findings require a resource-scoped import and cannot be published to a repository.");
430
+ }
431
+ else if (item.kind && item.kind !== "sca") {
432
+ finding = repositoryFinding(item.kind, record, input.repositories, legacy, target);
433
+ }
434
+ else {
435
+ if (!item.kind &&
436
+ (object(record["repository"]) ||
437
+ object(record["repositoryBranch"]) ||
438
+ object(record["resource"])))
439
+ throw new Error("Raw SAST, secret, and IaC records require their named sastFindings, secretInstances, or iacFindings collection. Bare arrays do not identify the finding family; use normalized JSONL for an explicit mapping.");
440
+ finding = wizFinding(record, target);
441
+ }
442
+ if (identities.has(finding.source_finding_id)) {
443
+ throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}. Select each vendor occurrence once.`);
444
+ }
445
+ identities.add(finding.source_finding_id);
446
+ result.findings.push(finding);
447
+ if (item.kind !== "sca_csv" && "source_finding_id" in record)
448
+ normalized?.add(finding);
449
+ }
450
+ catch (error) {
451
+ if (error instanceof CodexSecurityError)
452
+ throw error;
453
+ result.excluded.push({
454
+ position: index + 1,
455
+ source_finding_id: item.kind === "sca_csv"
456
+ ? text(record?.["ID"])
457
+ : (text(record?.["source_finding_id"]) ?? text(record?.["id"])),
458
+ reason: error instanceof Error ? error.message : String(error),
459
+ });
460
+ }
461
+ }
462
+ return result;
463
+ }
464
+ //# sourceMappingURL=wiz-findings.js.map