@openai/codex-security 0.10.0 → 0.10.1

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 (130) hide show
  1. package/_bundled_plugin/.mcp.json +1 -0
  2. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  3. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  4. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  5. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  8. package/_bundled_plugin/references/access-advisory.md +1 -1
  9. package/_bundled_plugin/references/threat-model.md +1 -0
  10. package/_bundled_plugin/scripts/deep_scan_workbench.py +1 -0
  11. package/_bundled_plugin/scripts/finalize_scan_contract.py +18 -6
  12. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
  13. package/_bundled_plugin/scripts/workbench_db.py +16 -54
  14. package/_bundled_plugin/scripts/workbench_scan_history.py +23 -28
  15. package/_bundled_plugin/scripts/workbench_scan_start.py +65 -2
  16. package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
  17. package/_bundled_plugin/scripts/workbench_target.py +17 -3
  18. package/_bundled_plugin/shared/workbench-history-repairs.json +5 -1
  19. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
  20. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
  21. package/_bundled_plugin/skills/publish-findings/SKILL.md +3 -1
  22. package/dist/api.d.ts +1 -0
  23. package/dist/api.d.ts.map +1 -1
  24. package/dist/api.js +23 -4
  25. package/dist/api.js.map +1 -1
  26. package/dist/classify-severity-diagnostics.d.ts +10 -0
  27. package/dist/classify-severity-diagnostics.d.ts.map +1 -0
  28. package/dist/classify-severity-diagnostics.js +57 -0
  29. package/dist/classify-severity-diagnostics.js.map +1 -0
  30. package/dist/classify-severity-records.d.ts +4 -0
  31. package/dist/classify-severity-records.d.ts.map +1 -1
  32. package/dist/classify-severity-records.js +35 -8
  33. package/dist/classify-severity-records.js.map +1 -1
  34. package/dist/cli.d.ts +3 -0
  35. package/dist/cli.d.ts.map +1 -1
  36. package/dist/cli.js +99 -11
  37. package/dist/cli.js.map +1 -1
  38. package/dist/component-plan.d.ts.map +1 -1
  39. package/dist/component-plan.js +3 -3
  40. package/dist/component-plan.js.map +1 -1
  41. package/dist/continuum-aws.d.ts +6 -0
  42. package/dist/continuum-aws.d.ts.map +1 -0
  43. package/dist/continuum-aws.js +202 -0
  44. package/dist/continuum-aws.js.map +1 -0
  45. package/dist/continuum-collector.d.ts +44 -0
  46. package/dist/continuum-collector.d.ts.map +1 -0
  47. package/dist/continuum-collector.js +266 -0
  48. package/dist/continuum-collector.js.map +1 -0
  49. package/dist/continuum-findings.d.ts +31 -2
  50. package/dist/continuum-findings.d.ts.map +1 -1
  51. package/dist/continuum-findings.js +440 -64
  52. package/dist/continuum-findings.js.map +1 -1
  53. package/dist/contract.d.ts +1 -0
  54. package/dist/contract.d.ts.map +1 -1
  55. package/dist/contract.js +3 -0
  56. package/dist/contract.js.map +1 -1
  57. package/dist/crowdstrike-findings.d.ts +7 -0
  58. package/dist/crowdstrike-findings.d.ts.map +1 -0
  59. package/dist/crowdstrike-findings.js +210 -0
  60. package/dist/crowdstrike-findings.js.map +1 -0
  61. package/dist/external-findings-local.d.ts.map +1 -1
  62. package/dist/external-findings-local.js +26 -8
  63. package/dist/external-findings-local.js.map +1 -1
  64. package/dist/external-findings-publish.d.ts.map +1 -1
  65. package/dist/external-findings-publish.js +5 -1
  66. package/dist/external-findings-publish.js.map +1 -1
  67. package/dist/external-findings-read.d.ts +10 -2
  68. package/dist/external-findings-read.d.ts.map +1 -1
  69. package/dist/external-findings-read.js +26 -3
  70. package/dist/external-findings-read.js.map +1 -1
  71. package/dist/external-import-contract.d.ts +3 -0
  72. package/dist/external-import-contract.d.ts.map +1 -1
  73. package/dist/external-import-contract.js +6 -1
  74. package/dist/external-import-contract.js.map +1 -1
  75. package/dist/host-protocol.d.ts +6 -0
  76. package/dist/host-protocol.d.ts.map +1 -1
  77. package/dist/host-protocol.js +11 -1
  78. package/dist/host-protocol.js.map +1 -1
  79. package/dist/host-records-protocol.d.ts +2 -0
  80. package/dist/host-records-protocol.d.ts.map +1 -1
  81. package/dist/host-records-protocol.js +4 -0
  82. package/dist/host-records-protocol.js.map +1 -1
  83. package/dist/index.d.ts +2 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +1 -0
  86. package/dist/index.js.map +1 -1
  87. package/dist/multiscan.d.ts.map +1 -1
  88. package/dist/multiscan.js +4 -2
  89. package/dist/multiscan.js.map +1 -1
  90. package/dist/project-config-schema.d.ts +2 -0
  91. package/dist/project-config-schema.d.ts.map +1 -1
  92. package/dist/project-config-schema.js +1 -0
  93. package/dist/project-config-schema.js.map +1 -1
  94. package/dist/project-config.d.ts +1 -0
  95. package/dist/project-config.d.ts.map +1 -1
  96. package/dist/project-config.js +3 -0
  97. package/dist/project-config.js.map +1 -1
  98. package/dist/runtime.d.ts.map +1 -1
  99. package/dist/runtime.js +4 -0
  100. package/dist/runtime.js.map +1 -1
  101. package/dist/scan-comparison.d.ts +20 -2
  102. package/dist/scan-comparison.d.ts.map +1 -1
  103. package/dist/scan-comparison.js +20 -3
  104. package/dist/scan-comparison.js.map +1 -1
  105. package/dist/scan-settings.d.ts +1 -0
  106. package/dist/scan-settings.d.ts.map +1 -1
  107. package/dist/scan-settings.js +1 -0
  108. package/dist/scan-settings.js.map +1 -1
  109. package/dist/severity-review.d.ts.map +1 -1
  110. package/dist/severity-review.js +1 -0
  111. package/dist/severity-review.js.map +1 -1
  112. package/dist/stored-finding-projection.d.ts.map +1 -1
  113. package/dist/stored-finding-projection.js +30 -5
  114. package/dist/stored-finding-projection.js.map +1 -1
  115. package/dist/targets.d.ts +2 -0
  116. package/dist/targets.d.ts.map +1 -1
  117. package/dist/targets.js +27 -0
  118. package/dist/targets.js.map +1 -1
  119. package/dist/trusted-executable.d.ts +1 -0
  120. package/dist/trusted-executable.d.ts.map +1 -1
  121. package/dist/trusted-executable.js +11 -3
  122. package/dist/trusted-executable.js.map +1 -1
  123. package/dist/value.js +3 -1
  124. package/dist/value.js.map +1 -1
  125. package/docs/classify-severity-records.md +30 -0
  126. package/docs/cli.md +164 -18
  127. package/docs/sdk.md +23 -8
  128. package/package.json +7 -2
  129. package/schemas/project-config.schema.json +5 -0
  130. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +0 -224
