@openai/codex-security 0.8.1 → 0.8.3
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.
- package/README.md +45 -57
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +187 -363
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +120 -35
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +414 -163
- package/dist/api.js.map +1 -1
- package/dist/auth.js +7 -2
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +635 -266
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +6 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +12 -5
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +11 -3
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +48 -16
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +44 -89
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +11 -15
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +12 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +411 -184
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +15 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1238 -226
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +10 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +71 -51
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +13 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +124 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +7 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +512 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +94 -36
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +5 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +110 -57
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +37 -48
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +48 -3
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +214 -39
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +50 -88
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +97 -106
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +320 -481
- package/docs/dedupe-records.md +27 -4
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +9 -10
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -35
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-import-models.js","sourceRoot":"","sources":["../src/external-import-models.ts"],"names":[],"mappings":"AAAA,qGAAqG","sourcesContent":["/* Generated from schemas/external-findings.schema.json. Run pnpm generate:external-import-models. */\n\nexport type RequestId = string;\nexport type Id = string;\nexport type RepoConnectorId = string;\nexport type EnvironmentId = string;\nexport type ResetMarker = string;\nexport type Provider = \"wiz\" | \"endor\" | \"snyk\" | \"github\" | \"semgrep\";\nexport type SourceKey = string;\nexport type ClientId = string;\nexport type SourceFindingId = string;\nexport type ExpectedVersion = number;\nexport type Title = string;\nexport type Severity =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type Description = string | null;\nexport type Url = string | null;\n/**\n * @maxItems 100\n */\nexport type AdvisoryIds = string[];\nexport type Name = string;\nexport type Ecosystem = string | null;\nexport type InstalledVersion = string | null;\nexport type VulnerableVersionRange = string | null;\nexport type ManifestPath = string | null;\n/**\n * @maxItems 100\n */\nexport type FixedVersions = string[];\n/**\n * @maxItems 100\n */\nexport type Packages = ImportedPackage[];\nexport type Path = string;\nexport type Line = number | null;\n/**\n * @maxItems 100\n */\nexport type Locations = ImportedLocation[];\nexport type Branch = string | null;\nexport type CodeRevision = string | null;\nexport type SourceScanId = string | null;\n/**\n * @maxItems 100\n */\nexport type ImageDigests = string[];\nexport type SourceUpdatedAt = number | null;\nexport type Kind = \"sast\" | \"secret\" | \"iac\" | \"advisory\";\nexport type Url1 = string;\nexport type Id1 = string | null;\nexport type Name1 = string | null;\nexport type Source = \"repository\" | \"global\";\nexport type SourceStatus = string | null;\nexport type ScannerOrigin = string | null;\nexport type ScannerVerdict = string | null;\nexport type Id2 = string | null;\nexport type ShortId = string | null;\nexport type Name2 = string | null;\n/**\n * @maxItems 100\n */\nexport type WeaknessIds = string[];\nexport type RemediationInstructions = string | null;\nexport type EndLine = number | null;\nexport type Snippet = string | null;\nexport type Type = string | null;\nexport type ImportedSecretConfidence = string;\nexport type ValidationStatus = string | null;\nexport type IsEncrypted = boolean | null;\nexport type IsManaged = boolean | null;\nexport type IntroducedCommit = string | null;\nexport type Platform = string | null;\nexport type CloudPlatform = string | null;\nexport type Expected = string | null;\nexport type Actual = string | null;\nexport type FileUrl = string | null;\n/**\n * @minItems 1\n * @maxItems 100\n */\nexport type Items = FindingImportItem[];\nexport type Id3 = string;\nexport type Object = \"security.finding_import\";\nexport type Actor = string;\nexport type CreatedAt = number;\nexport type ItemCount = number;\nexport type Created = number;\nexport type Updated = number;\nexport type Unchanged = number;\nexport type Error = number;\nexport type ClientId1 = string;\nexport type Outcome = \"created\" | \"updated\" | \"unchanged\" | \"error\";\nexport type SourceReportId = string | null;\nexport type ObservationId = string | null;\nexport type CanonicalFindingId = string | null;\nexport type Version = number | null;\nexport type Code =\n \"version_conflict\" | \"scope_conflict\" | \"stale_source_snapshot\";\nexport type Message = string;\nexport type Results = FindingImportResult[];\nexport type Object1 = \"page\";\nexport type Id4 = string;\nexport type Object2 = \"security.repository\";\nexport type RepoConnectorId1 = string;\nexport type Url2 = string;\nexport type DefaultBranch = string | null;\nexport type ResetMarker1 = string;\nexport type ImportEnvironmentId = string | null;\nexport type Data = ImportRepository[];\nexport type HasMore = boolean;\nexport type Next = string | null;\nexport type Id5 = string;\nexport type Object3 = \"security.source_report\";\nexport type Origin = \"imported\";\nexport type RepoId = string;\nexport type RepoConnectorId2 = string;\nexport type EnvironmentId1 = string;\nexport type CanonicalFindingId1 = string;\nexport type SourceFindingId1 = string;\nexport type ObservationId1 = string;\nexport type Version1 = number;\nexport type State = \"not_assessed\";\nexport type Id6 = string;\nexport type Actor1 = string;\nexport type CreatedAt1 = number;\nexport type CreatedAt2 = number;\nexport type UpdatedAt = number;\nexport type Object4 = \"page\";\nexport type Id7 = string;\nexport type Object5 = \"security.source_report_summary\";\nexport type Origin1 = \"imported\";\nexport type RepoId1 = string;\nexport type RepoConnectorId3 = string;\nexport type EnvironmentId2 = string;\nexport type CanonicalFindingId2 = string;\nexport type SourceFindingId2 = string;\nexport type ObservationId2 = string;\nexport type Version2 = number;\nexport type Title1 = string;\nexport type Severity1 =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type SourceUpdatedAt1 = number | null;\nexport type CreatedAt3 = number;\nexport type UpdatedAt1 = number;\nexport type Data1 = SourceReportSummary[];\nexport type HasMore1 = boolean;\nexport type Next1 = string | null;\n\n/**\n * Schema export root; transport endpoints return the individual models.\n */\nexport interface ExternalFindingContracts {\n request: FindingImportRequest;\n receipt: FindingImportReceipt;\n repositories: ImportRepositoryPage;\n source_report: SourceReport;\n source_reports: SourceReportPage;\n}\nexport interface FindingImportRequest {\n request_id: RequestId;\n repository: ImportDestination;\n source: ImportSource;\n items: Items;\n}\nexport interface ImportDestination {\n id: Id;\n repo_connector_id: RepoConnectorId;\n environment_id: EnvironmentId;\n reset_marker: ResetMarker;\n}\nexport interface ImportSource {\n provider: Provider;\n source_key: SourceKey;\n}\nexport interface FindingImportItem {\n client_id: ClientId;\n source_finding_id: SourceFindingId;\n expected_version: ExpectedVersion;\n evidence: ImportedFindingEvidence;\n}\nexport interface ImportedFindingEvidence {\n title: Title;\n severity: Severity;\n description?: Description;\n url?: Url;\n advisory_ids?: AdvisoryIds;\n packages?: Packages;\n locations?: Locations;\n branch?: Branch;\n code_revision?: CodeRevision;\n source_scan_id?: SourceScanId;\n image_digests?: ImageDigests;\n source_updated_at?: SourceUpdatedAt;\n source_data?: SourceData;\n details?: ImportedFindingDetails | null;\n}\nexport interface ImportedPackage {\n name: Name;\n ecosystem?: Ecosystem;\n installed_version?: InstalledVersion;\n vulnerable_version_range?: VulnerableVersionRange;\n manifest_path?: ManifestPath;\n fixed_versions?: FixedVersions;\n}\nexport interface ImportedLocation {\n path: Path;\n line?: Line;\n}\nexport interface SourceData {\n [k: string]: unknown;\n}\n/**\n * Typed repository evidence; vendor state is not a Codex assessment.\n */\nexport interface ImportedFindingDetails {\n kind: Kind;\n repository?: ImportedRepositoryReference | null;\n advisory?: ImportedAdvisoryContext | null;\n source_status?: SourceStatus;\n scanner_origin?: ScannerOrigin;\n scanner_verdict?: ScannerVerdict;\n rule?: ImportedFindingRule | null;\n weakness_ids?: WeaknessIds;\n remediation_instructions?: RemediationInstructions;\n code?: ImportedCodeContext | null;\n secret?: ImportedSecretDetails | null;\n configuration?: ImportedConfigurationDetails | null;\n file_url?: FileUrl;\n}\n/**\n * Vendor repository identity, resolved to the full source-control URL.\n */\nexport interface ImportedRepositoryReference {\n url: Url1;\n id?: Id1;\n name?: Name1;\n}\n/**\n * Where the advisory was read; applicability is assessed separately.\n */\nexport interface ImportedAdvisoryContext {\n source: Source;\n}\nexport interface ImportedFindingRule {\n id?: Id2;\n short_id?: ShortId;\n name?: Name2;\n}\n/**\n * Optional range and snippet for the evidence's first source location.\n */\nexport interface ImportedCodeContext {\n end_line?: EndLine;\n snippet?: Snippet;\n}\nexport interface ImportedSecretDetails {\n type?: Type;\n confidence?: ImportedSecretConfidence | null;\n validation_status?: ValidationStatus;\n is_encrypted?: IsEncrypted;\n is_managed?: IsManaged;\n introduced_commit?: IntroducedCommit;\n}\nexport interface ImportedConfigurationDetails {\n platform?: Platform;\n cloud_platform?: CloudPlatform;\n expected?: Expected;\n actual?: Actual;\n}\nexport interface FindingImportReceipt {\n id: Id3;\n object?: Object;\n repository: ImportDestination;\n source: ImportSource;\n actor: Actor;\n created_at: CreatedAt;\n item_count: ItemCount;\n counts: ImportCounts;\n results: Results;\n}\nexport interface ImportCounts {\n created?: Created;\n updated?: Updated;\n unchanged?: Unchanged;\n error?: Error;\n}\nexport interface FindingImportResult {\n client_id: ClientId1;\n outcome: Outcome;\n source_report_id?: SourceReportId;\n observation_id?: ObservationId;\n canonical_finding_id?: CanonicalFindingId;\n version?: Version;\n error?: ImportItemError | null;\n}\nexport interface ImportItemError {\n code: Code;\n message: Message;\n}\nexport interface ImportRepositoryPage {\n object?: Object1;\n data: Data;\n has_more: HasMore;\n next: Next;\n}\nexport interface ImportRepository {\n id: Id4;\n object?: Object2;\n repo_connector_id: RepoConnectorId1;\n url: Url2;\n default_branch?: DefaultBranch;\n reset_marker: ResetMarker1;\n import_environment_id?: ImportEnvironmentId;\n}\nexport interface SourceReport {\n id: Id5;\n object?: Object3;\n origin?: Origin;\n repo_id: RepoId;\n repo_connector_id: RepoConnectorId2;\n environment_id: EnvironmentId1;\n canonical_finding_id: CanonicalFindingId1;\n source: ImportSource;\n source_finding_id: SourceFindingId1;\n observation_id: ObservationId1;\n version: Version1;\n evidence: ImportedFindingEvidence;\n assessment?: ImportedAssessment;\n last_import?: LastImport | null;\n created_at: CreatedAt2;\n updated_at: UpdatedAt;\n}\nexport interface ImportedAssessment {\n state?: State;\n}\nexport interface LastImport {\n id: Id6;\n actor: Actor1;\n created_at: CreatedAt1;\n}\nexport interface SourceReportPage {\n object?: Object4;\n data: Data1;\n has_more: HasMore1;\n next: Next1;\n}\nexport interface SourceReportSummary {\n id: Id7;\n object?: Object5;\n origin?: Origin1;\n repo_id: RepoId1;\n repo_connector_id: RepoConnectorId3;\n environment_id: EnvironmentId2;\n canonical_finding_id: CanonicalFindingId2;\n source: ImportSource;\n source_finding_id: SourceFindingId2;\n observation_id: ObservationId2;\n version: Version2;\n title: Title1;\n severity: Severity1;\n source_updated_at: SourceUpdatedAt1;\n assessment?: ImportedAssessment;\n created_at: CreatedAt3;\n updated_at: UpdatedAt1;\n}\n\nexport type ExternalFindingEvidence = ImportedFindingEvidence;\n"]}
|
|
1
|
+
{"version":3,"file":"external-import-models.js","sourceRoot":"","sources":["../src/external-import-models.ts"],"names":[],"mappings":"AAAA,qGAAqG","sourcesContent":["/* Generated from schemas/external-findings.schema.json. Run pnpm generate:external-import-models. */\n\nexport type RequestId = string;\nexport type Id = string;\nexport type RepoConnectorId = string;\nexport type EnvironmentId = string;\nexport type ResetMarker = string;\nexport type Provider =\n | \"wiz\"\n | \"endor\"\n | \"snyk\"\n | \"github\"\n | \"semgrep\"\n | \"inspector\"\n | \"blackduck\"\n | \"veracode\"\n | \"sonar\"\n | \"continuum\";\nexport type SourceKey = string;\nexport type ClientId = string;\nexport type SourceFindingId = string;\nexport type ExpectedVersion = number;\nexport type Title = string;\nexport type Severity =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type Description = string | null;\nexport type Url = string | null;\n/**\n * @maxItems 100\n */\nexport type AdvisoryIds = string[];\nexport type Name = string;\nexport type Ecosystem = string | null;\nexport type InstalledVersion = string | null;\nexport type VulnerableVersionRange = string | null;\nexport type ManifestPath = string | null;\n/**\n * @maxItems 100\n */\nexport type FixedVersions = string[];\n/**\n * @maxItems 100\n */\nexport type Packages = ImportedPackage[];\nexport type Path = string;\nexport type Line = number | null;\n/**\n * @maxItems 100\n */\nexport type Locations = ImportedLocation[];\nexport type Branch = string | null;\nexport type CodeRevision = string | null;\nexport type SourceScanId = string | null;\n/**\n * @maxItems 100\n */\nexport type ImageDigests = string[];\nexport type SourceUpdatedAt = number | null;\nexport type Kind = \"sast\" | \"secret\" | \"iac\" | \"advisory\";\nexport type Url1 = string;\nexport type Id1 = string | null;\nexport type Name1 = string | null;\nexport type Source = \"repository\" | \"global\";\nexport type SourceStatus = string | null;\nexport type ScannerOrigin = string | null;\nexport type ScannerVerdict = string | null;\nexport type Id2 = string | null;\nexport type ShortId = string | null;\nexport type Name2 = string | null;\n/**\n * @maxItems 100\n */\nexport type WeaknessIds = string[];\nexport type RemediationInstructions = string | null;\nexport type EndLine = number | null;\nexport type Snippet = string | null;\nexport type Type = string | null;\nexport type ImportedSecretConfidence = string;\nexport type ValidationStatus = string | null;\nexport type IsEncrypted = boolean | null;\nexport type IsManaged = boolean | null;\nexport type IntroducedCommit = string | null;\nexport type Platform = string | null;\nexport type CloudPlatform = string | null;\nexport type Expected = string | null;\nexport type Actual = string | null;\nexport type FileUrl = string | null;\n/**\n * @minItems 1\n * @maxItems 100\n */\nexport type Items = FindingImportItem[];\nexport type Id3 = string;\nexport type Object = \"security.finding_import\";\nexport type Actor = string;\nexport type CreatedAt = number;\nexport type ItemCount = number;\nexport type Created = number;\nexport type Updated = number;\nexport type Unchanged = number;\nexport type Error = number;\nexport type ClientId1 = string;\nexport type Outcome = \"created\" | \"updated\" | \"unchanged\" | \"error\";\nexport type SourceReportId = string | null;\nexport type ObservationId = string | null;\nexport type CanonicalFindingId = string | null;\nexport type Version = number | null;\nexport type Code =\n \"version_conflict\" | \"scope_conflict\" | \"stale_source_snapshot\";\nexport type Message = string;\nexport type Results = FindingImportResult[];\nexport type Object1 = \"page\";\nexport type Id4 = string;\nexport type Object2 = \"security.repository\";\nexport type RepoConnectorId1 = string;\nexport type Url2 = string;\nexport type DefaultBranch = string | null;\nexport type ResetMarker1 = string;\nexport type ImportEnvironmentId = string | null;\nexport type Data = ImportRepository[];\nexport type HasMore = boolean;\nexport type Next = string | null;\nexport type Id5 = string;\nexport type Object3 = \"security.source_report\";\nexport type Origin = \"imported\";\nexport type RepoId = string;\nexport type RepoConnectorId2 = string;\nexport type EnvironmentId1 = string;\nexport type CanonicalFindingId1 = string;\nexport type SourceFindingId1 = string;\nexport type ObservationId1 = string;\nexport type Version1 = number;\nexport type State = \"not_assessed\";\nexport type Id6 = string;\nexport type Actor1 = string;\nexport type CreatedAt1 = number;\nexport type CreatedAt2 = number;\nexport type UpdatedAt = number;\nexport type Object4 = \"page\";\nexport type Id7 = string;\nexport type Object5 = \"security.source_report_summary\";\nexport type Origin1 = \"imported\";\nexport type RepoId1 = string;\nexport type RepoConnectorId3 = string;\nexport type EnvironmentId2 = string;\nexport type CanonicalFindingId2 = string;\nexport type SourceFindingId2 = string;\nexport type ObservationId2 = string;\nexport type Version2 = number;\nexport type Title1 = string;\nexport type Severity1 =\n \"critical\" | \"high\" | \"medium\" | \"low\" | \"informational\" | \"unknown\";\nexport type SourceUpdatedAt1 = number | null;\nexport type CreatedAt3 = number;\nexport type UpdatedAt1 = number;\nexport type Data1 = SourceReportSummary[];\nexport type HasMore1 = boolean;\nexport type Next1 = string | null;\n\n/**\n * Schema export root; transport endpoints return the individual models.\n */\nexport interface ExternalFindingContracts {\n request: FindingImportRequest;\n receipt: FindingImportReceipt;\n repositories: ImportRepositoryPage;\n source_report: SourceReport;\n source_reports: SourceReportPage;\n}\nexport interface FindingImportRequest {\n request_id: RequestId;\n repository: ImportDestination;\n source: ImportSource;\n items: Items;\n}\nexport interface ImportDestination {\n id: Id;\n repo_connector_id: RepoConnectorId;\n environment_id: EnvironmentId;\n reset_marker: ResetMarker;\n}\nexport interface ImportSource {\n provider: Provider;\n source_key: SourceKey;\n}\nexport interface FindingImportItem {\n client_id: ClientId;\n source_finding_id: SourceFindingId;\n expected_version: ExpectedVersion;\n evidence: ImportedFindingEvidence;\n}\nexport interface ImportedFindingEvidence {\n title: Title;\n severity: Severity;\n description?: Description;\n url?: Url;\n advisory_ids?: AdvisoryIds;\n packages?: Packages;\n locations?: Locations;\n branch?: Branch;\n code_revision?: CodeRevision;\n source_scan_id?: SourceScanId;\n image_digests?: ImageDigests;\n source_updated_at?: SourceUpdatedAt;\n source_data?: SourceData;\n details?: ImportedFindingDetails | null;\n}\nexport interface ImportedPackage {\n name: Name;\n ecosystem?: Ecosystem;\n installed_version?: InstalledVersion;\n vulnerable_version_range?: VulnerableVersionRange;\n manifest_path?: ManifestPath;\n fixed_versions?: FixedVersions;\n}\nexport interface ImportedLocation {\n path: Path;\n line?: Line;\n}\nexport interface SourceData {\n [k: string]: unknown;\n}\n/**\n * Typed repository evidence; vendor state is not a Codex assessment.\n */\nexport interface ImportedFindingDetails {\n kind: Kind;\n repository?: ImportedRepositoryReference | null;\n advisory?: ImportedAdvisoryContext | null;\n source_status?: SourceStatus;\n scanner_origin?: ScannerOrigin;\n scanner_verdict?: ScannerVerdict;\n rule?: ImportedFindingRule | null;\n weakness_ids?: WeaknessIds;\n remediation_instructions?: RemediationInstructions;\n code?: ImportedCodeContext | null;\n secret?: ImportedSecretDetails | null;\n configuration?: ImportedConfigurationDetails | null;\n file_url?: FileUrl;\n}\n/**\n * Vendor repository identity, resolved to the full source-control URL.\n */\nexport interface ImportedRepositoryReference {\n url: Url1;\n id?: Id1;\n name?: Name1;\n}\n/**\n * Where the advisory was read; applicability is assessed separately.\n */\nexport interface ImportedAdvisoryContext {\n source: Source;\n}\nexport interface ImportedFindingRule {\n id?: Id2;\n short_id?: ShortId;\n name?: Name2;\n}\n/**\n * Optional range and snippet for the evidence's first source location.\n */\nexport interface ImportedCodeContext {\n end_line?: EndLine;\n snippet?: Snippet;\n}\nexport interface ImportedSecretDetails {\n type?: Type;\n confidence?: ImportedSecretConfidence | null;\n validation_status?: ValidationStatus;\n is_encrypted?: IsEncrypted;\n is_managed?: IsManaged;\n introduced_commit?: IntroducedCommit;\n}\nexport interface ImportedConfigurationDetails {\n platform?: Platform;\n cloud_platform?: CloudPlatform;\n expected?: Expected;\n actual?: Actual;\n}\nexport interface FindingImportReceipt {\n id: Id3;\n object?: Object;\n repository: ImportDestination;\n source: ImportSource;\n actor: Actor;\n created_at: CreatedAt;\n item_count: ItemCount;\n counts: ImportCounts;\n results: Results;\n}\nexport interface ImportCounts {\n created?: Created;\n updated?: Updated;\n unchanged?: Unchanged;\n error?: Error;\n}\nexport interface FindingImportResult {\n client_id: ClientId1;\n outcome: Outcome;\n source_report_id?: SourceReportId;\n observation_id?: ObservationId;\n canonical_finding_id?: CanonicalFindingId;\n version?: Version;\n error?: ImportItemError | null;\n}\nexport interface ImportItemError {\n code: Code;\n message: Message;\n}\nexport interface ImportRepositoryPage {\n object?: Object1;\n data: Data;\n has_more: HasMore;\n next: Next;\n}\nexport interface ImportRepository {\n id: Id4;\n object?: Object2;\n repo_connector_id: RepoConnectorId1;\n url: Url2;\n default_branch?: DefaultBranch;\n reset_marker: ResetMarker1;\n import_environment_id?: ImportEnvironmentId;\n}\nexport interface SourceReport {\n id: Id5;\n object?: Object3;\n origin?: Origin;\n repo_id: RepoId;\n repo_connector_id: RepoConnectorId2;\n environment_id: EnvironmentId1;\n canonical_finding_id: CanonicalFindingId1;\n source: ImportSource;\n source_finding_id: SourceFindingId1;\n observation_id: ObservationId1;\n version: Version1;\n evidence: ImportedFindingEvidence;\n assessment?: ImportedAssessment;\n last_import?: LastImport | null;\n created_at: CreatedAt2;\n updated_at: UpdatedAt;\n}\nexport interface ImportedAssessment {\n state?: State;\n}\nexport interface LastImport {\n id: Id6;\n actor: Actor1;\n created_at: CreatedAt1;\n}\nexport interface SourceReportPage {\n object?: Object4;\n data: Data1;\n has_more: HasMore1;\n next: Next1;\n}\nexport interface SourceReportSummary {\n id: Id7;\n object?: Object5;\n origin?: Origin1;\n repo_id: RepoId1;\n repo_connector_id: RepoConnectorId3;\n environment_id: EnvironmentId2;\n canonical_finding_id: CanonicalFindingId2;\n source: ImportSource;\n source_finding_id: SourceFindingId2;\n observation_id: ObservationId2;\n version: Version2;\n title: Title1;\n severity: Severity1;\n source_updated_at: SourceUpdatedAt1;\n assessment?: ImportedAssessment;\n created_at: CreatedAt3;\n updated_at: UpdatedAt1;\n}\n\nexport type ExternalFindingEvidence = ImportedFindingEvidence;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type JsonObject = Record<string, unknown>;
|
|
2
2
|
/** Compatibility for historical report reads; never use this to admit new writes. */
|
|
3
|
-
export declare function normalizePersistedFindingDetails(finding: JsonObject): void;
|
|
3
|
+
export declare function normalizePersistedFindingDetails(finding: JsonObject, profile?: "sdk" | "tracking"): void;
|
|
4
4
|
export {};
|
|
5
5
|
//# sourceMappingURL=finding-normalization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding-normalization.d.ts","sourceRoot":"","sources":["../src/finding-normalization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"finding-normalization.d.ts","sourceRoot":"","sources":["../src/finding-normalization.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,qFAAqF;AACrF,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE,KAAK,GAAG,UAAkB,GAClC,IAAI,CAwKN"}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
/* Generated from plugin finding-normalization.ts. Run `pnpm generate:models`. */
|
|
1
2
|
import { isRecord as isObject } from "./record.js";
|
|
3
|
+
import { hasRequiredFindingText } from "./contract-values.js";
|
|
2
4
|
/** Compatibility for historical report reads; never use this to admit new writes. */
|
|
3
|
-
export function normalizePersistedFindingDetails(finding) {
|
|
5
|
+
export function normalizePersistedFindingDetails(finding, profile = "sdk") {
|
|
6
|
+
const evidenceIds = new Set();
|
|
7
|
+
if (profile === "tracking" && Array.isArray(finding["codeEvidence"])) {
|
|
8
|
+
for (const evidence of finding["codeEvidence"]) {
|
|
9
|
+
if (isObject(evidence) && isNonEmptyString(evidence["id"]))
|
|
10
|
+
evidenceIds.add(evidence["id"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
if (Array.isArray(finding["code_evidence"])) {
|
|
5
|
-
finding["code_evidence"] = finding["code_evidence"].filter((evidence) =>
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
finding["code_evidence"] = finding["code_evidence"].filter((evidence) => {
|
|
15
|
+
if (!isObject(evidence) ||
|
|
16
|
+
!isNonEmptyString(evidence["id"]) ||
|
|
17
|
+
!isNonEmptyString(evidence["code"]))
|
|
18
|
+
return false;
|
|
19
|
+
if (profile === "sdk")
|
|
20
|
+
return true;
|
|
21
|
+
if (!hasRequiredFindingText(evidence["id"]) ||
|
|
22
|
+
!hasRequiredFindingText(evidence["code"]) ||
|
|
23
|
+
evidenceIds.has(evidence["id"]))
|
|
24
|
+
return false;
|
|
25
|
+
evidenceIds.add(evidence["id"]);
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
8
28
|
}
|
|
9
|
-
else if (finding["code_evidence"] !== null) {
|
|
29
|
+
else if (profile === "tracking" || finding["code_evidence"] !== null) {
|
|
10
30
|
delete finding["code_evidence"];
|
|
11
31
|
}
|
|
12
32
|
for (const [sectionName, listFields] of [
|
|
@@ -50,12 +70,15 @@ export function normalizePersistedFindingDetails(finding) {
|
|
|
50
70
|
"language",
|
|
51
71
|
]);
|
|
52
72
|
}
|
|
53
|
-
else if (legacyRootCause !== null &&
|
|
73
|
+
else if (legacyRootCause !== null &&
|
|
74
|
+
(typeof legacyRootCause !== "string" ||
|
|
75
|
+
(profile === "tracking" && legacyRootCause === ""))) {
|
|
54
76
|
delete finding["root_cause"];
|
|
55
77
|
}
|
|
56
78
|
const validation = finding["validation"];
|
|
57
79
|
if (isObject(validation)) {
|
|
58
|
-
removeUnsupportedPersistedStrings(validation, ["method", "status", "summary", "disposition", "result"].filter((field) =>
|
|
80
|
+
removeUnsupportedPersistedStrings(validation, ["method", "status", "summary", "disposition", "result"].filter((field) => profile === "tracking" ||
|
|
81
|
+
!["status", "disposition", "result"].includes(field) ||
|
|
59
82
|
validation[field] !== null));
|
|
60
83
|
}
|
|
61
84
|
const attackPath = finding["attackPath"];
|
|
@@ -97,14 +120,26 @@ export function normalizePersistedFindingDetails(finding) {
|
|
|
97
120
|
function normalizePersistedStringLists(section, fields) {
|
|
98
121
|
for (const field of fields) {
|
|
99
122
|
const value = section[field];
|
|
100
|
-
|
|
101
|
-
|
|
123
|
+
const accepted = (value) => isNonEmptyString(value) &&
|
|
124
|
+
(profile === "sdk" || hasRequiredFindingText(value));
|
|
125
|
+
if (accepted(value)) {
|
|
126
|
+
if (profile === "tracking" || field !== "evidence")
|
|
102
127
|
section[field] = [value];
|
|
103
128
|
}
|
|
104
|
-
else if (Array.isArray(value))
|
|
105
|
-
|
|
129
|
+
else if (Array.isArray(value)) {
|
|
130
|
+
const items = value.filter(accepted);
|
|
131
|
+
if (profile === "tracking" && items.length === 0)
|
|
132
|
+
delete section[field];
|
|
133
|
+
else
|
|
134
|
+
section[field] = items;
|
|
135
|
+
}
|
|
106
136
|
else
|
|
107
137
|
delete section[field];
|
|
138
|
+
if (profile === "tracking" &&
|
|
139
|
+
(field === "evidenceRefs" || field === "evidence_refs") &&
|
|
140
|
+
Array.isArray(section[field])) {
|
|
141
|
+
section[field] = section[field].filter((ref) => typeof ref === "string" && evidenceIds.has(ref));
|
|
142
|
+
}
|
|
108
143
|
}
|
|
109
144
|
}
|
|
110
145
|
function removeUnsupportedPersistedStrings(section, fields) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding-normalization.js","sourceRoot":"","sources":["../src/finding-normalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAInD,qFAAqF;AACrF,MAAM,UAAU,gCAAgC,CAAC,OAAmB;IAClE,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CACxD,CAAC,QAAQ,EAAE,EAAE,CACX,QAAQ,CA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C,KAAc;QACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACvD,CAAC;AACH,CAAC","sourcesContent":["import { isRecord as isObject } from \"./record.js\";\n\ntype JsonObject = Record<string, unknown>;\n\n/** Compatibility for historical report reads; never use this to admit new writes. */\nexport function normalizePersistedFindingDetails(finding: JsonObject): void {\n if (Array.isArray(finding[\"code_evidence\"])) {\n finding[\"code_evidence\"] = finding[\"code_evidence\"].filter(\n (evidence) =>\n isObject(evidence) &&\n isNonEmptyString(evidence[\"id\"]) &&\n isNonEmptyString(evidence[\"code\"]),\n );\n } else if (finding[\"code_evidence\"] !== null) {\n delete finding[\"code_evidence\"];\n }\n\n for (const [sectionName, listFields] of [\n [\"rootCause\", [\"evidenceRefs\", \"evidence_refs\"]],\n [\"root_cause\", [\"evidenceRefs\", \"evidence_refs\"]],\n [\n \"validation\",\n [\n \"assertions\",\n \"counterEvidence\",\n \"evidence\",\n \"evidenceRefs\",\n \"evidence_refs\",\n \"limitations\",\n ],\n ],\n [\n \"attackPath\",\n [\n \"assumptions\",\n \"blindspots\",\n \"controls\",\n \"evidenceRefs\",\n \"evidence_refs\",\n \"limitations\",\n \"preconditions\",\n \"steps\",\n ],\n ],\n ] satisfies Array<[string, string[]]>) {\n const section = finding[sectionName];\n if (!isObject(section)) continue;\n normalizePersistedStringLists(section, listFields);\n }\n\n const legacyRootCause = finding[\"root_cause\"];\n if (isObject(legacyRootCause)) {\n removeUnsupportedPersistedStrings(legacyRootCause, [\n \"summary\",\n \"code\",\n \"language\",\n ]);\n } else if (legacyRootCause !== null && typeof legacyRootCause !== \"string\") {\n delete finding[\"root_cause\"];\n }\n\n const validation = finding[\"validation\"];\n if (isObject(validation)) {\n removeUnsupportedPersistedStrings(\n validation,\n [\"method\", \"status\", \"summary\", \"disposition\", \"result\"].filter(\n (field) =>\n ![\"status\", \"disposition\", \"result\"].includes(field) ||\n validation[field] !== null,\n ),\n );\n }\n\n const attackPath = finding[\"attackPath\"];\n if (!isObject(attackPath)) return;\n removeUnsupportedPersistedStrings(attackPath, [\"summary\"]);\n for (const field of [\"dataFlow\", \"data_flow\", \"dataflow\", \"reachability\"]) {\n const detail = attackPath[field];\n if (!isObject(detail)) {\n if (!isNonEmptyString(detail)) delete attackPath[field];\n continue;\n }\n removeUnsupportedPersistedStrings(detail, [\n \"summary\",\n \"source\",\n \"sink\",\n \"outcome\",\n ...(field === \"reachability\" ? [\"attacker\", \"entrypoint\"] : []),\n ]);\n normalizePersistedStringLists(detail, [\n \"evidenceRefs\",\n \"evidence_refs\",\n \"transformations\",\n ...(field === \"reachability\" ? [\"preconditions\"] : []),\n ]);\n }\n for (const field of [\"impact\", \"likelihood\"]) {\n const detail = attackPath[field];\n if (isObject(detail)) {\n removeUnsupportedPersistedStrings(detail, [\"level\", \"rationale\", \"why\"]);\n } else if (\n detail !== undefined &&\n detail !== null &&\n !isNonEmptyString(detail)\n ) {\n delete attackPath[field];\n }\n }\n\n function normalizePersistedStringLists(\n section: JsonObject,\n fields: string[],\n ): void {\n for (const field of fields) {\n const value = section[field];\n if (isNonEmptyString(value)) {\n if (field !== \"evidence\") section[field] = [value];\n } else if (Array.isArray(value))\n section[field] = value.filter(isNonEmptyString);\n else delete section[field];\n }\n }\n\n function removeUnsupportedPersistedStrings(\n section: JsonObject,\n fields: string[],\n ): void {\n for (const field of fields) {\n if (!isNonEmptyString(section[field])) delete section[field];\n }\n }\n\n function isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"finding-normalization.js","sourceRoot":"","sources":["../src/finding-normalization.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,qFAAqF;AACrF,MAAM,UAAU,gCAAgC,CAC9C,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AAC,CAAC;YAC7B,IACE,OAAO,KAAK,UAAU;gBACtB,CAAC,KAAK,KAAK,cAAc,IAAI,KAAK,KAAK,eAAe,CAAC;gBACvD,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAC7B,CAAC;gBACD,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CACpC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CACzD,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,SAAS,iCAAiC,CACxC,OAAmB,EACnB,MAAgB;QAEhB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,SAAS,gBAAgB,CAAC,KAAc;QACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACvD,CAAC;AACH,CAAC","sourcesContent":["/* Generated from plugin finding-normalization.ts. Run `pnpm generate:models`. */\nimport { isRecord as isObject } from \"./record.js\";\nimport { hasRequiredFindingText } from \"./contract-values.js\";\n\ntype JsonObject = Record<string, unknown>;\n\n/** Compatibility for historical report reads; never use this to admit new writes. */\nexport function normalizePersistedFindingDetails(\n finding: JsonObject,\n profile: \"sdk\" | \"tracking\" = \"sdk\",\n): void {\n const evidenceIds = new Set<string>();\n if (profile === \"tracking\" && Array.isArray(finding[\"codeEvidence\"])) {\n for (const evidence of finding[\"codeEvidence\"]) {\n if (isObject(evidence) && isNonEmptyString(evidence[\"id\"]))\n evidenceIds.add(evidence[\"id\"]);\n }\n }\n if (Array.isArray(finding[\"code_evidence\"])) {\n finding[\"code_evidence\"] = finding[\"code_evidence\"].filter((evidence) => {\n if (\n !isObject(evidence) ||\n !isNonEmptyString(evidence[\"id\"]) ||\n !isNonEmptyString(evidence[\"code\"])\n )\n return false;\n if (profile === \"sdk\") return true;\n if (\n !hasRequiredFindingText(evidence[\"id\"]) ||\n !hasRequiredFindingText(evidence[\"code\"]) ||\n evidenceIds.has(evidence[\"id\"])\n )\n return false;\n evidenceIds.add(evidence[\"id\"]);\n return true;\n });\n } else if (profile === \"tracking\" || finding[\"code_evidence\"] !== null) {\n delete finding[\"code_evidence\"];\n }\n\n for (const [sectionName, listFields] of [\n [\"rootCause\", [\"evidenceRefs\", \"evidence_refs\"]],\n [\"root_cause\", [\"evidenceRefs\", \"evidence_refs\"]],\n [\n \"validation\",\n [\n \"assertions\",\n \"counterEvidence\",\n \"evidence\",\n \"evidenceRefs\",\n \"evidence_refs\",\n \"limitations\",\n ],\n ],\n [\n \"attackPath\",\n [\n \"assumptions\",\n \"blindspots\",\n \"controls\",\n \"evidenceRefs\",\n \"evidence_refs\",\n \"limitations\",\n \"preconditions\",\n \"steps\",\n ],\n ],\n ] satisfies Array<[string, string[]]>) {\n const section = finding[sectionName];\n if (!isObject(section)) continue;\n normalizePersistedStringLists(section, listFields);\n }\n\n const legacyRootCause = finding[\"root_cause\"];\n if (isObject(legacyRootCause)) {\n removeUnsupportedPersistedStrings(legacyRootCause, [\n \"summary\",\n \"code\",\n \"language\",\n ]);\n } else if (\n legacyRootCause !== null &&\n (typeof legacyRootCause !== \"string\" ||\n (profile === \"tracking\" && legacyRootCause === \"\"))\n ) {\n delete finding[\"root_cause\"];\n }\n\n const validation = finding[\"validation\"];\n if (isObject(validation)) {\n removeUnsupportedPersistedStrings(\n validation,\n [\"method\", \"status\", \"summary\", \"disposition\", \"result\"].filter(\n (field) =>\n profile === \"tracking\" ||\n ![\"status\", \"disposition\", \"result\"].includes(field) ||\n validation[field] !== null,\n ),\n );\n }\n\n const attackPath = finding[\"attackPath\"];\n if (!isObject(attackPath)) return;\n removeUnsupportedPersistedStrings(attackPath, [\"summary\"]);\n for (const field of [\"dataFlow\", \"data_flow\", \"dataflow\", \"reachability\"]) {\n const detail = attackPath[field];\n if (!isObject(detail)) {\n if (!isNonEmptyString(detail)) delete attackPath[field];\n continue;\n }\n removeUnsupportedPersistedStrings(detail, [\n \"summary\",\n \"source\",\n \"sink\",\n \"outcome\",\n ...(field === \"reachability\" ? [\"attacker\", \"entrypoint\"] : []),\n ]);\n normalizePersistedStringLists(detail, [\n \"evidenceRefs\",\n \"evidence_refs\",\n \"transformations\",\n ...(field === \"reachability\" ? [\"preconditions\"] : []),\n ]);\n }\n for (const field of [\"impact\", \"likelihood\"]) {\n const detail = attackPath[field];\n if (isObject(detail)) {\n removeUnsupportedPersistedStrings(detail, [\"level\", \"rationale\", \"why\"]);\n } else if (\n detail !== undefined &&\n detail !== null &&\n !isNonEmptyString(detail)\n ) {\n delete attackPath[field];\n }\n }\n\n function normalizePersistedStringLists(\n section: JsonObject,\n fields: string[],\n ): void {\n for (const field of fields) {\n const value = section[field];\n const accepted = (value: unknown): value is string =>\n isNonEmptyString(value) &&\n (profile === \"sdk\" || hasRequiredFindingText(value));\n if (accepted(value)) {\n if (profile === \"tracking\" || field !== \"evidence\")\n section[field] = [value];\n } else if (Array.isArray(value)) {\n const items = value.filter(accepted);\n if (profile === \"tracking\" && items.length === 0) delete section[field];\n else section[field] = items;\n } else delete section[field];\n if (\n profile === \"tracking\" &&\n (field === \"evidenceRefs\" || field === \"evidence_refs\") &&\n Array.isArray(section[field])\n ) {\n section[field] = section[field].filter(\n (ref) => typeof ref === \"string\" && evidenceIds.has(ref),\n );\n }\n }\n }\n\n function removeUnsupportedPersistedStrings(\n section: JsonObject,\n fields: string[],\n ): void {\n for (const field of fields) {\n if (!isNonEmptyString(section[field])) delete section[field];\n }\n }\n\n function isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n }\n}\n"]}
|
|
@@ -11,9 +11,9 @@ export interface FindingSourceSnapshot {
|
|
|
11
11
|
revision: string;
|
|
12
12
|
snapshotDigest: string | null;
|
|
13
13
|
}
|
|
14
|
-
export interface FindingNeighborhood {
|
|
15
|
-
finding:
|
|
16
|
-
potentialDuplicates:
|
|
14
|
+
export interface FindingNeighborhood<T = Finding> {
|
|
15
|
+
finding: T;
|
|
16
|
+
potentialDuplicates: T[];
|
|
17
17
|
/** Saved storage associations, separate from model-authored finding content. */
|
|
18
18
|
repositoryIds?: Record<string, string[]>;
|
|
19
19
|
/** Present only when the current body matches its persisted scan occurrence. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding-retrieval.d.ts","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,eAAe,EAAE,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;
|
|
1
|
+
{"version":3,"file":"finding-retrieval.d.ts","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,eAAe,EAAE,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,OAAO;IAC9C,OAAO,EAAE,CAAC,CAAC;IACX,mBAAmB,EAAE,CAAC,EAAE,CAAC;IACzB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CACzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding-retrieval.js","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"","sourcesContent":["import type { Finding } from \"./models.js\";\n\nexport type FindingSearchScope =\n | { repositoryId: string; allRepositories?: never }\n | { allRepositories: true; repositoryId?: never };\n\nexport interface FindingSourceSnapshot {\n repositoryId: string | null;\n revision: string;\n snapshotDigest: string | null;\n}\n\nexport interface FindingNeighborhood {\n finding:
|
|
1
|
+
{"version":3,"file":"finding-retrieval.js","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"","sourcesContent":["import type { Finding } from \"./models.js\";\n\nexport type FindingSearchScope =\n | { repositoryId: string; allRepositories?: never }\n | { allRepositories: true; repositoryId?: never };\n\nexport interface FindingSourceSnapshot {\n repositoryId: string | null;\n revision: string;\n snapshotDigest: string | null;\n}\n\nexport interface FindingNeighborhood<T = Finding> {\n finding: T;\n potentialDuplicates: T[];\n /** Saved storage associations, separate from model-authored finding content. */\n repositoryIds?: Record<string, string[]>;\n /** Present only when the current body matches its persisted scan occurrence. */\n sourceSnapshots?: Record<string, FindingSourceSnapshot>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonObject } from "./config.js";
|
|
2
2
|
import type { LoadedContract } from "./contract.js";
|
|
3
|
+
import type { ScanCost } from "./cost-model.js";
|
|
3
4
|
import type { FindingSearchScope } from "./finding-retrieval.js";
|
|
4
5
|
import { runWorkbench, type WorkbenchCommandOptions } from "./runtime.js";
|
|
5
6
|
export type WorkflowStage = "scan" | "publish" | "dedupe";
|
|
@@ -14,6 +15,7 @@ export interface WorkflowBinding {
|
|
|
14
15
|
}
|
|
15
16
|
export interface WorkflowState extends WorkflowBinding {
|
|
16
17
|
id: string;
|
|
18
|
+
recordedCost?: ScanCost;
|
|
17
19
|
stages: Record<WorkflowStage, {
|
|
18
20
|
status: "pending" | "running" | "failed" | "completed";
|
|
19
21
|
result?: unknown;
|
|
@@ -57,7 +59,10 @@ export declare class FindingWorkflow {
|
|
|
57
59
|
complete(stage: WorkflowStage, result: unknown): Promise<WorkflowState>;
|
|
58
60
|
fail(stage: WorkflowStage, error: unknown, result?: unknown): Promise<void>;
|
|
59
61
|
run<T>(stage: WorkflowStage, operation: () => Promise<T>): Promise<T>;
|
|
60
|
-
registeredScan(scanId: string): Promise<
|
|
62
|
+
registeredScan(scanId: string): Promise<{
|
|
63
|
+
scan: JsonObject;
|
|
64
|
+
recipe: import("./config.js").JsonValue | undefined;
|
|
65
|
+
}>;
|
|
61
66
|
sourceSnapshot(repository: string, options?: SourceSnapshotOptions & {
|
|
62
67
|
optional?: false;
|
|
63
68
|
}): Promise<JsonObject>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding-workflow.d.ts","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"finding-workflow.d.ts","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO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GACd,OAAO,CAAC,aAAa,CAAC,CAExB;IAEK,IAAI,CACR,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC,CAOf;IAEK,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAY1E;IAEK,cAAc,CAAC,MAAM,EAAE,MAAM;cAEV,UAAU;;OAClC;IAEK,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,qBAAqB,GAAG;QAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;KAAE,GACrD,OAAO,CAAC,UAAU,CAAC,CAAC;IACjB,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,qBAAqB,GAAG;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,GAClD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAmBxB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7C;IAEK,UAAU,CACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,EACf,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO,GAClC,OAAO,CAAC,IAAI,CAAC,CAQf;IAEK,aAAa,CACjB,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,kBAAkB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAOf;YAEa,OAAO;YAKP,OAAO;YAOP,IAAI;CAgBnB"}
|
package/dist/finding-workflow.js
CHANGED
|
@@ -79,8 +79,8 @@ export class FindingWorkflow {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
async registeredScan(scanId) {
|
|
82
|
-
const
|
|
83
|
-
return
|
|
82
|
+
const { scan, recipe } = await this.call(["get-scan", "--scan-id", scanId]);
|
|
83
|
+
return { scan: scan, recipe };
|
|
84
84
|
}
|
|
85
85
|
async sourceSnapshot(repository, options = {}) {
|
|
86
86
|
return (await this.request({
|
|
@@ -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;AAGtD,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,cAAc,CAAC;AAqCtB,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CACzD,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC/D,CAAC,CAAC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACtE;QACH,CAAC,CAAC,IAAI,CACT,CAAC;IACF,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,I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C5C,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,IAAI,CAChB,IAAuB,EACvB,KAAc;QAEd,IAAI,CAAC,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YAC7B,UAAU,EAAE,MAAM,iBAAiB,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,SAAS,CAAC,aAAa;aAC5C,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 type { LoadedContract } from \"./contract.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 scanArtifactDigest({\n manifest,\n findings,\n review,\n}: Pick<LoadedContract, \"manifest\" | \"findings\" | \"review\">): string {\n return workflowDigest({ manifest, findings, review });\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"]}
|
|
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;AAItD,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,cAAc,CAAC;AAsCtB,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CACzD,IAAI,KAAK,I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,CAAC,aAAa,CACjB,MAAe,EACf,YAAgC;QAEhC,MAAM,IAAI,CAAC,OAAO,CAAC;YACjB,MAAM,EAAE,gBAAgB;YACxB,KAAK,EAAE,QAAQ;YACf,MAAM;YACN,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,OAAe;QACnC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC,UAAU,CAAoC,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,OAAe;QACnC,OAAO,MAAM,IAAI,CAAC,IAAI,CACpB,CAAC,kBAAkB,CAAC,EACpB,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAC5C,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,IAAI,CAChB,IAAuB,EACvB,KAAc;QAEd,IAAI,CAAC,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YAC7B,UAAU,EAAE,MAAM,iBAAiB,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,SAAS,CAAC,aAAa;aAC5C,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 type { LoadedContract } from \"./contract.js\";\nimport type { ScanCost } from \"./cost-model.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 recordedCost?: ScanCost;\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 scanArtifactDigest({\n manifest,\n findings,\n review,\n}: Pick<LoadedContract, \"manifest\" | \"findings\" | \"review\">): string {\n return workflowDigest({ manifest, findings, review });\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) {\n const { scan, recipe } = await this.call([\"get-scan\", \"--scan-id\", scanId]);\n return { scan: scan as JsonObject, recipe };\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"]}
|
package/dist/git-remote.d.ts
CHANGED
|
@@ -7,4 +7,8 @@ export interface GitRemote {
|
|
|
7
7
|
/** Parse transport syntax only; callers decide which hosts and credentials are allowed. */
|
|
8
8
|
export declare function parseGitRemote(remote: string): GitRemote | undefined;
|
|
9
9
|
export declare function isGitHubCloudHost(host: string): boolean;
|
|
10
|
+
export declare function isGitSsh(protocol: string): boolean;
|
|
11
|
+
export declare function isGitHubSshOverHttps(url: URL): boolean;
|
|
12
|
+
/** Azure Repos uses different hosts and paths for the same SSH and HTTPS repository. */
|
|
13
|
+
export declare function azureReposHttpsUrl(url: URL, path: string): string | undefined;
|
|
10
14
|
//# sourceMappingURL=git-remote.d.ts.map
|
package/dist/git-remote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-remote.d.ts","sourceRoot":"","sources":["../src/git-remote.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,GAAG,CAAC;IACT,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAmBpE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|
|
1
|
+
{"version":3,"file":"git-remote.d.ts","sourceRoot":"","sources":["../src/git-remote.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,GAAG,CAAC;IACT,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAmBpE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAMtD;AAED,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAY7E"}
|
package/dist/git-remote.js
CHANGED
|
@@ -21,4 +21,24 @@ export function parseGitRemote(remote) {
|
|
|
21
21
|
export function isGitHubCloudHost(host) {
|
|
22
22
|
return host === "github.com" || host.endsWith(".ghe.com");
|
|
23
23
|
}
|
|
24
|
+
export function isGitSsh(protocol) {
|
|
25
|
+
return ["ssh:", "git+ssh:", "ssh+git:"].includes(protocol);
|
|
26
|
+
}
|
|
27
|
+
export function isGitHubSshOverHttps(url) {
|
|
28
|
+
return (isGitSsh(url.protocol) &&
|
|
29
|
+
url.hostname.toLowerCase() === "ssh.github.com" &&
|
|
30
|
+
url.port === "443");
|
|
31
|
+
}
|
|
32
|
+
/** Azure Repos uses different hosts and paths for the same SSH and HTTPS repository. */
|
|
33
|
+
export function azureReposHttpsUrl(url, path) {
|
|
34
|
+
if (!isGitSsh(url.protocol) ||
|
|
35
|
+
url.hostname.toLowerCase() !== "ssh.dev.azure.com" ||
|
|
36
|
+
url.username !== "git" ||
|
|
37
|
+
url.password ||
|
|
38
|
+
(url.port && url.port !== "22"))
|
|
39
|
+
return;
|
|
40
|
+
const match = /^v3\/([^/]+)\/([^/]+)\/([^/]+)$/u.exec(path);
|
|
41
|
+
if (match)
|
|
42
|
+
return `https://dev.azure.com/${match[1]}/${match[2]}/_git/${match[3]}`;
|
|
43
|
+
}
|
|
24
44
|
//# sourceMappingURL=git-remote.js.map
|
package/dist/git-remote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-remote.js","sourceRoot":"","sources":["../src/git-remote.ts"],"names":[],"mappings":"AAOA,2FAA2F;AAC3F,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,OAAO;YACL,GAAG;YACH,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3B,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,uDAAuD,CAAC,IAAI,CACtE,MAAM,CACP,CAAC;IACF,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACnC,OAAO;QACL,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,wEAAwE;QACxE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAE;QACb,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["export interface GitRemote {\n url: URL;\n /** Repository path without a URL's leading slash; SCP paths remain literal. */\n path: string;\n scpStyle: boolean;\n}\n\n/** Parse transport syntax only; callers decide which hosts and credentials are allowed. */\nexport function parseGitRemote(remote: string): GitRemote | undefined {\n if (remote.includes(\"://\")) {\n const url = new URL(remote);\n return {\n url,\n path: url.pathname.slice(1),\n scpStyle: false,\n };\n }\n const scp = /^((?:[^@/:\\s?#]+@)?(?:\\[[^\\]]+\\]|[^@/:\\s?#]+)):(.+)$/u.exec(\n remote,\n );\n if (scp === null) return undefined;\n return {\n url: new URL(`ssh://${scp[1]}`),\n // An SCP path's ?, #, and dot segments are literal Git path characters.\n path: scp[2]!,\n scpStyle: true,\n };\n}\n\nexport function isGitHubCloudHost(host: string): boolean {\n return host === \"github.com\" || host.endsWith(\".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MAAM,UAAU,kBAAkB,CAAC,GAAQ,EAAE,IAAY;IACvD,IACE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;QACvB,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,mBAAmB;QAClD,GAAG,CAAC,QAAQ,KAAK,KAAK;QACtB,GAAG,CAAC,QAAQ;QACZ,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC;QAE/B,OAAO;IACT,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,IAAI,KAAK;QACP,OAAO,yBAAyB,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["export interface GitRemote {\n url: URL;\n /** Repository path without a URL's leading slash; SCP paths remain literal. */\n path: string;\n scpStyle: boolean;\n}\n\n/** Parse transport syntax only; callers decide which hosts and credentials are allowed. */\nexport function parseGitRemote(remote: string): GitRemote | undefined {\n if (remote.includes(\"://\")) {\n const url = new URL(remote);\n return {\n url,\n path: url.pathname.slice(1),\n scpStyle: false,\n };\n }\n const scp = /^((?:[^@/:\\s?#]+@)?(?:\\[[^\\]]+\\]|[^@/:\\s?#]+)):(.+)$/u.exec(\n remote,\n );\n if (scp === null) return undefined;\n return {\n url: new URL(`ssh://${scp[1]}`),\n // An SCP path's ?, #, and dot segments are literal Git path characters.\n path: scp[2]!,\n scpStyle: true,\n };\n}\n\nexport function isGitHubCloudHost(host: string): boolean {\n return host === \"github.com\" || host.endsWith(\".ghe.com\");\n}\n\nexport function isGitSsh(protocol: string): boolean {\n return [\"ssh:\", \"git+ssh:\", \"ssh+git:\"].includes(protocol);\n}\n\nexport function isGitHubSshOverHttps(url: URL): boolean {\n return (\n isGitSsh(url.protocol) &&\n url.hostname.toLowerCase() === \"ssh.github.com\" &&\n url.port === \"443\"\n );\n}\n\n/** Azure Repos uses different hosts and paths for the same SSH and HTTPS repository. */\nexport function azureReposHttpsUrl(url: URL, path: string): string | undefined {\n if (\n !isGitSsh(url.protocol) ||\n url.hostname.toLowerCase() !== \"ssh.dev.azure.com\" ||\n url.username !== \"git\" ||\n url.password ||\n (url.port && url.port !== \"22\")\n )\n return;\n const match = /^v3\\/([^/]+)\\/([^/]+)\\/([^/]+)$/u.exec(path);\n if (match)\n return `https://dev.azure.com/${match[1]}/${match[2]}/_git/${match[3]}`;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Octokit } from "@octokit/core";
|
|
2
|
+
import { type GitHubImportConnectionOptions, type GitHubImportDependencies } from "./github.js";
|
|
2
3
|
export declare const GITHUB_ADVISORY_STATES: readonly ["published", "draft", "triage", "closed"];
|
|
3
|
-
export interface GitHubAdvisoryImportOptions {
|
|
4
|
+
export interface GitHubAdvisoryImportOptions extends GitHubImportConnectionOptions {
|
|
4
5
|
/** Source repository, or the selected target for explicit global advisory IDs. */
|
|
5
6
|
repository: string;
|
|
6
7
|
/** Exact GHSA IDs. Required for the global advisory API. */
|
|
@@ -9,11 +10,6 @@ export interface GitHubAdvisoryImportOptions {
|
|
|
9
10
|
source?: "repository" | "global";
|
|
10
11
|
/** Repository list state (default: published). Exact IDs ignore state. */
|
|
11
12
|
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
13
|
}
|
|
18
14
|
type RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;
|
|
19
15
|
type GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;
|
|
@@ -27,13 +23,8 @@ export interface ImportedGitHubAdvisory {
|
|
|
27
23
|
/** Upstream disclosure, not proof that the selected repository is affected. */
|
|
28
24
|
advisory: RepositoryAdvisory | GlobalAdvisory;
|
|
29
25
|
}
|
|
30
|
-
interface GitHubAdvisoryImportDependencies {
|
|
31
|
-
environment?: NodeJS.ProcessEnv;
|
|
32
|
-
currentDirectory?: string;
|
|
33
|
-
createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;
|
|
34
|
-
}
|
|
35
26
|
/** Read repository disclosures or explicitly selected public GHSA records. */
|
|
36
|
-
export declare function importGitHubAdvisories(options: GitHubAdvisoryImportOptions, dependencies?:
|
|
27
|
+
export declare function importGitHubAdvisories(options: GitHubAdvisoryImportOptions, dependencies?: GitHubImportDependencies): Promise<ImportedGitHubAdvisory[]>;
|
|
37
28
|
declare function fetchRepositoryAdvisory(github: Octokit, owner: string, repo: string, id: string, signal?: AbortSignal): Promise<{
|
|
38
29
|
ghsa_id: string;
|
|
39
30
|
cve_id: string | null;
|
|
@@ -1 +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;
|
|
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;AAO7C,OAAO,EAIL,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,EAC9B,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,sBAAsB,YACjC,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,CACA,CAAC;AAEX,MAAM,WAAW,2BAA4B,SAAQ,6BAA6B;IAChF,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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AAM,EACV,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAOrB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CANONICAL_GHSA_ID, githubRepositoryParts, } from "./github-identifiers.js";
|
|
2
|
-
import { CodexSecurityError
|
|
2
|
+
import { CodexSecurityError } from "./errors.js";
|
|
3
3
|
import { requireExternalImports } from "./external-imports-feature.js";
|
|
4
|
-
import {
|
|
4
|
+
import { githubImportHost, githubImportClient, githubImportError, } from "./github.js";
|
|
5
5
|
export const GITHUB_ADVISORY_STATES = [
|
|
6
6
|
"published",
|
|
7
7
|
"draft",
|
|
@@ -36,19 +36,9 @@ export async function importGitHubAdvisories(options, dependencies = {}) {
|
|
|
36
36
|
throw new CodexSecurityError("Select explicit GHSA IDs for global advisories; database-wide import is not supported.");
|
|
37
37
|
if (ids.length > 0 && state !== "published")
|
|
38
38
|
throw new CodexSecurityError("--github-state only filters repository lists; omit it when selecting exact GHSA IDs.");
|
|
39
|
-
const host = options.githubHost
|
|
40
|
-
(environment["GH_HOST"]?.trim() || "github.com");
|
|
41
|
-
if (!host)
|
|
42
|
-
throw new CodexSecurityError("GitHub host must not be empty.");
|
|
39
|
+
const host = githubImportHost(options.githubHost, environment);
|
|
43
40
|
try {
|
|
44
|
-
const github = dependencies
|
|
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
|
-
});
|
|
41
|
+
const github = await githubImportClient(host, options, dependencies, environment);
|
|
52
42
|
const advisories = [];
|
|
53
43
|
if (ids.length > 0) {
|
|
54
44
|
for (const id of ids) {
|
|
@@ -97,21 +87,11 @@ export async function importGitHubAdvisories(options, dependencies = {}) {
|
|
|
97
87
|
}));
|
|
98
88
|
}
|
|
99
89
|
catch (error) {
|
|
100
|
-
options.signal
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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)}`);
|
|
90
|
+
throw githubImportError(error, options.signal, {
|
|
91
|
+
operation: "security advisory",
|
|
92
|
+
denied: "GitHub denied security advisory access. Check repository advisory permissions and API rate limits.",
|
|
93
|
+
notFound: "GitHub repository or security advisory was not found or is not accessible.",
|
|
94
|
+
});
|
|
115
95
|
}
|
|
116
96
|
}
|
|
117
97
|
async function fetchRepositoryAdvisory(github, owner, repo, id, signal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-advisories.js","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,OAAO;IACP,QAAQ;IACR,QAAQ;CACA,CAAC;AAsCX,8EAA8E;AAC9E,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AoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,yDAAyD,EACzD;QACE,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,MAAe,EACf,EAAU,EACV,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE;QACjE,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Octokit } from \"@octokit/core\";\nimport {\n CANONICAL_GHSA_ID,\n githubRepositoryParts,\n} from \"./github-identifiers.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\nimport { createAuthenticatedGitHub } from \"./github.js\";\n\nexport const GITHUB_ADVISORY_STATES = [\n \"published\",\n \"draft\",\n \"triage\",\n \"closed\",\n] as const;\n\nexport interface GitHubAdvisoryImportOptions {\n /** Source repository, or the selected target for explicit global advisory IDs. */\n repository: string;\n /** Exact GHSA IDs. Required for the global advisory API. */\n advisoryIds?: readonly string[];\n /** Repository advisories by default; global never enumerates the database. */\n source?: \"repository\" | \"global\";\n /** Repository list state (default: published). Exact IDs ignore state. */\n state?: (typeof GITHUB_ADVISORY_STATES)[number];\n /** Defaults to GH_HOST or github.com. */\n githubHost?: string;\n /** Omit to use the authenticated GitHub CLI. */\n githubToken?: string;\n signal?: AbortSignal;\n}\n\ntype RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;\ntype GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;\n\nexport interface ImportedGitHubAdvisory {\n source: \"github-security-advisory\";\n selection: \"repository\" | \"global\";\n repository: string;\n githubHost: string;\n ghsaId: string;\n url: string;\n /** Upstream disclosure, not proof that the selected repository is affected. */\n advisory: RepositoryAdvisory | GlobalAdvisory;\n}\n\ninterface GitHubAdvisoryImportDependencies {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;\n}\n\n/** Read repository disclosures or explicitly selected public GHSA records. */\nexport async function importGitHubAdvisories(\n options: GitHubAdvisoryImportOptions,\n dependencies: GitHubAdvisoryImportDependencies = {},\n): Promise<ImportedGitHubAdvisory[]> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n requireExternalImports(environment);\n const repository = options.repository.trim();\n const parts = githubRepositoryParts(repository);\n if (!parts)\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n const [owner, repo] = parts;\n const ids = [\n ...new Set(\n (options.advisoryIds ?? []).map((id) =>\n id\n .trim()\n .toLowerCase()\n .replace(/^ghsa-/u, \"GHSA-\"),\n ),\n ),\n ];\n if (ids.some((id) => !CANONICAL_GHSA_ID.test(id)))\n throw new CodexSecurityError(\n \"GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.\",\n );\n const source = options.source ?? \"repository\";\n const state = options.state ?? \"published\";\n if (source !== \"repository\" && source !== \"global\")\n throw new CodexSecurityError(\n \"GitHub advisory source must be repository or global.\",\n );\n if (!GITHUB_ADVISORY_STATES.includes(state))\n throw new CodexSecurityError(\"GitHub advisory state is invalid.\");\n if (source === \"global\" && ids.length === 0)\n throw new CodexSecurityError(\n \"Select explicit GHSA IDs for global advisories; database-wide import is not supported.\",\n );\n if (ids.length > 0 && state !== \"published\")\n throw new CodexSecurityError(\n \"--github-state only filters repository lists; omit it when selecting exact GHSA IDs.\",\n );\n const host =\n options.githubHost?.trim() ??\n (environment[\"GH_HOST\"]?.trim() || \"github.com\");\n if (!host) throw new CodexSecurityError(\"GitHub host must not be empty.\");\n\n try {\n const github = dependencies.createGitHub\n ? await dependencies.createGitHub(host, options.signal)\n : await createAuthenticatedGitHub(host, {\n token: options.githubToken,\n environment,\n currentDirectory: dependencies.currentDirectory,\n signal: options.signal,\n });\n const advisories: (RepositoryAdvisory | GlobalAdvisory)[] = [];\n if (ids.length > 0) {\n for (const id of ids) {\n options.signal?.throwIfAborted();\n advisories.push(\n source === \"global\"\n ? await fetchGlobalAdvisory(github, id, options.signal)\n : await fetchRepositoryAdvisory(\n github,\n owner,\n repo,\n id,\n options.signal,\n ),\n );\n }\n } else {\n let after: string | undefined;\n const cursors = new Set<string>();\n do {\n options.signal?.throwIfAborted();\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories\",\n {\n owner,\n repo,\n state,\n per_page: 100,\n after,\n request: { signal: options.signal, redirect: \"error\" },\n },\n );\n advisories.push(...response.data);\n const next = response.headers.link\n ?.split(\",\")\n .find((link) => /;\\s*rel=\"next\"/u.test(link));\n const nextUrl = next?.match(/<([^>]+)>/u)?.[1];\n // Keep requests on the authenticated route; only carry over the cursor.\n after = nextUrl\n ? (new URL(nextUrl).searchParams.get(\"after\") ?? undefined)\n : undefined;\n if (next && (!after || cursors.has(after)))\n throw new CodexSecurityError(\n \"GitHub returned invalid advisory pagination.\",\n );\n if (after) cursors.add(after);\n } while (after !== undefined);\n }\n return advisories.map((advisory) => ({\n source: \"github-security-advisory\",\n selection: source,\n repository,\n githubHost: host,\n ghsaId: advisory.ghsa_id,\n url: advisory.html_url,\n advisory,\n }));\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error instanceof CodexSecurityError) throw error;\n const status =\n typeof error === \"object\" && error !== null && \"status\" in error\n ? error.status\n : undefined;\n if (status === 401)\n throw new CodexSecurityError(\"GitHub authentication failed.\");\n if (status === 403)\n throw new CodexSecurityError(\n \"GitHub denied security advisory access. Check repository advisory permissions and API rate limits.\",\n );\n if (status === 404)\n throw new CodexSecurityError(\n \"GitHub repository or security advisory was not found or is not accessible.\",\n );\n if (status === 429)\n throw new CodexSecurityError(\n \"GitHub request was rate limited. Wait and retry.\",\n );\n throw new CodexSecurityError(\n `GitHub security advisory request failed${typeof status === \"number\" ? ` (HTTP ${status})` : \"\"}: ${errorMessage(error)}`,\n );\n }\n}\n\nasync function fetchRepositoryAdvisory(\n github: Octokit,\n owner: string,\n repo: string,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}\",\n {\n owner,\n repo,\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n\nasync function fetchGlobalAdvisory(\n github: Octokit,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\"GET /advisories/{ghsa_id}\", {\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n });\n return response.data;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"github-advisories.js","sourceRoot":"","sources":["../src/github-advisories.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAGlB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,OAAO;IACP,QAAQ;IACR,QAAQ;CACA,CAAC;AA2BX,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAoC,EACpC,YAAY,GAA6B,EAAE;IAE3C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAC5D,sBAAsB,CAAC,WAAW,CA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IAAY,EACZ,EAAU,EACV,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,yDAAyD,EACzD;QACE,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,MAAe,EACf,EAAU,EACV,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE;QACjE,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Octokit } from \"@octokit/core\";\nimport {\n CANONICAL_GHSA_ID,\n githubRepositoryParts,\n} from \"./github-identifiers.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\nimport {\n githubImportHost,\n githubImportClient,\n githubImportError,\n type GitHubImportConnectionOptions,\n type GitHubImportDependencies,\n} from \"./github.js\";\n\nexport const GITHUB_ADVISORY_STATES = [\n \"published\",\n \"draft\",\n \"triage\",\n \"closed\",\n] as const;\n\nexport interface GitHubAdvisoryImportOptions extends GitHubImportConnectionOptions {\n /** Source repository, or the selected target for explicit global advisory IDs. */\n repository: string;\n /** Exact GHSA IDs. Required for the global advisory API. */\n advisoryIds?: readonly string[];\n /** Repository advisories by default; global never enumerates the database. */\n source?: \"repository\" | \"global\";\n /** Repository list state (default: published). Exact IDs ignore state. */\n state?: (typeof GITHUB_ADVISORY_STATES)[number];\n}\n\ntype RepositoryAdvisory = Awaited<ReturnType<typeof fetchRepositoryAdvisory>>;\ntype GlobalAdvisory = Awaited<ReturnType<typeof fetchGlobalAdvisory>>;\n\nexport interface ImportedGitHubAdvisory {\n source: \"github-security-advisory\";\n selection: \"repository\" | \"global\";\n repository: string;\n githubHost: string;\n ghsaId: string;\n url: string;\n /** Upstream disclosure, not proof that the selected repository is affected. */\n advisory: RepositoryAdvisory | GlobalAdvisory;\n}\n\n/** Read repository disclosures or explicitly selected public GHSA records. */\nexport async function importGitHubAdvisories(\n options: GitHubAdvisoryImportOptions,\n dependencies: GitHubImportDependencies = {},\n): Promise<ImportedGitHubAdvisory[]> {\n options.signal?.throwIfAborted();\n const environment = dependencies.environment ?? process.env;\n requireExternalImports(environment);\n const repository = options.repository.trim();\n const parts = githubRepositoryParts(repository);\n if (!parts)\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n const [owner, repo] = parts;\n const ids = [\n ...new Set(\n (options.advisoryIds ?? []).map((id) =>\n id\n .trim()\n .toLowerCase()\n .replace(/^ghsa-/u, \"GHSA-\"),\n ),\n ),\n ];\n if (ids.some((id) => !CANONICAL_GHSA_ID.test(id)))\n throw new CodexSecurityError(\n \"GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form.\",\n );\n const source = options.source ?? \"repository\";\n const state = options.state ?? \"published\";\n if (source !== \"repository\" && source !== \"global\")\n throw new CodexSecurityError(\n \"GitHub advisory source must be repository or global.\",\n );\n if (!GITHUB_ADVISORY_STATES.includes(state))\n throw new CodexSecurityError(\"GitHub advisory state is invalid.\");\n if (source === \"global\" && ids.length === 0)\n throw new CodexSecurityError(\n \"Select explicit GHSA IDs for global advisories; database-wide import is not supported.\",\n );\n if (ids.length > 0 && state !== \"published\")\n throw new CodexSecurityError(\n \"--github-state only filters repository lists; omit it when selecting exact GHSA IDs.\",\n );\n const host = githubImportHost(options.githubHost, environment);\n\n try {\n const github = await githubImportClient(\n host,\n options,\n dependencies,\n environment,\n );\n const advisories: (RepositoryAdvisory | GlobalAdvisory)[] = [];\n if (ids.length > 0) {\n for (const id of ids) {\n options.signal?.throwIfAborted();\n advisories.push(\n source === \"global\"\n ? await fetchGlobalAdvisory(github, id, options.signal)\n : await fetchRepositoryAdvisory(\n github,\n owner,\n repo,\n id,\n options.signal,\n ),\n );\n }\n } else {\n let after: string | undefined;\n const cursors = new Set<string>();\n do {\n options.signal?.throwIfAborted();\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories\",\n {\n owner,\n repo,\n state,\n per_page: 100,\n after,\n request: { signal: options.signal, redirect: \"error\" },\n },\n );\n advisories.push(...response.data);\n const next = response.headers.link\n ?.split(\",\")\n .find((link) => /;\\s*rel=\"next\"/u.test(link));\n const nextUrl = next?.match(/<([^>]+)>/u)?.[1];\n // Keep requests on the authenticated route; only carry over the cursor.\n after = nextUrl\n ? (new URL(nextUrl).searchParams.get(\"after\") ?? undefined)\n : undefined;\n if (next && (!after || cursors.has(after)))\n throw new CodexSecurityError(\n \"GitHub returned invalid advisory pagination.\",\n );\n if (after) cursors.add(after);\n } while (after !== undefined);\n }\n return advisories.map((advisory) => ({\n source: \"github-security-advisory\",\n selection: source,\n repository,\n githubHost: host,\n ghsaId: advisory.ghsa_id,\n url: advisory.html_url,\n advisory,\n }));\n } catch (error) {\n throw githubImportError(error, options.signal, {\n operation: \"security advisory\",\n denied:\n \"GitHub denied security advisory access. Check repository advisory permissions and API rate limits.\",\n notFound:\n \"GitHub repository or security advisory was not found or is not accessible.\",\n });\n }\n}\n\nasync function fetchRepositoryAdvisory(\n github: Octokit,\n owner: string,\n repo: string,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}\",\n {\n owner,\n repo,\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n\nasync function fetchGlobalAdvisory(\n github: Octokit,\n id: string,\n signal?: AbortSignal,\n) {\n const response = await github.request(\"GET /advisories/{ghsa_id}\", {\n ghsa_id: id,\n request: { signal, redirect: \"error\" },\n });\n return response.data;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-dependabot-findings.d.ts","sourceRoot":"","sources":["../src/github-dependabot-findings.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"github-dependabot-findings.d.ts","sourceRoot":"","sources":["../src/github-dependabot-findings.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAWhF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAalC;AAkHD,wBAAgB,oBAAoB,CAAC,EACnC,iBAAiB,EAAE,EAAE,EACrB,QAAQ,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,GAC3C,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CA8BtC;AAmID,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAgClB"}
|