@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
@@ -21,16 +21,18 @@ export class FindingWorkflow {
21
21
  environment;
22
22
  workbench;
23
23
  pythonPath;
24
- protectedRoot;
24
+ selection;
25
25
  options;
26
- constructor(id, environment = process.env, workbench = runWorkbench, pythonPath, protectedRoot) {
26
+ constructor(id, environment = process.env, workbench = runWorkbench, pythonPath, selection = {}) {
27
27
  this.id = id;
28
28
  this.environment = environment;
29
29
  this.workbench = workbench;
30
30
  this.pythonPath = pythonPath;
31
- this.protectedRoot = protectedRoot;
31
+ this.selection = selection;
32
32
  if (!id.trim())
33
33
  throw new CodexSecurityError("workflowId must be a nonempty string.");
34
+ if (selection.workbenchOptions !== undefined)
35
+ this.options = Promise.resolve(selection.workbenchOptions);
34
36
  }
35
37
  async protectArtifacts(scanDir) {
36
38
  const path = relative(await canonicalizeModelSafePath(scanDir), await canonicalizeModelSafePath(codexSecurityStateDirectory(this.environment)));
@@ -51,11 +53,12 @@ export class FindingWorkflow {
51
53
  async complete(stage, result) {
52
54
  return (await this.command({ action: "complete", stage, result }));
53
55
  }
54
- async fail(stage, error) {
56
+ async fail(stage, error, result) {
55
57
  await this.command({
56
58
  action: "fail",
57
59
  stage,
58
60
  error: errorMessage(error),
61
+ ...(result === undefined ? {} : { result }),
59
62
  }).catch(() => undefined);
60
63
  }
61
64
  async run(stage, operation) {
@@ -76,19 +79,29 @@ export class FindingWorkflow {
76
79
  const context = await this.call(["get-scan", "--scan-id", scanId]);
77
80
  return context["scan"];
78
81
  }
79
- async sourceSnapshot(repository, gitDisabled = false, privateStatePaths = []) {
82
+ async sourceSnapshot(repository, options = {}) {
80
83
  return (await this.request({
81
84
  action: "source",
82
85
  repository,
83
- ...(gitDisabled ? { gitDisabled } : {}),
84
- ...(privateStatePaths.length ? { privateStatePaths } : {}),
86
+ ...(options.optional ? { optional: true } : {}),
87
+ ...(options.gitDisabled ? { gitDisabled: true } : {}),
88
+ ...(options.evidence ? { evidence: true } : {}),
89
+ ...(options.privateStatePaths?.length
90
+ ? { privateStatePaths: options.privateStatePaths }
91
+ : {}),
85
92
  }))["source"];
86
93
  }
87
94
  async getReview(key) {
88
95
  return (await this.request({ action: "get-review", key }))["review"];
89
96
  }
90
- async saveReview(key, binding, result) {
91
- await this.request({ action: "save-review", key, binding, result });
97
+ async saveReview(key, binding, result, options = {}) {
98
+ await this.request({
99
+ action: "save-review",
100
+ key,
101
+ binding,
102
+ result,
103
+ ...(options.replace ? { replace: true } : {}),
104
+ });
92
105
  }
93
106
  async prepareDedupe(result, pendingWrite) {
94
107
  await this.command({
@@ -111,7 +124,7 @@ export class FindingWorkflow {
111
124
  python: await resolvePluginPython({
112
125
  environment: this.environment,
113
126
  configuredPath: this.pythonPath,
114
- protectedRoot: this.protectedRoot,
127
+ protectedRoot: this.selection.protectedRoot,
115
128
  }),
116
129
  environment: workbenchEnvironment(this.environment),
117
130
  failureMessage: "Could not save or resume the findings workflow",
@@ -1 +1 @@
1
- {"version":3,"file":"finding-workflow.js","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,GAEb,MAAM,c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EAAE;YACrC,MAAM,EAAE,MAAM,mBAAmB,CAAC;gBAChC,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,cAAc,EAAE,IAAI,CAAC,UAAU;gBAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;aAClC,CAAC;YACF,WAAW,EAAE,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC;YACnD,cAAc,EAAE,gDAAgD;SACjE,CAAC,CAAC,EAAE,CAAC;QACN,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isAbsolute, relative, sep } from \"node:path\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { findingsBaseUrl } from \"./findings-client.js\";\nimport type { FindingSearchScope } from \"./finding-retrieval.js\";\nimport {\n bundledPluginRoot,\n canonicalizeModelSafePath,\n codexSecurityStateDirectory,\n workbenchEnvironment,\n resolvePluginPython,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"./runtime.js\";\n\nexport type WorkflowStage = \"scan\" | \"publish\" | \"dedupe\";\nexport interface WorkflowBinding {\n repositoryPath?: string;\n scanRequestDigest?: string;\n scanId?: string;\n scanDir?: string;\n artifactDigest?: string;\n destination?: string;\n scope?: FindingSearchScope;\n}\nexport interface WorkflowState extends WorkflowBinding {\n id: string;\n stages: Record<\n WorkflowStage,\n {\n status: \"pending\" | \"running\" | \"failed\" | \"completed\";\n result?: unknown;\n error?: string;\n pendingWrite?: DedupePendingWrite;\n }\n >;\n}\n\nexport interface DedupePendingWrite {\n groups: string[][];\n local?: { inputDigest: string; source: JsonObject; gitDisabled?: boolean };\n}\n\nexport function workflowDigest(value: unknown): string {\n const json = JSON.stringify(value, (_key, item: unknown) =>\n item !== null && typeof item === \"object\" && !Array.isArray(item)\n ? Object.fromEntries(\n Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n )\n : item,\n );\n return createHash(\"sha256\").update(json).digest(\"hex\");\n}\n\nexport function workflowDestination(url: string): string {\n const destination = findingsBaseUrl(url);\n destination.username = \"\";\n destination.password = \"\";\n return destination.href;\n}\n\n/** State lives in the workbench database, never in sealed scan artifacts. */\nexport class FindingWorkflow {\n private options?: Promise<WorkbenchCommandOptions>;\n\n constructor(\n readonly id: string,\n private readonly environment: NodeJS.ProcessEnv = process.env,\n private readonly workbench: typeof runWorkbench = runWorkbench,\n private readonly pythonPath?: string,\n private readonly protectedRoot?: string,\n ) {\n if (!id.trim())\n throw new CodexSecurityError(\"workflowId must be a nonempty string.\");\n }\n\n async protectArtifacts(scanDir: string): Promise<void> {\n const path = relative(\n await canonicalizeModelSafePath(scanDir),\n await canonicalizeModelSafePath(\n codexSecurityStateDirectory(this.environment),\n ),\n );\n if (\n path === \"\" ||\n (!isAbsolute(path) && path !== \"..\" && !path.startsWith(`..${sep}`))\n ) {\n throw new CodexSecurityError(\n \"Workflow state must be outside the sealed scan artifacts.\",\n );\n }\n }\n\n async get(): Promise<WorkflowState | null> {\n return (await this.command({ action: \"get\" })) as WorkflowState | null;\n }\n\n async bind(binding: WorkflowBinding): Promise<WorkflowState> {\n return (await this.command({ action: \"bind\", binding }))!;\n }\n\n async begin(stage: WorkflowStage): Promise<WorkflowState> {\n return (await this.command({ action: \"begin\", stage }))!;\n }\n\n async complete(\n stage: WorkflowStage,\n result: unknown,\n ): Promise<WorkflowState> {\n return (await this.command({ action: \"complete\", stage, result }))!;\n }\n\n async fail(stage: WorkflowStage, error: unknown): Promise<void> {\n await this.command({\n action: \"fail\",\n stage,\n error: errorMessage(error),\n }).catch(() => undefined);\n }\n\n async run<T>(stage: WorkflowStage, operation: () => Promise<T>): Promise<T> {\n const state = await this.begin(stage);\n if (state.stages[stage].status === \"completed\")\n return state.stages[stage].result as T;\n try {\n const result = await operation();\n await this.complete(stage, result);\n return result;\n } catch (error) {\n await this.fail(stage, error);\n throw error;\n }\n }\n\n async registeredScan(scanId: string): Promise<JsonObject> {\n const context = await this.call([\"get-scan\", \"--scan-id\", scanId]);\n return context[\"scan\"] as JsonObject;\n }\n\n async sourceSnapshot(\n repository: string,\n gitDisabled = false,\n privateStatePaths: readonly string[] = [],\n ): Promise<JsonObject> {\n return (\n await this.request({\n action: \"source\",\n repository,\n ...(gitDisabled ? { gitDisabled } : {}),\n ...(privateStatePaths.length ? { privateStatePaths } : {}),\n })\n )[\"source\"] as JsonObject;\n }\n\n async getReview(key: string): Promise<unknown> {\n return (await this.request({ action: \"get-review\", key }))[\"review\"];\n }\n\n async saveReview(\n key: string,\n binding: object,\n result: unknown,\n ): Promise<void> {\n await this.request({ action: \"save-review\", key, binding, result });\n }\n\n async prepareDedupe(\n result: unknown,\n pendingWrite: DedupePendingWrite,\n ): Promise<void> {\n await this.command({\n action: \"prepare-dedupe\",\n stage: \"dedupe\",\n result,\n pendingWrite,\n });\n }\n\n private async command(payload: object): Promise<WorkflowState | null> {\n const result = await this.request(payload);\n return result[\"workflow\"] as unknown as WorkflowState | null;\n }\n\n private async request(payload: object): Promise<JsonObject> {\n return await this.call(\n [\"finding-workflow\"],\n JSON.stringify({ id: this.id, ...payload }),\n );\n }\n\n private async call(\n args: readonly string[],\n input?: string,\n ): Promise<JsonObject> {\n this.options ??= (async () => ({\n pluginRoot: await bundledPluginRoot(),\n python: await resolvePluginPython({\n environment: this.environment,\n configuredPath: this.pythonPath,\n protectedRoot: this.protectedRoot,\n }),\n environment: workbenchEnvironment(this.environment),\n failureMessage: \"Could not save or resume the findings workflow\",\n }))();\n return await this.workbench(await this.options, args, input);\n }\n}\n"]}
1
+ {"version":3,"file":"finding-workflow.js","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,W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,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isAbsolute, relative, sep } from \"node:path\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { findingsBaseUrl } from \"./findings-client.js\";\nimport type { FindingSearchScope } from \"./finding-retrieval.js\";\nimport {\n bundledPluginRoot,\n canonicalizeModelSafePath,\n codexSecurityStateDirectory,\n workbenchEnvironment,\n resolvePluginPython,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"./runtime.js\";\n\nexport type WorkflowStage = \"scan\" | \"publish\" | \"dedupe\";\nexport interface WorkflowBinding {\n repositoryPath?: string;\n scanRequestDigest?: string;\n scanId?: string;\n scanDir?: string;\n artifactDigest?: string;\n destination?: string;\n scope?: FindingSearchScope;\n}\nexport interface WorkflowState extends WorkflowBinding {\n id: string;\n stages: Record<\n WorkflowStage,\n {\n status: \"pending\" | \"running\" | \"failed\" | \"completed\";\n result?: unknown;\n error?: string;\n pendingWrite?: DedupePendingWrite;\n }\n >;\n}\n\nexport interface DedupePendingWrite {\n groups: string[][];\n local?: { inputDigest: string; source: JsonObject; gitDisabled?: boolean };\n}\n\ninterface SourceSnapshotOptions {\n optional?: boolean;\n gitDisabled?: boolean;\n privateStatePaths?: readonly string[];\n evidence?: boolean;\n}\n\nexport function workflowDigest(value: unknown): string {\n const json = JSON.stringify(value, (_key, item: unknown) =>\n item !== null && typeof item === \"object\" && !Array.isArray(item)\n ? Object.fromEntries(\n Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n )\n : item,\n );\n return createHash(\"sha256\").update(json).digest(\"hex\");\n}\n\nexport function workflowDestination(url: string): string {\n const destination = findingsBaseUrl(url);\n destination.username = \"\";\n destination.password = \"\";\n return destination.href;\n}\n\n/** State lives in the workbench database, never in sealed scan artifacts. */\nexport class FindingWorkflow {\n private options?: Promise<WorkbenchCommandOptions>;\n\n constructor(\n readonly id: string,\n private readonly environment: NodeJS.ProcessEnv = process.env,\n private readonly workbench: typeof runWorkbench = runWorkbench,\n private readonly pythonPath?: string,\n private readonly selection: {\n protectedRoot?: string;\n workbenchOptions?: WorkbenchCommandOptions;\n } = {},\n ) {\n if (!id.trim())\n throw new CodexSecurityError(\"workflowId must be a nonempty string.\");\n if (selection.workbenchOptions !== undefined)\n this.options = Promise.resolve(selection.workbenchOptions);\n }\n\n async protectArtifacts(scanDir: string): Promise<void> {\n const path = relative(\n await canonicalizeModelSafePath(scanDir),\n await canonicalizeModelSafePath(\n codexSecurityStateDirectory(this.environment),\n ),\n );\n if (\n path === \"\" ||\n (!isAbsolute(path) && path !== \"..\" && !path.startsWith(`..${sep}`))\n ) {\n throw new CodexSecurityError(\n \"Workflow state must be outside the sealed scan artifacts.\",\n );\n }\n }\n\n async get(): Promise<WorkflowState | null> {\n return (await this.command({ action: \"get\" })) as WorkflowState | null;\n }\n\n async bind(binding: WorkflowBinding): Promise<WorkflowState> {\n return (await this.command({ action: \"bind\", binding }))!;\n }\n\n async begin(stage: WorkflowStage): Promise<WorkflowState> {\n return (await this.command({ action: \"begin\", stage }))!;\n }\n\n async complete(\n stage: WorkflowStage,\n result: unknown,\n ): Promise<WorkflowState> {\n return (await this.command({ action: \"complete\", stage, result }))!;\n }\n\n async fail(\n stage: WorkflowStage,\n error: unknown,\n result?: unknown,\n ): Promise<void> {\n await this.command({\n action: \"fail\",\n stage,\n error: errorMessage(error),\n ...(result === undefined ? {} : { result }),\n }).catch(() => undefined);\n }\n\n async run<T>(stage: WorkflowStage, operation: () => Promise<T>): Promise<T> {\n const state = await this.begin(stage);\n if (state.stages[stage].status === \"completed\")\n return state.stages[stage].result as T;\n try {\n const result = await operation();\n await this.complete(stage, result);\n return result;\n } catch (error) {\n await this.fail(stage, error);\n throw error;\n }\n }\n\n async registeredScan(scanId: string): Promise<JsonObject> {\n const context = await this.call([\"get-scan\", \"--scan-id\", scanId]);\n return context[\"scan\"] as JsonObject;\n }\n\n async sourceSnapshot(\n repository: string,\n options?: SourceSnapshotOptions & { optional?: false },\n ): Promise<JsonObject>;\n async sourceSnapshot(\n repository: string,\n options: SourceSnapshotOptions & { optional: true },\n ): Promise<JsonObject | null>;\n async sourceSnapshot(\n repository: string,\n options: SourceSnapshotOptions = {},\n ): Promise<JsonObject | null> {\n return (\n await this.request({\n action: \"source\",\n repository,\n ...(options.optional ? { optional: true } : {}),\n ...(options.gitDisabled ? { gitDisabled: true } : {}),\n ...(options.evidence ? { evidence: true } : {}),\n ...(options.privateStatePaths?.length\n ? { privateStatePaths: options.privateStatePaths }\n : {}),\n })\n )[\"source\"] as JsonObject | null;\n }\n\n async getReview(key: string): Promise<unknown> {\n return (await this.request({ action: \"get-review\", key }))[\"review\"];\n }\n\n async saveReview(\n key: string,\n binding: object,\n result: unknown,\n options: { replace?: boolean } = {},\n ): Promise<void> {\n await this.request({\n action: \"save-review\",\n key,\n binding,\n result,\n ...(options.replace ? { replace: true } : {}),\n });\n }\n\n async prepareDedupe(\n result: unknown,\n pendingWrite: DedupePendingWrite,\n ): Promise<void> {\n await this.command({\n action: \"prepare-dedupe\",\n stage: \"dedupe\",\n result,\n pendingWrite,\n });\n }\n\n private async command(payload: object): Promise<WorkflowState | null> {\n const result = await this.request(payload);\n return result[\"workflow\"] as unknown as WorkflowState | null;\n }\n\n private async request(payload: object): Promise<JsonObject> {\n return await this.call(\n [\"finding-workflow\"],\n JSON.stringify({ id: this.id, ...payload }),\n );\n }\n\n private async call(\n args: readonly string[],\n input?: string,\n ): Promise<JsonObject> {\n this.options ??= (async () => ({\n pluginRoot: await bundledPluginRoot(),\n python: await resolvePluginPython({\n environment: this.environment,\n configuredPath: this.pythonPath,\n protectedRoot: this.selection.protectedRoot,\n }),\n environment: workbenchEnvironment(this.environment),\n failureMessage: \"Could not save or resume the findings workflow\",\n }))();\n return await this.workbench(await this.options, args, input);\n }\n}\n"]}
@@ -0,0 +1,386 @@
1
+ import type { Octokit } from "@octokit/core";
2
+ export declare const GITHUB_ADVISORY_STATES: readonly ["published", "draft", "triage", "closed"];
3
+ export interface GitHubAdvisoryImportOptions {
4
+ /** Source repository, or the selected target for explicit global advisory IDs. */
5
+ repository: string;
6
+ /** Exact GHSA IDs. Required for the global advisory API. */
7
+ advisoryIds?: readonly string[];
8
+ /** Repository advisories by default; global never enumerates the database. */
9
+ source?: "repository" | "global";
10
+ /** Repository list state (default: published). Exact IDs ignore state. */
11
+ state?: (typeof GITHUB_ADVISORY_STATES)[number];
12
+ /** Defaults to GH_HOST or github.com. */
13
+ githubHost?: string;
14
+ /** Omit to use the authenticated GitHub CLI. */
15
+ githubToken?: string;
16
+ signal?: AbortSignal;
17
+ }
18
+ type RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;
19
+ type GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;
20
+ export interface ImportedGitHubAdvisory {
21
+ source: "github-security-advisory";
22
+ selection: "repository" | "global";
23
+ repository: string;
24
+ githubHost: string;
25
+ ghsaId: string;
26
+ url: string;
27
+ /** Upstream disclosure, not proof that the selected repository is affected. */
28
+ advisory: RepositoryAdvisory | GlobalAdvisory;
29
+ }
30
+ interface GitHubAdvisoryImportDependencies {
31
+ environment?: NodeJS.ProcessEnv;
32
+ currentDirectory?: string;
33
+ createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;
34
+ }
35
+ /** Read repository disclosures or explicitly selected public GHSA records. */
36
+ export declare function importGitHubAdvisories(options: GitHubAdvisoryImportOptions, dependencies?: GitHubAdvisoryImportDependencies): Promise<ImportedGitHubAdvisory[]>;
37
+ declare function fetchRepositoryAdvisory(github: Octokit, owner: string, repo: string, id: string, signal?: AbortSignal): Promise<{
38
+ ghsa_id: string;
39
+ cve_id: string | null;
40
+ url: string;
41
+ html_url: string;
42
+ summary: string;
43
+ description: string | null;
44
+ severity: "critical" | "high" | "medium" | "low" | null;
45
+ author: {
46
+ name?: string | null;
47
+ email?: string | null;
48
+ login: string;
49
+ id: number | bigint;
50
+ node_id: string;
51
+ avatar_url: string;
52
+ gravatar_id: string | null;
53
+ url: string;
54
+ html_url: string;
55
+ followers_url: string;
56
+ following_url: string;
57
+ gists_url: string;
58
+ starred_url: string;
59
+ subscriptions_url: string;
60
+ organizations_url: string;
61
+ repos_url: string;
62
+ events_url: string;
63
+ received_events_url: string;
64
+ type: string;
65
+ site_admin: boolean;
66
+ starred_at?: string;
67
+ user_view_type?: string;
68
+ } | null;
69
+ publisher: {
70
+ name?: string | null;
71
+ email?: string | null;
72
+ login: string;
73
+ id: number | bigint;
74
+ node_id: string;
75
+ avatar_url: string;
76
+ gravatar_id: string | null;
77
+ url: string;
78
+ html_url: string;
79
+ followers_url: string;
80
+ following_url: string;
81
+ gists_url: string;
82
+ starred_url: string;
83
+ subscriptions_url: string;
84
+ organizations_url: string;
85
+ repos_url: string;
86
+ events_url: string;
87
+ received_events_url: string;
88
+ type: string;
89
+ site_admin: boolean;
90
+ starred_at?: string;
91
+ user_view_type?: string;
92
+ } | null;
93
+ identifiers: readonly {
94
+ type: "CVE" | "GHSA";
95
+ value: string;
96
+ }[];
97
+ state: "published" | "closed" | "withdrawn" | "draft" | "triage";
98
+ created_at: string | null;
99
+ updated_at: string | null;
100
+ published_at: string | null;
101
+ closed_at: string | null;
102
+ withdrawn_at: string | null;
103
+ submission: {
104
+ readonly accepted: boolean;
105
+ } | null;
106
+ vulnerabilities: {
107
+ package: {
108
+ ecosystem: "actions" | "composer" | "erlang" | "go" | "maven" | "npm" | "nuget" | "other" | "pip" | "pub" | "rubygems" | "rust" | "swift";
109
+ name: string | null;
110
+ } | null;
111
+ vulnerable_version_range: string | null;
112
+ patched_versions: string | null;
113
+ vulnerable_functions: string[] | null;
114
+ }[] | null;
115
+ cvss: {
116
+ vector_string: string | null;
117
+ score: number | null;
118
+ } | null;
119
+ cvss_severities?: {
120
+ cvss_v3?: {
121
+ vector_string: string | null;
122
+ score: number | null;
123
+ } | null;
124
+ cvss_v4?: {
125
+ vector_string: string | null;
126
+ score: number | null;
127
+ } | null;
128
+ } | null;
129
+ cwes: readonly {
130
+ cwe_id: string;
131
+ name: string;
132
+ }[] | null;
133
+ cwe_ids: string[] | null;
134
+ credits: {
135
+ login?: string;
136
+ type?: "analyst" | "coordinator" | "finder" | "other" | "remediation_developer" | "remediation_reviewer" | "remediation_verifier" | "reporter" | "sponsor" | "tool";
137
+ }[] | null;
138
+ credits_detailed: readonly {
139
+ user: {
140
+ name?: string | null;
141
+ email?: string | null;
142
+ login: string;
143
+ id: number | bigint;
144
+ node_id: string;
145
+ avatar_url: string;
146
+ gravatar_id: string | null;
147
+ url: string;
148
+ html_url: string;
149
+ followers_url: string;
150
+ following_url: string;
151
+ gists_url: string;
152
+ starred_url: string;
153
+ subscriptions_url: string;
154
+ organizations_url: string;
155
+ repos_url: string;
156
+ events_url: string;
157
+ received_events_url: string;
158
+ type: string;
159
+ site_admin: boolean;
160
+ starred_at?: string;
161
+ user_view_type?: string;
162
+ };
163
+ type: "analyst" | "coordinator" | "finder" | "other" | "remediation_developer" | "remediation_reviewer" | "remediation_verifier" | "reporter" | "sponsor" | "tool";
164
+ state: "accepted" | "declined" | "pending";
165
+ }[] | null;
166
+ collaborating_users: {
167
+ name?: string | null;
168
+ email?: string | null;
169
+ login: string;
170
+ id: number | bigint;
171
+ node_id: string;
172
+ avatar_url: string;
173
+ gravatar_id: string | null;
174
+ url: string;
175
+ html_url: string;
176
+ followers_url: string;
177
+ following_url: string;
178
+ gists_url: string;
179
+ starred_url: string;
180
+ subscriptions_url: string;
181
+ organizations_url: string;
182
+ repos_url: string;
183
+ events_url: string;
184
+ received_events_url: string;
185
+ type: string;
186
+ site_admin: boolean;
187
+ starred_at?: string;
188
+ user_view_type?: string;
189
+ }[] | null;
190
+ collaborating_teams: {
191
+ id: number;
192
+ node_id: string;
193
+ name: string;
194
+ slug: string;
195
+ description: string | null;
196
+ privacy?: string;
197
+ notification_setting?: string;
198
+ permission: string;
199
+ permissions?: {
200
+ pull: boolean;
201
+ triage: boolean;
202
+ push: boolean;
203
+ maintain: boolean;
204
+ admin: boolean;
205
+ };
206
+ url: string;
207
+ html_url: string;
208
+ members_url: string;
209
+ repositories_url: string;
210
+ type: "enterprise" | "organization";
211
+ access_source?: "direct" | "organization" | "enterprise";
212
+ organization_id?: number;
213
+ enterprise_id?: number;
214
+ parent: {
215
+ id: number;
216
+ node_id: string;
217
+ url: string;
218
+ members_url: string;
219
+ name: string;
220
+ description: string | null;
221
+ permission: string;
222
+ privacy?: string;
223
+ notification_setting?: string;
224
+ html_url: string;
225
+ repositories_url: string;
226
+ slug: string;
227
+ ldap_dn?: string;
228
+ type: "enterprise" | "organization";
229
+ organization_id?: number;
230
+ enterprise_id?: number;
231
+ } | null;
232
+ }[] | null;
233
+ private_fork: {
234
+ id: number | bigint;
235
+ node_id: string;
236
+ name: string;
237
+ full_name: string;
238
+ owner: {
239
+ name?: string | null;
240
+ email?: string | null;
241
+ login: string;
242
+ id: number | bigint;
243
+ node_id: string;
244
+ avatar_url: string;
245
+ gravatar_id: string | null;
246
+ url: string;
247
+ html_url: string;
248
+ followers_url: string;
249
+ following_url: string;
250
+ gists_url: string;
251
+ starred_url: string;
252
+ subscriptions_url: string;
253
+ organizations_url: string;
254
+ repos_url: string;
255
+ events_url: string;
256
+ received_events_url: string;
257
+ type: string;
258
+ site_admin: boolean;
259
+ starred_at?: string;
260
+ user_view_type?: string;
261
+ };
262
+ private: boolean;
263
+ html_url: string;
264
+ description: string | null;
265
+ fork: boolean;
266
+ url: string;
267
+ archive_url: string;
268
+ assignees_url: string;
269
+ blobs_url: string;
270
+ branches_url: string;
271
+ collaborators_url: string;
272
+ comments_url: string;
273
+ commits_url: string;
274
+ compare_url: string;
275
+ contents_url: string;
276
+ contributors_url: string;
277
+ deployments_url: string;
278
+ downloads_url: string;
279
+ events_url: string;
280
+ forks_url: string;
281
+ git_commits_url: string;
282
+ git_refs_url: string;
283
+ git_tags_url: string;
284
+ issue_comment_url: string;
285
+ issue_events_url: string;
286
+ issues_url: string;
287
+ keys_url: string;
288
+ labels_url: string;
289
+ languages_url: string;
290
+ merges_url: string;
291
+ milestones_url: string;
292
+ notifications_url: string;
293
+ pulls_url: string;
294
+ releases_url: string;
295
+ stargazers_url: string;
296
+ statuses_url: string;
297
+ subscribers_url: string;
298
+ subscription_url: string;
299
+ tags_url: string;
300
+ teams_url: string;
301
+ trees_url: string;
302
+ hooks_url: string;
303
+ } | null;
304
+ }>;
305
+ declare function fetchGlobalAdvisory(github: Octokit, id: string, signal?: AbortSignal): Promise<{
306
+ ghsa_id: string;
307
+ cve_id: string | null;
308
+ url: string;
309
+ html_url: string;
310
+ repository_advisory_url: string | null;
311
+ summary: string;
312
+ description: string | null;
313
+ type: "reviewed" | "unreviewed" | "malware";
314
+ severity: "critical" | "high" | "medium" | "low" | "unknown";
315
+ source_code_location: string | null;
316
+ identifiers: readonly {
317
+ type: "CVE" | "GHSA";
318
+ value: string;
319
+ }[] | null;
320
+ references: string[] | null;
321
+ published_at: string;
322
+ updated_at: string;
323
+ github_reviewed_at: string | null;
324
+ nvd_published_at: string | null;
325
+ withdrawn_at: string | null;
326
+ vulnerabilities: {
327
+ package: {
328
+ ecosystem: "actions" | "composer" | "erlang" | "go" | "maven" | "npm" | "nuget" | "other" | "pip" | "pub" | "rubygems" | "rust" | "swift";
329
+ name: string | null;
330
+ } | null;
331
+ vulnerable_version_range: string | null;
332
+ first_patched_version: string | null;
333
+ vulnerable_functions: readonly string[] | null;
334
+ }[] | null;
335
+ cvss: {
336
+ vector_string: string | null;
337
+ score: number | null;
338
+ } | null;
339
+ cvss_severities?: {
340
+ cvss_v3?: {
341
+ vector_string: string | null;
342
+ score: number | null;
343
+ } | null;
344
+ cvss_v4?: {
345
+ vector_string: string | null;
346
+ score: number | null;
347
+ } | null;
348
+ } | null;
349
+ epss?: {
350
+ readonly percentage?: number;
351
+ readonly percentile?: number;
352
+ } | null;
353
+ cwes: {
354
+ cwe_id: string;
355
+ name: string;
356
+ }[] | null;
357
+ credits: readonly {
358
+ user: {
359
+ name?: string | null;
360
+ email?: string | null;
361
+ login: string;
362
+ id: number | bigint;
363
+ node_id: string;
364
+ avatar_url: string;
365
+ gravatar_id: string | null;
366
+ url: string;
367
+ html_url: string;
368
+ followers_url: string;
369
+ following_url: string;
370
+ gists_url: string;
371
+ starred_url: string;
372
+ subscriptions_url: string;
373
+ organizations_url: string;
374
+ repos_url: string;
375
+ events_url: string;
376
+ received_events_url: string;
377
+ type: string;
378
+ site_admin: boolean;
379
+ starred_at?: string;
380
+ user_view_type?: string;
381
+ };
382
+ type: "analyst" | "coordinator" | "finder" | "other" | "remediation_developer" | "remediation_reviewer" | "remediation_verifier" | "reporter" | "sponsor" | "tool";
383
+ }[] | null;
384
+ }>;
385
+ export {};
386
+ //# sourceMappingURL=github-advisories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-advisories.d.ts","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,eAAO,MAAM,sBAAsB,YACjC,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,CACA,CAAC;AAEX,MAAM,WAAW,2BAA2B;IAC1C,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC;IACjC,0EAA0E;IAC1E,KAAK,CAAC,EAAE,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;IAChD,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAYrB;AAED,iBAAe,mBAAmB,CAChC,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAOrB"}
@@ -0,0 +1,133 @@
1
+ import { CodexSecurityError, errorMessage } from "./errors.js";
2
+ import { requireExternalImports } from "./external-imports-feature.js";
3
+ import { createAuthenticatedGitHub } from "./github.js";
4
+ export const GITHUB_ADVISORY_STATES = [
5
+ "published",
6
+ "draft",
7
+ "triage",
8
+ "closed",
9
+ ];
10
+ /** Read repository disclosures or explicitly selected public GHSA records. */
11
+ export async function importGitHubAdvisories(options, dependencies = {}) {
12
+ options.signal?.throwIfAborted();
13
+ const environment = dependencies.environment ?? process.env;
14
+ requireExternalImports(environment);
15
+ const repository = options.repository.trim();
16
+ const parts = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)$/iu.exec(repository);
17
+ if (!parts || parts.slice(1).some((part) => /^\.{1,2}$/u.test(part)))
18
+ throw new CodexSecurityError("GitHub repository must be OWNER/REPO.");
19
+ const owner = parts[1];
20
+ const repo = parts[2];
21
+ const ids = [
22
+ ...new Set((options.advisoryIds ?? []).map((id) => id
23
+ .trim()
24
+ .toLowerCase()
25
+ .replace(/^ghsa-/u, "GHSA-"))),
26
+ ];
27
+ if (ids.some((id) => !/^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/u.test(id)))
28
+ throw new CodexSecurityError("GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.");
29
+ const source = options.source ?? "repository";
30
+ const state = options.state ?? "published";
31
+ if (source !== "repository" && source !== "global")
32
+ throw new CodexSecurityError("GitHub advisory source must be repository or global.");
33
+ if (!GITHUB_ADVISORY_STATES.includes(state))
34
+ throw new CodexSecurityError("GitHub advisory state is invalid.");
35
+ if (source === "global" && ids.length === 0)
36
+ throw new CodexSecurityError("Select explicit GHSA IDs for global advisories; database-wide import is not supported.");
37
+ if (ids.length > 0 && state !== "published")
38
+ throw new CodexSecurityError("--github-state only filters repository lists; omit it when selecting exact GHSA IDs.");
39
+ const host = options.githubHost?.trim() ??
40
+ (environment["GH_HOST"]?.trim() || "github.com");
41
+ if (!host)
42
+ throw new CodexSecurityError("GitHub host must not be empty.");
43
+ try {
44
+ const github = dependencies.createGitHub
45
+ ? await dependencies.createGitHub(host, options.signal)
46
+ : await createAuthenticatedGitHub(host, {
47
+ token: options.githubToken,
48
+ environment,
49
+ currentDirectory: dependencies.currentDirectory,
50
+ signal: options.signal,
51
+ });
52
+ const advisories = [];
53
+ if (ids.length > 0) {
54
+ for (const id of ids) {
55
+ options.signal?.throwIfAborted();
56
+ advisories.push(source === "global"
57
+ ? await fetchGlobalAdvisory(github, id, options.signal)
58
+ : await fetchRepositoryAdvisory(github, owner, repo, id, options.signal));
59
+ }
60
+ }
61
+ else {
62
+ let after;
63
+ const cursors = new Set();
64
+ do {
65
+ options.signal?.throwIfAborted();
66
+ const response = await github.request("GET /repos/{owner}/{repo}/security-advisories", {
67
+ owner,
68
+ repo,
69
+ state,
70
+ per_page: 100,
71
+ after,
72
+ request: { signal: options.signal, redirect: "error" },
73
+ });
74
+ advisories.push(...response.data);
75
+ const next = response.headers.link
76
+ ?.split(",")
77
+ .find((link) => /;\s*rel="next"/u.test(link));
78
+ const nextUrl = next?.match(/<([^>]+)>/u)?.[1];
79
+ // Keep requests on the authenticated route; only carry over the cursor.
80
+ after = nextUrl
81
+ ? (new URL(nextUrl).searchParams.get("after") ?? undefined)
82
+ : undefined;
83
+ if (next && (!after || cursors.has(after)))
84
+ throw new CodexSecurityError("GitHub returned invalid advisory pagination.");
85
+ if (after)
86
+ cursors.add(after);
87
+ } while (after !== undefined);
88
+ }
89
+ return advisories.map((advisory) => ({
90
+ source: "github-security-advisory",
91
+ selection: source,
92
+ repository,
93
+ githubHost: host,
94
+ ghsaId: advisory.ghsa_id,
95
+ url: advisory.html_url,
96
+ advisory,
97
+ }));
98
+ }
99
+ catch (error) {
100
+ options.signal?.throwIfAborted();
101
+ if (error instanceof CodexSecurityError)
102
+ throw error;
103
+ const status = typeof error === "object" && error !== null && "status" in error
104
+ ? error.status
105
+ : undefined;
106
+ if (status === 401)
107
+ throw new CodexSecurityError("GitHub authentication failed.");
108
+ if (status === 403)
109
+ throw new CodexSecurityError("GitHub denied security advisory access. Check repository advisory permissions and API rate limits.");
110
+ if (status === 404)
111
+ throw new CodexSecurityError("GitHub repository or security advisory was not found or is not accessible.");
112
+ if (status === 429)
113
+ throw new CodexSecurityError("GitHub request was rate limited. Wait and retry.");
114
+ throw new CodexSecurityError(`GitHub security advisory request failed${typeof status === "number" ? ` (HTTP ${status})` : ""}: ${errorMessage(error)}`);
115
+ }
116
+ }
117
+ async function fetchRepositoryAdvisory(github, owner, repo, id, signal) {
118
+ const response = await github.request("GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}", {
119
+ owner,
120
+ repo,
121
+ ghsa_id: id,
122
+ request: { signal, redirect: "error" },
123
+ });
124
+ return response.data;
125
+ }
126
+ async function fetchGlobalAdvisory(github, id, signal) {
127
+ const response = await github.request("GET /advisories/{ghsa_id}", {
128
+ ghsa_id: id,
129
+ request: { signal, redirect: "error" },
130
+ });
131
+ return response.data;
132
+ }
133
+ //# sourceMappingURL=github-advisories.js.map