@@ -1,12 +1,14 @@
1
1
  import { hash } from "node:crypto";
2
2
  import { CodexSecurityError } from "./errors.js";
3
- import { CLOUD_EVIDENCE_BYTES, DEFAULT_CLOUD_STRING_BYTES, validateEnrichedExternalEvidence, validateExternalEvidenceJson, } from "./external-import-contract.js";
3
+ import { CLOUD_EVIDENCE_BYTES, CloudEvidenceSizeError, DEFAULT_CLOUD_STRING_BYTES, repositoryUrlKey, validateEnrichedExternalEvidence, validateExternalEvidence, validateExternalEvidenceJson, } from "./external-import-contract.js";
4
4
  import { isRecord } from "./record.js";
5
- import { array, awsTimestampSeconds, concreteVersion, normalizeRecords, scannerJsonReader, record, repositoryFilePath, requiredText, strings, text, } from "./scanner-import.js";
5
+ import { array, awsTimestampSeconds, concreteVersion, normalizeRecords, optionalArray, scannerJsonReader, record, repositoryFilePath, requiredText, strings, text, } from "./scanner-import.js";
6
6
  import { declaredScannerRepositoryUrl, repositoryScopeValidator, } from "./scanner-repository-url.js";
7
7
  const format = "aws-continuum-code-findings/v1";
8
+ export const continuumIssueFormat = "aws-continuum-code-issues/v1";
8
9
  const findingArn = /^(arn:[a-z0-9-]+:continuum:[a-z0-9-]+:\d{12}:environments\/([a-z0-9]+))\/code-findings\/([a-z0-9]+)$/u;
9
- function identity(value) {
10
+ const issueArn = /^(arn:[a-z0-9-]+:continuum:[a-z0-9-]+:\d{12}:environments\/([a-z0-9]+))\/code-issues\/([a-z0-9]+)$/u;
11
+ export function findingIdentity(value) {
10
12
  const row = record(value, "Continuum finding");
11
13
  const arn = requiredText(row["findingArn"], "Continuum finding ARN");
12
14
  const match = findingArn.exec(arn);
@@ -14,12 +16,21 @@ function identity(value) {
14
16
  row["environmentId"] !== match[2] ||
15
17
  row["findingId"] !== match[3])
16
18
  throw new Error("Expected a Continuum finding ARN matching its environmentId and findingId.");
17
- return { arn, scope: match[1] };
19
+ return { arn, scope: match[1], id: match[3] };
20
+ }
21
+ export function issueIdentity(value) {
22
+ const issue = record(value, "Continuum issue");
23
+ const arn = requiredText(issue["issueArn"], "Continuum issue ARN");
24
+ const match = issueArn.exec(arn);
25
+ if (!match || issue["issueId"] !== match[3])
26
+ throw new Error("Expected a Continuum issue ARN matching its issueId.");
27
+ return { arn, scope: match[1], environmentId: match[2], id: match[3] };
18
28
  }
19
29
  function retainedRepository(provider, finding, target) {
20
30
  const { source_finding_id: id, evidence: { source_data: data }, } = finding;
21
- const native = data?.["finding"];
22
- const marked = data?.["format"] === format;
31
+ const isIssue = data?.["format"] === continuumIssueFormat || issueArn.test(id);
32
+ const native = data?.[isIssue ? "issue" : "finding"];
33
+ const marked = isIssue || data?.["format"] === format;
23
34
  const nativeArn = isRecord(native) && findingArn.test(text(native["findingArn"]) ?? "");
24
35
  if (provider !== "continuum") {
25
36
  if (marked ||
@@ -31,27 +42,55 @@ function retainedRepository(provider, finding, target) {
31
42
  }
32
43
  if (!marked && !nativeArn && !findingArn.test(id))
33
44
  return;
34
- const { arn, scope } = identity(native);
45
+ const { arn, scope } = isIssue
46
+ ? issueIdentity(native)
47
+ : findingIdentity(native);
35
48
  if (arn !== id)
36
- throw new Error("Continuum source finding ID does not match the retained finding ARN.");
49
+ throw new Error(`Continuum source finding ID does not match the retained ${isIssue ? "issue" : "finding"} ARN.`);
37
50
  return {
38
51
  url: declaredScannerRepositoryUrl(data?.["sourceRepositoryUrl"], "Continuum", target),
39
52
  scope,
40
53
  };
41
54
  }
42
55
  export const continuumReportRepositories = repositoryScopeValidator({ provider: "continuum", label: "AWS Continuum", scope: "environment" }, retainedRepository);
43
- function codeLocations(row, vulnerabilities) {
56
+ function findingVulnerabilities(row) {
57
+ return array(row["vulnerabilities"] ?? [], "Continuum vulnerabilities").map((item) => record(item, "Continuum vulnerability"));
58
+ }
59
+ function* findingCodeLocations(row, vulnerabilities) {
60
+ yield {
61
+ filePath: row["filePath"],
62
+ startLine: row["lineNumber"],
63
+ endLine: row["endLine"],
64
+ code: row["vulnerableCode"],
65
+ };
66
+ for (const vulnerability of vulnerabilities) {
67
+ for (const value of array(vulnerability["locations"] ?? [], "Continuum vulnerability locations")) {
68
+ const location = record(value, "Continuum vulnerability location");
69
+ yield {
70
+ filePath: location["filePath"],
71
+ startLine: location["startLine"],
72
+ endLine: location["endLine"],
73
+ code: vulnerability["code"],
74
+ };
75
+ }
76
+ }
77
+ }
78
+ function locationLine(value) {
79
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0
80
+ ? value
81
+ : null;
82
+ }
83
+ function codeLocations(ranges) {
44
84
  const locations = [];
45
85
  const seen = new Set();
46
86
  let endLine = null;
47
87
  let snippet = null;
48
- function add(value, start, end, fragment) {
49
- const path = repositoryFilePath(value);
88
+ for (const range of ranges) {
89
+ const path = repositoryFilePath(range.filePath);
50
90
  if (!path)
51
- return;
52
- const line = typeof start === "number" && Number.isSafeInteger(start) && start > 0
53
- ? start
54
- : null;
91
+ continue;
92
+ const line = locationLine(range.startLine);
93
+ const end = locationLine(range.endLine);
55
94
  const key = JSON.stringify([path, line]);
56
95
  if (!seen.has(key)) {
57
96
  seen.add(key);
@@ -59,19 +98,9 @@ function codeLocations(row, vulnerabilities) {
59
98
  }
60
99
  // The flat location and first nested location can describe the same range.
61
100
  if (locations[0].path === path && locations[0].line === line) {
62
- if (line !== null &&
63
- typeof end === "number" &&
64
- Number.isSafeInteger(end) &&
65
- end >= line)
101
+ if (line !== null && end !== null && end >= line)
66
102
  endLine ??= end;
67
- snippet ??= text(fragment);
68
- }
69
- }
70
- add(row["filePath"], row["lineNumber"], row["endLine"], row["vulnerableCode"]);
71
- for (const vulnerability of vulnerabilities) {
72
- for (const value of array(vulnerability["locations"] ?? [], "Continuum vulnerability locations")) {
73
- const location = record(value, "Continuum vulnerability location");
74
- add(location["filePath"], location["startLine"], location["endLine"], vulnerability["code"]);
103
+ snippet ??= text(range.code);
75
104
  }
76
105
  }
77
106
  return { locations, code: { end_line: endLine, snippet } };
@@ -86,17 +115,17 @@ function reportRows(input) {
86
115
  if (!("items" in document ||
87
116
  "findingArn" in document ||
88
117
  "finding" in document))
89
- throw new Error("Expected a Continuum ListCodeFindings, GetCodeFinding, or finding with patch artifacts.");
118
+ throw new Error("Expected a Continuum ListCodeFindings, GetCodeFinding, or finding with artifacts.");
90
119
  const summary = "items" in document;
91
120
  return {
92
121
  rows: summary ? array(document["items"], "Continuum items") : [document],
93
122
  summary,
94
123
  };
95
124
  }
96
- function isPatchCapture(value) {
125
+ function isFindingCapture(value) {
97
126
  return isRecord(value) && !("findingArn" in value) && "finding" in value;
98
127
  }
99
- function readPatch(value) {
128
+ export function readPatch(value) {
100
129
  const artifact = record(value, "Continuum patch artifact");
101
130
  const patch = requiredText(artifact["patch"], "Continuum patch content");
102
131
  const sizeBytes = Buffer.byteLength(patch);
@@ -117,29 +146,64 @@ function readPatch(value) {
117
146
  }),
118
147
  };
119
148
  }
120
- function projectPatches(patches, target, project) {
121
- if (!patches.length || target === "local")
122
- return project(patches);
149
+ function projectArtifactBodies(artifacts, target, project) {
150
+ if (!Object.keys(artifacts).length || target === "local")
151
+ return project(artifacts);
123
152
  try {
124
- return project(patches);
153
+ return project(artifacts);
125
154
  }
126
- catch {
127
- // Complete patches can exceed the Cloud evidence budget.
155
+ catch (error) {
156
+ if (!(error instanceof CloudEvidenceSizeError))
157
+ throw error;
128
158
  }
129
- // Reserve each artifact's lookup information, then include whole patches that fit.
159
+ // Reserve all descriptors. Fit whole validation bodies before optional patches.
130
160
  const marker = { contentOmitted: "cloud_evidence_limit" };
131
- const markerBytes = Buffer.byteLength(JSON.stringify(marker));
132
- const sizes = patches.map(({ patch }) => Buffer.byteLength(JSON.stringify({ patch })) - markerBytes);
133
- const projected = patches.map(({ patch, ...descriptor }, index) => sizes[index] > 0 ? { ...descriptor, ...marker } : patches[index]);
134
- const result = project(projected);
135
- let remaining = CLOUD_EVIDENCE_BYTES - validateExternalEvidenceJson(result, target);
136
- for (const [index, bytes] of sizes.entries()) {
137
- if (bytes > 0 && bytes <= remaining) {
138
- projected[index] = patches[index];
139
- remaining -= bytes;
161
+ const projected = {};
162
+ const omitted = [];
163
+ for (const key of ["evidence_artifacts", "patches"]) {
164
+ const group = artifacts[key];
165
+ if (!group)
166
+ continue;
167
+ const bodyKey = key === "patches" ? "patch" : "body";
168
+ const wireBytes = (entry) => validateExternalEvidenceJson({ source_data: { [key]: [entry] } }, target);
169
+ const markerBytes = wireBytes(marker);
170
+ const compact = [];
171
+ projected[key] = compact;
172
+ for (const [index, artifact] of group.entries()) {
173
+ const { [bodyKey]: body, ...descriptor } = artifact;
174
+ try {
175
+ const bytes = wireBytes({ [bodyKey]: body }) - markerBytes;
176
+ if (bytes <= 0) {
177
+ compact.push(artifact);
178
+ continue;
179
+ }
180
+ omitted.push({ compact, index, bytes, artifact });
181
+ }
182
+ catch (error) {
183
+ if (!(error instanceof CloudEvidenceSizeError))
184
+ throw error;
185
+ }
186
+ compact.push({ ...descriptor, ...marker });
140
187
  }
141
188
  }
142
- result.source_data["patches"] = projected;
189
+ let result;
190
+ try {
191
+ result = project(projected);
192
+ }
193
+ catch (error) {
194
+ if (!(error instanceof CloudEvidenceSizeError) ||
195
+ !artifacts.evidence_artifacts?.length)
196
+ throw error;
197
+ // Even the validation descriptors exceed the budget. Retry the original finding and patches.
198
+ return projectArtifactBodies(artifacts.patches ? { patches: artifacts.patches } : {}, target, project);
199
+ }
200
+ let remaining = CLOUD_EVIDENCE_BYTES - validateExternalEvidenceJson(result, target);
201
+ for (const { compact, index, bytes, artifact } of omitted) {
202
+ if (bytes > remaining)
203
+ continue;
204
+ compact[index] = artifact;
205
+ remaining -= bytes;
206
+ }
143
207
  return result;
144
208
  }
145
209
  function subcategoryCwe(row) {
@@ -189,25 +253,327 @@ function affectedPackages(items, target) {
189
253
  }
190
254
  return [...unique.values()];
191
255
  }
256
+ function linkedIssueFindings(value, issue, scope) {
257
+ const ids = array(issue["findingIds"], "Continuum issue findingIds").map((id) => requiredText(id, "Continuum issue finding ID"));
258
+ const missing = new Set(ids);
259
+ const findings = new Map();
260
+ const invalidLinks = "Supply exactly one detail response per Continuum issue finding ID.";
261
+ if (ids.length === 0 || missing.size !== ids.length)
262
+ throw new Error(invalidLinks);
263
+ for (const item of array(value, "Continuum issue findings")) {
264
+ const { id, scope: findingScope } = findingIdentity(item);
265
+ if (findingScope !== scope)
266
+ throw new Error("Continuum issue and linked finding must share an environment.");
267
+ if (!missing.delete(id))
268
+ throw new Error(invalidLinks);
269
+ findings.set(id, record(item, "Continuum finding"));
270
+ }
271
+ if (missing.size)
272
+ throw new Error(invalidLinks);
273
+ return ids.map((id) => findings.get(id));
274
+ }
275
+ function issueFindingEvidence(finding, includeReviewEvidence) {
276
+ const dependencyFields = (row) => ({
277
+ cveId: text(row["cveId"]),
278
+ affectedPackages: Array.isArray(row["affectedPackages"])
279
+ ? row["affectedPackages"]
280
+ : [],
281
+ });
282
+ const vulnerableCode = includeReviewEvidence && text(finding["vulnerableCode"]);
283
+ const mitigation = includeReviewEvidence && text(finding["mitigation"]);
284
+ const validation = finding["validation"];
285
+ // Retain the inputs needed to replay the stored issue. The export on disk
286
+ // retains the full finding details.
287
+ return {
288
+ findingArn: finding["findingArn"],
289
+ findingId: finding["findingId"],
290
+ environmentId: finding["environmentId"],
291
+ ocsfClass: finding["posture"] != null
292
+ ? "APPLICATION_SECURITY_POSTURE_FINDING"
293
+ : text(finding["ocsfClass"]),
294
+ ...dependencyFields(finding),
295
+ filePath: text(finding["filePath"]),
296
+ lineNumber: locationLine(finding["lineNumber"]),
297
+ endLine: locationLine(finding["endLine"]),
298
+ ...(vulnerableCode && { vulnerableCode }),
299
+ ...(mitigation && { mitigation }),
300
+ ...(includeReviewEvidence && isRecord(validation) && { validation }),
301
+ vulnerabilities: findingVulnerabilities(finding).map((vulnerability) => {
302
+ const code = includeReviewEvidence && text(vulnerability["code"]);
303
+ return {
304
+ ...dependencyFields(vulnerability),
305
+ locations: vulnerability["locations"] ?? [],
306
+ ...(code && { code }),
307
+ };
308
+ }),
309
+ };
310
+ }
311
+ function issueEvidenceBody(artifact) {
312
+ const body = artifact["body"];
313
+ if (!isRecord(body))
314
+ return;
315
+ if (artifact["artifactType"] === "VALIDATION_EVIDENCE") {
316
+ if (isRecord(body["validationEvidence"]))
317
+ return { validationEvidence: body["validationEvidence"] };
318
+ if (typeof body["raw"] === "string")
319
+ return { raw: body["raw"] };
320
+ }
321
+ const projection = body["prevalidationSignals"];
322
+ if (artifact["artifactType"] !== "EVIDENCE" || !isRecord(projection))
323
+ return;
324
+ const signals = array(projection["signals"] ?? [], "Continuum evidence signals").map((signal) => record(signal, "Continuum evidence signal"));
325
+ return { prevalidationSignals: { ...projection, signals } };
326
+ }
327
+ function issueEvidenceDescriptor(artifact) {
328
+ return {
329
+ artifactId: requiredText(artifact["artifactId"], "Continuum evidence artifact ID"),
330
+ artifactType: artifact["artifactType"],
331
+ ...(artifact["createdAt"] != null && { createdAt: artifact["createdAt"] }),
332
+ ...(artifact["mediaType"] != null && { mediaType: artifact["mediaType"] }),
333
+ ...(artifact["producer"] != null && { producer: artifact["producer"] }),
334
+ };
335
+ }
336
+ export function singleFindingValidationIssue(issue, issueId, finding) {
337
+ if (!isRecord(issue) || typeof issueId !== "string")
338
+ return null;
339
+ const arn = `${finding.scope}/code-issues/${issueId}`;
340
+ const ids = issue["findingIds"];
341
+ if (issue["issueArn"] !== arn ||
342
+ issue["issueId"] !== issueId ||
343
+ !Array.isArray(ids) ||
344
+ ids.length !== 1 ||
345
+ ids[0] !== finding.id)
346
+ return null;
347
+ return { issueArn: arn, issueId, findingIds: [finding.id] };
348
+ }
349
+ export function selectFindingValidationArtifact(artifact, findingId) {
350
+ if (artifact["artifactType"] !== "VALIDATION_EVIDENCE")
351
+ return;
352
+ const body = issueEvidenceBody(artifact);
353
+ if (!body)
354
+ return;
355
+ const results = body.validationEvidence?.["perFindingResults"];
356
+ if (results === undefined)
357
+ return { scope: "issue", artifact };
358
+ // A bundle's top-level proof can belong to a different finding.
359
+ const matches = array(results, "Continuum per-finding results")
360
+ .map((value) => record(value, "Continuum per-finding result"))
361
+ .filter((result) => result["findingId"] === findingId);
362
+ if (matches.length === 0)
363
+ return;
364
+ return {
365
+ scope: "finding",
366
+ artifact: {
367
+ ...issueEvidenceDescriptor(artifact),
368
+ body: {
369
+ validationEvidence: {
370
+ ...(matches.length === 1 &&
371
+ "exploitable" in matches[0] && {
372
+ exploitable: matches[0]["exploitable"],
373
+ }),
374
+ perFindingResults: matches,
375
+ },
376
+ },
377
+ },
378
+ };
379
+ }
380
+ function issueEvidenceArtifacts(artifacts) {
381
+ return artifacts.flatMap((artifact) => {
382
+ const body = issueEvidenceBody(artifact);
383
+ return body ? [{ ...issueEvidenceDescriptor(artifact), body }] : [];
384
+ });
385
+ }
386
+ function normalizeContinuumIssues(document, repository, target) {
387
+ const environmentId = requiredText(document["environmentId"], "Continuum environment ID");
388
+ const rows = array(document["issues"], "Continuum issues");
389
+ const scopes = new Set();
390
+ const result = normalizeRecords(rows, (value) => {
391
+ const row = record(value, "Continuum issue record");
392
+ const { artifacts, ...issue } = record(row["issue"], "Continuum issue");
393
+ const { arn, id, scope } = issueIdentity(issue);
394
+ const issueArtifacts = array(artifacts ?? row["evidenceArtifacts"] ?? [], "Continuum issue artifacts").map((artifact) => record(artifact, "Continuum issue artifact"));
395
+ const evidenceArtifacts = issueEvidenceArtifacts(issueArtifacts);
396
+ const patches = issueArtifacts
397
+ .filter((artifact) => artifact["artifactType"] === "PATCH")
398
+ .map((artifact) => {
399
+ const body = record(artifact["body"], "Continuum patch body");
400
+ return readPatch({
401
+ ...record(body["patch"], "Continuum patch"),
402
+ artifactId: artifact["artifactId"],
403
+ });
404
+ });
405
+ const verdicts = new Set();
406
+ for (const artifact of evidenceArtifacts) {
407
+ for (const signal of artifact.body.prevalidationSignals?.signals ??
408
+ []) {
409
+ const subject = signal["subjectRef"];
410
+ const exploitability = signal["exploitability"];
411
+ if (signal["dimension"] !== "EXPLOITABILITY" ||
412
+ (subject !== id && subject !== arn) ||
413
+ !isRecord(exploitability))
414
+ continue;
415
+ const verdict = text(exploitability["verdict"]);
416
+ if (verdict)
417
+ verdicts.add(verdict);
418
+ }
419
+ }
420
+ const scannerVerdict = verdicts.size > 1 ? "MIXED" : [...verdicts][0];
421
+ const linked = linkedIssueFindings(row["findings"], issue, scope);
422
+ const findings = linked.map((finding) => issueFindingEvidence(finding, true));
423
+ const ranges = findings.flatMap((finding) => Array.from(findingCodeLocations(finding, finding.vulnerabilities)));
424
+ const { locations, code } = codeLocations([
425
+ ...ranges.filter(({ startLine }) => locationLine(startLine) !== null),
426
+ ...ranges.filter(({ startLine }) => locationLine(startLine) === null),
427
+ ]);
428
+ const all = findings.flatMap((finding) => [
429
+ finding,
430
+ ...finding.vulnerabilities,
431
+ ]);
432
+ const advisories = [...new Set(strings(all.map((row) => row.cveId)))];
433
+ const packages = all.flatMap((row) => row.affectedPackages);
434
+ const dependency = advisories.length > 0 || packages.length > 0;
435
+ const posture = findings.some((finding) => finding.ocsfClass === "APPLICATION_SECURITY_POSTURE_FINDING");
436
+ const status = requiredText(issue["status"], "Continuum issue status");
437
+ const synopsis = requiredText(issue["synopsis"], "Continuum issue synopsis");
438
+ const details = posture || (!scannerVerdict && locations[0]?.line == null)
439
+ ? undefined
440
+ : {
441
+ details: {
442
+ kind: dependency ? "advisory" : "sast",
443
+ ...(dependency && { advisory: { source: "repository" } }),
444
+ repository: { url: repository },
445
+ source_status: status,
446
+ ...(scannerVerdict && { scanner_verdict: scannerVerdict }),
447
+ remediation_instructions: text(issue["summary"]),
448
+ code: { ...code, snippet: null },
449
+ },
450
+ };
451
+ const reviewDetails = details && {
452
+ details: {
453
+ ...details.details,
454
+ remediation_instructions: details.details.remediation_instructions ??
455
+ findings.find(({ mitigation }) => mitigation)?.mitigation ??
456
+ null,
457
+ code,
458
+ },
459
+ };
460
+ const dependencyEvidence = dependency
461
+ ? {
462
+ advisory_ids: target === "cloud" ? advisories.slice(0, 100) : advisories,
463
+ packages: affectedPackages(packages, target),
464
+ }
465
+ : undefined;
466
+ const source = {
467
+ format: continuumIssueFormat,
468
+ sourceRepositoryUrl: repository,
469
+ environmentId,
470
+ issue,
471
+ ...(evidenceArtifacts.length && {
472
+ evidence_artifacts: evidenceArtifacts,
473
+ }),
474
+ };
475
+ const compactSource = structuredClone({
476
+ ...source,
477
+ findings: linked.map((finding) => issueFindingEvidence(finding, false)),
478
+ });
479
+ const findingsWithVerdicts = compactSource.findings.map((finding, index) => {
480
+ const verdict = text(findings[index]?.validation?.["verdict"]);
481
+ return verdict ? { ...finding, validation: { verdict } } : finding;
482
+ });
483
+ const evidence = validateEnrichedExternalEvidence({
484
+ title: requiredText(issue["name"], "Continuum issue name"),
485
+ severity: text(issue["severity"])?.toLowerCase() ?? "unknown",
486
+ description: [synopsis, text(issue["severityReasoning"])]
487
+ .filter(Boolean)
488
+ .join("\n\n"),
489
+ // Keep every reported range in source_data, including ranges beyond
490
+ // the Cloud limit for navigable locations.
491
+ locations: target === "cloud" ? locations.slice(0, 100) : locations,
492
+ source_updated_at: statusUpdatedAt(issue["updatedAt"]) ??
493
+ statusUpdatedAt(issue["statusUpdatedAt"]),
494
+ source_data: compactSource,
495
+ ...(scannerVerdict &&
496
+ details && {
497
+ details: {
498
+ ...details.details,
499
+ remediation_instructions: null,
500
+ code: null,
501
+ },
502
+ }),
503
+ }, target, {
504
+ ...reviewDetails,
505
+ ...dependencyEvidence,
506
+ source_data: structuredClone({ ...source, findings }),
507
+ },
508
+ // Bulky linked validation evidence can exceed the Cloud record limit.
509
+ // Keep the per-finding verdicts with the structured review fields if they fit.
510
+ {
511
+ ...reviewDetails,
512
+ ...dependencyEvidence,
513
+ source_data: { ...compactSource, findings: findingsWithVerdicts },
514
+ }, dependencyEvidence
515
+ ? { ...reviewDetails, ...dependencyEvidence }
516
+ : undefined, reviewDetails, dependencyEvidence ? { ...details, ...dependencyEvidence } : undefined, details, dependencyEvidence);
517
+ if (!patches.length)
518
+ return evidence;
519
+ // Fit optional patch bodies after selecting the scanner evidence to retain.
520
+ return projectArtifactBodies({ patches }, target, (artifacts) => validateExternalEvidence({
521
+ ...evidence,
522
+ source_data: { ...evidence.source_data, ...artifacts },
523
+ }, target));
524
+ }, (value) => {
525
+ const issue = issueIdentity(record(value, "Continuum issue record")["issue"]);
526
+ if (issue.environmentId !== environmentId)
527
+ throw new Error("Continuum issue ARN does not match the export environment.");
528
+ scopes.add(issue.scope);
529
+ return issue.arn;
530
+ }, target);
531
+ if (scopes.size > 1)
532
+ throw new Error("Continuum issues must belong to the same environment.");
533
+ return result;
534
+ }
192
535
  export function normalizeContinuumFindings(input, sourceRepositoryUrl, target = "cloud") {
193
- const repository = declaredScannerRepositoryUrl(sourceRepositoryUrl, "Continuum", target);
536
+ const issueReport = isRecord(input) && input["format"] === continuumIssueFormat;
537
+ const capturedSource = issueReport && input["sourceRepositoryUrl"] !== undefined
538
+ ? declaredScannerRepositoryUrl(input["sourceRepositoryUrl"], "Continuum", target)
539
+ : undefined;
540
+ const repository = declaredScannerRepositoryUrl(sourceRepositoryUrl || capturedSource, "Continuum", target);
541
+ if (issueReport) {
542
+ if (capturedSource &&
543
+ repositoryUrlKey(capturedSource) !== repositoryUrlKey(repository))
544
+ throw new Error("The Continuum export repository does not match the declared source repository.");
545
+ const findings = normalizeContinuumIssues(input, capturedSource ?? repository, target);
546
+ return capturedSource
547
+ ? { ...findings, report: { sourceRepositoryUrl: capturedSource } }
548
+ : findings;
549
+ }
194
550
  const { rows, summary } = reportRows(input);
195
551
  const scopes = new Set();
196
552
  const output = normalizeRecords(rows, (value) => {
197
- const capture = !summary && isPatchCapture(value) ? value : undefined;
553
+ const capture = !summary && isFindingCapture(value) ? value : undefined;
198
554
  const row = record(capture ? capture["finding"] : value, "Continuum finding");
199
- const patches = capture
200
- ? array(capture["patches"], "Continuum patches").map(readPatch)
201
- : [];
202
- if (patches.length &&
203
- !(text(row["createdIssueId"]) || text(row["duplicateOfIssueId"])))
204
- throw new Error("Continuum patches require a finding linked to an issue.");
555
+ const patches = optionalArray(capture?.["patches"], "Continuum patches").map(readPatch);
556
+ const linkedIssue = text(row["createdIssueId"]) ?? text(row["duplicateOfIssueId"]);
557
+ let validationIssue;
558
+ const evidenceArtifacts = issueEvidenceArtifacts(optionalArray(capture?.["evidenceArtifacts"], "Continuum evidence artifacts").flatMap((value) => {
559
+ const selected = selectFindingValidationArtifact(record(value, "Continuum validation artifact"), row["findingId"]);
560
+ if (!selected)
561
+ return [];
562
+ if (selected.scope === "issue") {
563
+ validationIssue ??= singleFindingValidationIssue(capture?.["validationIssue"], linkedIssue, findingIdentity(row));
564
+ if (!validationIssue)
565
+ return [];
566
+ }
567
+ return [selected.artifact];
568
+ }));
569
+ if ((patches.length || evidenceArtifacts.length) && !linkedIssue)
570
+ throw new Error(`Continuum ${patches.length ? "patches" : "validation artifacts"} require a finding linked to an issue.`);
205
571
  if (row["type"] !== "CONTINUUM_CODE_VULN" &&
206
572
  row["type"] !== "CUSTOMER_CODE_VULN")
207
573
  throw new Error("Expected a Continuum code vulnerability finding type.");
208
574
  const severity = requiredText(row["severity"], "Continuum severity").toLowerCase();
209
- const vulnerabilities = array(row["vulnerabilities"] ?? [], "Continuum vulnerabilities").map((item) => record(item, "Continuum vulnerability"));
210
- const { locations, code } = codeLocations(row, vulnerabilities);
575
+ const vulnerabilities = findingVulnerabilities(row);
576
+ const { locations, code } = codeLocations(findingCodeLocations(row, vulnerabilities));
211
577
  const source = requiredText(row["source"], "Continuum source");
212
578
  const status = requiredText(row["status"], "Continuum status");
213
579
  const validation = record(row["validation"] ?? {}, "Continuum validation");
@@ -266,16 +632,26 @@ export function normalizeContinuumFindings(input, sourceRepositoryUrl, target =
266
632
  ? { details: { ...evidence.details, weakness_ids: [namedCwe] } }
267
633
  : undefined;
268
634
  // Keep previously admissible evidence if an optional projection exceeds the Cloud budget.
269
- return projectPatches(patches, target, (artifacts) => validateEnrichedExternalEvidence(artifacts.length
270
- ? {
271
- ...evidence,
272
- source_data: { ...evidence.source_data, patches: artifacts },
273
- }
274
- : evidence, target, inferred ? { ...enrichment, ...inferred } : undefined, enrichment, packages.length && updatedAt !== null
635
+ return projectArtifactBodies({
636
+ ...(evidenceArtifacts.length && {
637
+ evidence_artifacts: structuredClone(evidenceArtifacts),
638
+ }),
639
+ ...(patches.length && { patches }),
640
+ }, target, (artifacts) => validateEnrichedExternalEvidence({
641
+ ...evidence,
642
+ source_data: {
643
+ ...evidence.source_data,
644
+ ...(validationIssue &&
645
+ artifacts.evidence_artifacts?.length && {
646
+ validation_issue: validationIssue,
647
+ }),
648
+ ...artifacts,
649
+ },
650
+ }, target, inferred ? { ...enrichment, ...inferred } : undefined, enrichment, packages.length && updatedAt !== null
275
651
  ? { source_updated_at: updatedAt }
276
652
  : undefined, inferred));
277
653
  }, (value) => {
278
- const { arn, scope } = identity(!summary && isPatchCapture(value) ? value["finding"] : value);
654
+ const { arn, scope } = findingIdentity(!summary && isFindingCapture(value) ? value["finding"] : value);
279
655
  scopes.add(scope);
280
656
  return arn;
281
657
  }, target);