@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":"snyk-findings.js","sourceRoot":"","sources":["../src/snyk-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,kCAAkC,EAClC,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,wBAAwB,EACxB,QAAQ,EACR,OAAO,EACP,IAAI,GACL,MAAM,qBAAqB,CAAC;AAE7B,SAAS,YAAY,CAAC,KAAc,EAAE,OAAsB;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,kBAAkB,CAAC;S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CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,MAAM,GAAyB,OAAO;IAEtC,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IAChD,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,yBAAyB;QAClD,OAAO,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,QAAQ,CAAC,SAAS,CAAC,KAAK,OAAO;QACjC,OAAO,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC9C,OAAO,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n hasSarifExternalPropertyReferences,\n normalizeRecords,\n readScannerJson,\n record,\n requiredText,\n sarifRunContextForResult,\n stableId,\n strings,\n text,\n} from \"./scanner-import.js\";\n\nfunction snykIdentity(value: unknown, project: string | null): string {\n const result = record(value, \"SARIF result\");\n const id = requiredText(result[\"ruleId\"], \"Snyk advisory ruleId\");\n const paths = array(result[\"locations\"] ?? [], \"Result locations\")\n .map((value) => {\n const physical = record(\n record(value, \"Location\")[\"physicalLocation\"] ?? {},\n \"Physical location\",\n );\n const artifact = record(\n physical[\"artifactLocation\"] ?? {},\n \"Artifact location\",\n );\n if (\n artifact[\"index\"] !== undefined ||\n artifact[\"uriBaseId\"] !== undefined\n )\n throw new Error(\n \"Snyk SARIF artifact references are unsupported; use direct manifest URIs from the Snyk Open Source formatter.\",\n );\n return text(artifact[\"uri\"]);\n })\n .filter((path): path is string => path !== null);\n const fields: unknown[] = [id, [...new Set(paths)].sort()];\n if (project !== null) fields.push(project);\n return stableId(\"snyk-sarif\", fields);\n}\n\nfunction snykSarifProject(run: Record<string, unknown>): string | null {\n const details = run[\"automationDetails\"];\n const id = isRecord(details) ? text(details[\"id\"]) : null;\n // The formatter appends a run index and export timestamp after the project name.\n return /^Snyk\\/Open Source\\/(.+)\\/\\d+\\/[^/]+$/su.exec(id ?? \"\")?.[1] ?? null;\n}\n\nfunction pluginIdentity(value: unknown): string {\n const finding = record(value, \"Snyk plugin finding\");\n const id = record(finding[\"id\"], \"Snyk plugin identity\");\n return stableId(\"snyk-plugin\", [\n requiredText(id[\"kind\"], \"Identity kind\"),\n requiredText(id[\"value\"], \"Finding identity\"),\n ]);\n}\n\n/** Import the official Snyk Codex plugin's documented local SCA bundle. */\nexport function normalizeSnykFindingsExport(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Snyk plugin export\");\n if (\n document[\"format\"] !== \"snyk-findings-export/v1\" ||\n document[\"provider\"] !== \"snyk\"\n )\n throw new Error(\"Expected a snyk-findings-export/v1 bundle from Snyk.\");\n const collection = record(document[\"collection\"], \"Snyk collection\");\n const sourceTarget = record(collection[\"target\"], \"Snyk target\");\n const { findings: _findings, ...context } = document;\n return normalizeRecords(\n array(document[\"findings\"], \"Snyk findings\"),\n (value, sourceFindingId) => {\n const finding = record(value, \"Snyk plugin finding\");\n const observation = record(finding[\"observation\"], \"Snyk observation\");\n if (\n finding[\"originatingScanner\"] !== \"snyk-open-source\" ||\n finding[\"category\"] !== \"dependency_vulnerability\" ||\n observation[\"scan\"] !== \"sca\"\n )\n throw new Error(\n \"Only Snyk Open Source SCA vulnerability findings are supported from plugin bundles.\",\n );\n record(finding[\"nativeRecord\"], \"Snyk native MCP record\");\n const asset = record(finding[\"asset\"], \"Snyk asset\");\n const pkg = record(asset[\"package\"], \"Snyk package\");\n const rule = record(finding[\"rule\"], \"Snyk rule\");\n const aliases = record(rule[\"aliases\"] ?? {}, \"Snyk rule aliases\");\n const remediation = record(\n finding[\"remediation\"] ?? {},\n \"Snyk remediation\",\n );\n const severity = text(\n record(finding[\"severity\"], \"Snyk severity\")[\"value\"],\n )?.toLowerCase();\n const revision = text(sourceTarget[\"revision\"]);\n return {\n source_finding_id: sourceFindingId,\n evidence: validateExternalEvidence(\n {\n title: requiredText(finding[\"title\"], \"Snyk title\"),\n description: text(\n record(finding[\"description\"] ?? {}, \"Snyk description\")[\"text\"],\n ),\n severity: [\"critical\", \"high\", \"medium\", \"low\"].includes(\n severity ?? \"\",\n )\n ? severity\n : \"unknown\",\n advisory_ids: [\n ...new Set([\n requiredText(rule[\"id\"], \"Snyk advisory ID\"),\n ...strings(aliases[\"cve\"]),\n ]),\n ],\n packages: [\n {\n name: requiredText(pkg[\"name\"], \"Snyk package name\"),\n ecosystem: text(pkg[\"ecosystem\"]),\n installed_version: text(pkg[\"version\"]),\n // Plugin v1 manifests are target-relative, without a Git-root offset.\n manifest_path: null,\n fixed_versions: strings(remediation[\"fixedIn\"]),\n },\n ],\n locations: [],\n code_revision:\n sourceTarget[\"workingTreeDirty\"] === false &&\n revision !== \"unknown\"\n ? revision\n : null,\n source_data: structuredClone({ ...context, finding }),\n },\n target,\n ),\n };\n },\n pluginIdentity,\n target,\n );\n}\n\nfunction normalizeGitRepositoryUrl(\n repository: string,\n cloudRepositoryUrl?: string,\n): string {\n // Cloud's selected catalog repository supplies connected GitHub host context;\n // imported evidence alone cannot establish an Enterprise host's SSH aliases.\n const destination = cloudRepositoryUrl\n ? new URL(cloudRepositoryUrl)\n : undefined;\n const connectedHost =\n destination?.protocol === \"https:\"\n ? destination.hostname.toLowerCase()\n : undefined;\n const connectedTenant = /^([^.]+)\\.ghe\\.com$/u.exec(connectedHost ?? \"\")?.[1];\n const isGitHubSshUser = (username: string, hostname: string) =>\n (username === \"git\" &&\n (hostname === \"github.com\" || hostname === connectedHost)) ||\n (username === connectedTenant && hostname === connectedHost);\n const scp = /^([^@/:]+)@([^/:]+):(.+)$/u.exec(repository);\n if (scp && isGitHubSshUser(scp[1]!, scp[2]!.toLowerCase()))\n return `https://${scp[2]}/${scp[3]}`;\n // Compare Git's literal SSH userinfo before URL strips tabs or newlines.\n const ssh = /^ssh:\\/\\/([^/]+)@/u.exec(repository);\n if (ssh) {\n // Git retains these bytes, but URL parsing would erase them from the alias.\n if (/[\\t\\r\\n]/u.test(repository)) return repository;\n const url = new URL(repository);\n const hostname = url.hostname.toLowerCase();\n const githubSsh =\n isGitHubSshUser(ssh[1]!, hostname) &&\n (url.port === \"\" || url.port === \"22\");\n const githubSshOverHttps =\n ssh[1] === \"git\" && hostname === \"ssh.github.com\" && url.port === \"443\";\n if (githubSshOverHttps) return `https://github.com${url.pathname}`;\n if (githubSsh) return `https://${hostname}${url.pathname}`;\n }\n return repository;\n}\n\n/** @internal Repository claims retained in original Snyk evidence. */\nexport function snykRepositoryUrls(\n sourceData: unknown,\n {\n normalizeGitRemote = true,\n cloudRepositoryUrl,\n }: {\n normalizeGitRemote?: boolean;\n /** The selected destination from the authenticated Cloud repository catalog. */\n cloudRepositoryUrl?: string;\n } = {},\n): string[] {\n if (\n !sourceData ||\n typeof sourceData !== \"object\" ||\n Array.isArray(sourceData)\n )\n return [];\n const source = sourceData as Record<string, unknown>;\n if (source[\"format\"] === \"snyk-findings-export/v1\") {\n const collection = record(source[\"collection\"], \"Snyk collection\");\n const target = record(collection[\"target\"], \"Snyk target\");\n const repository = text(target[\"repository\"]);\n if (repository === null || repository === \"unknown\") return [];\n return [\n normalizeGitRemote\n ? normalizeGitRepositoryUrl(repository, cloudRepositoryUrl)\n : repository,\n ];\n }\n // Generic normalized evidence may use these field names for opaque metadata.\n const document = source[\"document\"];\n const driver = source[\"driver\"];\n if (\n !isRecord(document) ||\n document[\"version\"] !== \"2.1.0\" ||\n !isRecord(driver) ||\n driver[\"name\"] !== \"Snyk Open Source\"\n )\n return [];\n const run = source[\"run\"];\n if (run == null) return [];\n return array(\n record(run, \"Snyk run context\")[\"versionControlProvenance\"] ?? [],\n \"Snyk version control provenance\",\n ).map((entry) => {\n const repository = requiredText(\n record(entry, \"Snyk repository provenance\")[\"repositoryUri\"],\n \"Snyk repository URI\",\n );\n return normalizeGitRemote\n ? normalizeGitRepositoryUrl(repository, cloudRepositoryUrl)\n : repository;\n });\n}\n\n/** Snyk Open Source's formatter groups all dependency paths for an advisory in a project. */\nexport function normalizeSnykSarif(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Snyk SARIF\");\n if (document[\"version\"] !== \"2.1.0\")\n throw new Error(\"Expected Snyk Open Source SARIF 2.1.0.\");\n const entries = array(document[\"runs\"], \"SARIF runs\").flatMap((value) => {\n const run = record(value, \"SARIF run\");\n const driver = record(\n record(run[\"tool\"], \"SARIF tool\")[\"driver\"],\n \"SARIF driver\",\n );\n if (driver[\"name\"] !== \"Snyk Open Source\")\n throw new Error(\n \"Only Snyk Open Source SARIF is supported; Code, Container, and IaC need separate mappings.\",\n );\n if (\n hasSarifExternalPropertyReferences(run[\"externalPropertyFileReferences\"])\n )\n throw new Error(\n \"External SARIF property files are unsupported; use a self-contained report.\",\n );\n const rules = array(driver[\"rules\"], \"SARIF rules\").map((rule) =>\n record(rule, \"SARIF rule\"),\n );\n const rulesById = new Map<\n unknown,\n { rule: Record<string, unknown>; index: number } | null\n >();\n rules.forEach((rule, index) => {\n const id = rule[\"id\"];\n rulesById.set(id, rulesById.has(id) ? null : { rule, index });\n });\n const project = snykSarifProject(run);\n const { results: _results, tool: _tool, ...runContext } = run;\n const { rules: _rules, ...driverContext } = driver;\n const { driver: _driver, ...toolContext } = record(\n run[\"tool\"],\n \"SARIF tool\",\n );\n runContext[\"tool\"] = toolContext;\n const { runs: _runs, ...documentContext } = document;\n return array(run[\"results\"], \"SARIF results\").map((result) => ({\n result,\n rulesById,\n project,\n runContext,\n driverContext,\n documentContext,\n }));\n });\n return normalizeRecords(\n entries,\n (\n { result: value, rulesById, runContext, driverContext, documentContext },\n sourceFindingId,\n ) => {\n const result = record(value, \"SARIF result\");\n const id = requiredText(result[\"ruleId\"], \"Snyk advisory ruleId\");\n const match = rulesById.get(id);\n if (!match)\n throw new Error(\"Result must reference exactly one rule in its run.\");\n const { rule, index } = match;\n if (result[\"ruleIndex\"] !== undefined && result[\"ruleIndex\"] !== index)\n throw new Error(\"Result ruleIndex and ruleId disagree.\");\n if (result[\"rule\"] !== undefined) {\n const ref = record(result[\"rule\"], \"Rule reference\");\n if (\n ref[\"toolComponent\"] !== undefined ||\n (ref[\"id\"] !== undefined && ref[\"id\"] !== id) ||\n (ref[\"index\"] !== undefined && ref[\"index\"] !== index) ||\n (ref[\"guid\"] !== undefined && ref[\"guid\"] !== rule[\"guid\"])\n )\n throw new Error(\n \"Result uses an inconsistent or external rule reference.\",\n );\n }\n const help = requiredText(\n record(rule[\"help\"], \"Rule help\")[\"markdown\"],\n \"Rule help markdown\",\n );\n const manager = /^\\* Package Manager: (.+)$/mu.exec(help)?.[1] ?? null;\n if (!manager || !/^\\* Vulnerable module: .+$/mu.test(help))\n throw new Error(\n \"Expected the Snyk Open Source vulnerability profile; license findings are unsupported.\",\n );\n const title = requiredText(\n record(rule[\"shortDescription\"], \"Rule shortDescription\")[\"text\"],\n \"Rule title\",\n );\n const severity =\n /^(Critical|High|Medium|Low) severity - /u\n .exec(title)?.[1]\n ?.toLowerCase() ?? \"unknown\";\n const message = requiredText(\n record(result[\"message\"], \"Result message\")[\"text\"],\n \"Result message text\",\n );\n const locations = array(\n result[\"locations\"] ?? [],\n \"Result locations\",\n ).map((v) => record(v, \"Location\"));\n const packages: {\n name: string;\n ecosystem: string;\n installed_version: string | null;\n manifest_path: string | null;\n fixed_versions: string[];\n }[] = [];\n for (const location of locations) {\n for (const logical of array(\n location[\"logicalLocations\"] ?? [],\n \"Logical locations\",\n )) {\n const coordinate = text(\n record(logical, \"Logical location\")[\"fullyQualifiedName\"],\n );\n if (!coordinate) continue;\n const split = coordinate.lastIndexOf(\"@\");\n if (split <= 0) continue;\n packages.push({\n name: coordinate.slice(0, split),\n ecosystem: manager,\n installed_version: coordinate.slice(split + 1) || null,\n manifest_path: null,\n fixed_versions: [],\n });\n }\n }\n const description = [message, help].join(\"\\n\\n\");\n // Use the project, advisory group, and literal manifest set within the caller's namespace.\n return {\n source_finding_id: sourceFindingId,\n evidence: validateExternalEvidence(\n {\n title,\n description,\n severity,\n advisory_ids: [\n ...new Set([\n id,\n ...(text(\n record(rule[\"fullDescription\"] ?? {}, \"Full description\")[\n \"text\"\n ],\n )?.match(/\\bCVE-\\d{4}-\\d+\\b/gu) ?? []),\n ]),\n ],\n packages,\n // Snyk emits target-relative paths without a Git-root offset and may\n // synthesize startLine=1. Keep both only in the original evidence.\n locations: [],\n source_data: structuredClone({\n document: documentContext,\n run: sarifRunContextForResult(\n runContext,\n result,\n rule,\n driverContext,\n documentContext,\n ),\n driver: driverContext,\n rule,\n result,\n }),\n },\n target,\n ),\n };\n },\n ({ result, project }) => snykIdentity(result, project),\n target,\n );\n}\n\n/** Import native `snyk test --json` Open Source vulnerability occurrences. */\nexport function normalizeSnykJson(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const projects = Array.isArray(input) ? input : [input];\n const entries = projects.flatMap((value) => {\n const project = record(value, \"Snyk Open Source project\");\n if (project[\"error\"])\n throw new Error(`Snyk scan failed: ${String(project[\"error\"])}`);\n if (project[\"docker\"] || project[\"applications\"])\n throw new Error(\n \"Snyk Container JSON is unsupported; use Open Source SCA results.\",\n );\n if (typeof project[\"ok\"] !== \"boolean\")\n throw new Error(\"Expected a completed Snyk Open Source test result.\");\n const manager = requiredText(\n project[\"packageManager\"],\n \"Snyk package manager\",\n );\n const manifest =\n text(project[\"displayTargetFile\"]) ?? text(project[\"targetFile\"]);\n const { vulnerabilities, ...context } = project;\n return array(vulnerabilities, \"Snyk vulnerabilities\").map((value) => ({\n value,\n context,\n manager,\n manifest,\n }));\n });\n return normalizeRecords(\n entries,\n ({ value, context, manager }, sourceFindingId) => {\n const vulnerability = record(value, \"Snyk vulnerability\");\n if (vulnerability[\"type\"] === \"license\")\n throw new Error(\n \"Snyk license findings are unsupported; only Open Source SCA vulnerabilities are imported.\",\n );\n const identifiers = record(\n vulnerability[\"identifiers\"] ?? {},\n \"Snyk identifiers\",\n );\n const severity = text(vulnerability[\"severity\"])?.toLowerCase();\n return {\n source_finding_id: sourceFindingId,\n evidence: validateExternalEvidence(\n {\n title: requiredText(\n vulnerability[\"title\"],\n \"Snyk vulnerability title\",\n ),\n description: text(vulnerability[\"description\"]),\n severity: [\"critical\", \"high\", \"medium\", \"low\"].includes(\n severity ?? \"\",\n )\n ? severity\n : \"unknown\",\n advisory_ids: [\n ...new Set([\n requiredText(vulnerability[\"id\"], \"Snyk advisory ID\"),\n ...strings(identifiers[\"CVE\"]),\n ]),\n ],\n packages: [\n {\n name: requiredText(\n vulnerability[\"name\"] ?? vulnerability[\"packageName\"],\n \"Snyk package name\",\n ),\n ecosystem: manager,\n installed_version: text(vulnerability[\"version\"]),\n // Native test paths are scan-target-relative, without a Git-root offset.\n manifest_path: null,\n fixed_versions: strings(vulnerability[\"fixedIn\"]),\n },\n ],\n locations: [],\n source_data: structuredClone({ project: context, vulnerability }),\n },\n target,\n ),\n };\n },\n ({ value, manager, manifest }) => {\n const vulnerability = record(value, \"Snyk vulnerability\");\n return stableId(\"snyk-json\", [\n manager,\n manifest,\n requiredText(vulnerability[\"id\"], \"Snyk advisory ID\"),\n requiredText(\n vulnerability[\"name\"] ?? vulnerability[\"packageName\"],\n \"Snyk package name\",\n ),\n text(vulnerability[\"version\"]),\n array(vulnerability[\"from\"] ?? [], \"Snyk dependency path\").map((item) =>\n requiredText(item, \"Snyk dependency\"),\n ),\n ]);\n },\n target,\n );\n}\n\nexport async function readSnykFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n const input = await readScannerJson(path);\n if (Array.isArray(input)) return normalizeSnykJson(input, target);\n const document = record(input, \"Snyk findings\");\n if (document[\"format\"] === \"snyk-findings-export/v1\")\n return normalizeSnykFindingsExport(document, target);\n if (document[\"version\"] === \"2.1.0\")\n return normalizeSnykSarif(document, target);\n return normalizeSnykJson(document, target);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snyk-findings.js","sourceRoot":"","sources":["../src/snyk-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,kCAAkC,EAClC,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,uBAAuB,EACvB,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,SAAS,YAAY,CAAC,KAAc,EAAE,OAAsB;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,kBAAkB,CAAC;SAC/D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,QAAQ,GAAG,MAAM,CACrB,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE,EACnD,mBAAmB,CACpB,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,CACrB,QAAQ,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAClC,mBAAmB,CACpB,CAAC;QACF,IACE,QAAQ,CAAC,OAAO,CAAC,KAAK,SAAS;YAC/B,QAAQ,CAAC,WAAW,CAAC,K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E,kBAAkB,CAAC;YACrD,YAAY,CACV,aAAa,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,EACrD,mBAAmB,CACpB;YACD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;YAC9B,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,sBAAsB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtE,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CACtC;SACF,CAAC,CAAC;IACL,CAAC,EACD,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,MAAM,GAAyB,OAAO;IAEtC,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IAChD,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,yBAAyB;QAClD,OAAO,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,QAAQ,CAAC,SAAS,CAAC,KAAK,OAAO;QACjC,OAAO,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC9C,OAAO,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n hasSarifExternalPropertyReferences,\n indexSarifRules,\n normalizeRecords,\n readScannerJson,\n record,\n requiredText,\n sarifRunContextSelector,\n stableId,\n strings,\n text,\n validateSarifRuleReference,\n} from \"./scanner-import.js\";\n\nfunction snykIdentity(value: unknown, project: string | null): string {\n const result = record(value, \"SARIF result\");\n const id = requiredText(result[\"ruleId\"], \"Snyk advisory ruleId\");\n const paths = array(result[\"locations\"] ?? [], \"Result locations\")\n .map((value) => {\n const physical = record(\n record(value, \"Location\")[\"physicalLocation\"] ?? {},\n \"Physical location\",\n );\n const artifact = record(\n physical[\"artifactLocation\"] ?? {},\n \"Artifact location\",\n );\n if (\n artifact[\"index\"] !== undefined ||\n artifact[\"uriBaseId\"] !== undefined\n )\n throw new Error(\n \"Snyk SARIF artifact references are unsupported; use direct manifest URIs from the Snyk Open Source formatter.\",\n );\n return text(artifact[\"uri\"]);\n })\n .filter((path): path is string => path !== null);\n const fields: unknown[] = [id, [...new Set(paths)].sort()];\n if (project !== null) fields.push(project);\n return stableId(\"snyk-sarif\", fields);\n}\n\nfunction snykSarifProject(run: Record<string, unknown>): string | null {\n const details = run[\"automationDetails\"];\n const id = isRecord(details) ? text(details[\"id\"]) : null;\n // The formatter appends a run index and export timestamp after the project name.\n return /^Snyk\\/Open Source\\/(.+)\\/\\d+\\/[^/]+$/su.exec(id ?? \"\")?.[1] ?? null;\n}\n\nfunction pluginIdentity(value: unknown): string {\n const finding = record(value, \"Snyk plugin finding\");\n const id = record(finding[\"id\"], \"Snyk plugin identity\");\n return stableId(\"snyk-plugin\", [\n requiredText(id[\"kind\"], \"Identity kind\"),\n requiredText(id[\"value\"], \"Finding identity\"),\n ]);\n}\n\n/** Import the official Snyk Codex plugin's documented local SCA bundle. */\nexport function normalizeSnykFindingsExport(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Snyk plugin export\");\n if (\n document[\"format\"] !== \"snyk-findings-export/v1\" ||\n document[\"provider\"] !== \"snyk\"\n )\n throw new Error(\"Expected a snyk-findings-export/v1 bundle from Snyk.\");\n const collection = record(document[\"collection\"], \"Snyk collection\");\n const sourceTarget = record(collection[\"target\"], \"Snyk target\");\n const { findings: _findings, ...context } = document;\n return normalizeRecords(\n array(document[\"findings\"], \"Snyk findings\"),\n (value) => {\n const finding = record(value, \"Snyk plugin finding\");\n const observation = record(finding[\"observation\"], \"Snyk observation\");\n if (\n finding[\"originatingScanner\"] !== \"snyk-open-source\" ||\n finding[\"category\"] !== \"dependency_vulnerability\" ||\n observation[\"scan\"] !== \"sca\"\n )\n throw new Error(\n \"Only Snyk Open Source SCA vulnerability findings are supported from plugin bundles.\",\n );\n record(finding[\"nativeRecord\"], \"Snyk native MCP record\");\n const asset = record(finding[\"asset\"], \"Snyk asset\");\n const pkg = record(asset[\"package\"], \"Snyk package\");\n const rule = record(finding[\"rule\"], \"Snyk rule\");\n const aliases = record(rule[\"aliases\"] ?? {}, \"Snyk rule aliases\");\n const remediation = record(\n finding[\"remediation\"] ?? {},\n \"Snyk remediation\",\n );\n const severity = text(\n record(finding[\"severity\"], \"Snyk severity\")[\"value\"],\n )?.toLowerCase();\n const revision = text(sourceTarget[\"revision\"]);\n return validateExternalEvidence(\n {\n title: requiredText(finding[\"title\"], \"Snyk title\"),\n description: text(\n record(finding[\"description\"] ?? {}, \"Snyk description\")[\"text\"],\n ),\n severity: [\"critical\", \"high\", \"medium\", \"low\"].includes(\n severity ?? \"\",\n )\n ? severity\n : \"unknown\",\n advisory_ids: [\n ...new Set([\n requiredText(rule[\"id\"], \"Snyk advisory ID\"),\n ...strings(aliases[\"cve\"]),\n ]),\n ],\n packages: [\n {\n name: requiredText(pkg[\"name\"], \"Snyk package name\"),\n ecosystem: text(pkg[\"ecosystem\"]),\n installed_version: text(pkg[\"version\"]),\n // Plugin v1 manifests are target-relative, without a Git-root offset.\n manifest_path: null,\n fixed_versions: strings(remediation[\"fixedIn\"]),\n },\n ],\n locations: [],\n code_revision:\n sourceTarget[\"workingTreeDirty\"] === false && revision !== \"unknown\"\n ? revision\n : null,\n source_data: structuredClone({ ...context, finding }),\n },\n target,\n );\n },\n pluginIdentity,\n target,\n );\n}\n\nfunction normalizeGitRepositoryUrl(\n repository: string,\n cloudRepositoryUrl?: string,\n): string {\n // Cloud's selected catalog repository supplies connected GitHub host context;\n // imported evidence alone cannot establish an Enterprise host's SSH aliases.\n const destination = cloudRepositoryUrl\n ? new URL(cloudRepositoryUrl)\n : undefined;\n const connectedHost =\n destination?.protocol === \"https:\"\n ? destination.hostname.toLowerCase()\n : undefined;\n const connectedTenant = /^([^.]+)\\.ghe\\.com$/u.exec(connectedHost ?? \"\")?.[1];\n const isGitHubSshUser = (username: string, hostname: string) =>\n (username === \"git\" &&\n (hostname === \"github.com\" || hostname === connectedHost)) ||\n (username === connectedTenant && hostname === connectedHost);\n const scp = /^([^@/:]+)@([^/:]+):(.+)$/u.exec(repository);\n if (scp && isGitHubSshUser(scp[1]!, scp[2]!.toLowerCase()))\n return `https://${scp[2]}/${scp[3]}`;\n // Compare Git's literal SSH userinfo before URL strips tabs or newlines.\n const ssh = /^ssh:\\/\\/([^/]+)@/u.exec(repository);\n if (ssh) {\n // Git retains these bytes, but URL parsing would erase them from the alias.\n if (/[\\t\\r\\n]/u.test(repository)) return repository;\n const url = new URL(repository);\n const hostname = url.hostname.toLowerCase();\n const githubSsh =\n isGitHubSshUser(ssh[1]!, hostname) &&\n (url.port === \"\" || url.port === \"22\");\n const githubSshOverHttps =\n ssh[1] === \"git\" && hostname === \"ssh.github.com\" && url.port === \"443\";\n if (githubSshOverHttps) return `https://github.com${url.pathname}`;\n if (githubSsh) return `https://${hostname}${url.pathname}`;\n }\n return repository;\n}\n\n/** @internal Repository claims retained in original Snyk evidence. */\nexport function snykRepositoryUrls(\n sourceData: unknown,\n {\n normalizeGitRemote = true,\n cloudRepositoryUrl,\n }: {\n normalizeGitRemote?: boolean;\n /** The selected destination from the authenticated Cloud repository catalog. */\n cloudRepositoryUrl?: string;\n } = {},\n): string[] {\n if (\n !sourceData ||\n typeof sourceData !== \"object\" ||\n Array.isArray(sourceData)\n )\n return [];\n const source = sourceData as Record<string, unknown>;\n if (source[\"format\"] === \"snyk-findings-export/v1\") {\n const collection = record(source[\"collection\"], \"Snyk collection\");\n const target = record(collection[\"target\"], \"Snyk target\");\n const repository = text(target[\"repository\"]);\n if (repository === null || repository === \"unknown\") return [];\n return [\n normalizeGitRemote\n ? normalizeGitRepositoryUrl(repository, cloudRepositoryUrl)\n : repository,\n ];\n }\n const project = source[\"project\"];\n if (\n isRecord(project) &&\n typeof project[\"ok\"] === \"boolean\" &&\n text(project[\"packageManager\"]) &&\n isRecord(source[\"vulnerability\"])\n ) {\n // A remote Snyk test puts its GitHub URL and optional ref in the same\n // path field that local scans use for a directory or npm package name.\n const repository = text(project[\"path\"])?.split(\"#\", 1)[0];\n if (\n repository &&\n /^https?:\\/\\/github\\.com(?::\\d+)?\\/[^/?#\\\\\\s]+\\/[^/?#\\\\\\s]+\\/?$/iu.test(\n repository,\n )\n )\n return [repository];\n }\n // Generic normalized evidence may use these field names for opaque metadata.\n const document = source[\"document\"];\n const driver = source[\"driver\"];\n if (\n !isRecord(document) ||\n document[\"version\"] !== \"2.1.0\" ||\n !isRecord(driver) ||\n driver[\"name\"] !== \"Snyk Open Source\"\n )\n return [];\n const run = source[\"run\"];\n if (run == null) return [];\n return array(\n record(run, \"Snyk run context\")[\"versionControlProvenance\"] ?? [],\n \"Snyk version control provenance\",\n ).map((entry) => {\n const repository = requiredText(\n record(entry, \"Snyk repository provenance\")[\"repositoryUri\"],\n \"Snyk repository URI\",\n );\n return normalizeGitRemote\n ? normalizeGitRepositoryUrl(repository, cloudRepositoryUrl)\n : repository;\n });\n}\n\n/** Snyk Open Source's formatter groups all dependency paths for an advisory in a project. */\nexport function normalizeSnykSarif(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Snyk SARIF\");\n if (document[\"version\"] !== \"2.1.0\")\n throw new Error(\"Expected Snyk Open Source SARIF 2.1.0.\");\n const entries = array(document[\"runs\"], \"SARIF runs\").flatMap((value) => {\n const run = record(value, \"SARIF run\");\n const driver = record(\n record(run[\"tool\"], \"SARIF tool\")[\"driver\"],\n \"SARIF driver\",\n );\n if (driver[\"name\"] !== \"Snyk Open Source\")\n throw new Error(\n \"Only Snyk Open Source SARIF is supported; Code, Container, and IaC need separate mappings.\",\n );\n if (\n hasSarifExternalPropertyReferences(run[\"externalPropertyFileReferences\"])\n )\n throw new Error(\n \"External SARIF property files are unsupported; use a self-contained report.\",\n );\n const rules = array(driver[\"rules\"], \"SARIF rules\").map((rule) =>\n record(rule, \"SARIF rule\"),\n );\n // SDK inputs can leave descriptor slots empty. Keep the original rule indexes.\n const rulesById = indexSarifRules(\n rules.entries().filter(([index]) => index in rules),\n );\n const project = snykSarifProject(run);\n const { results: _results, tool: _tool, ...runContext } = run;\n const { rules: _rules, ...driverContext } = driver;\n const { driver: _driver, ...toolContext } = record(\n run[\"tool\"],\n \"SARIF tool\",\n );\n runContext[\"tool\"] = toolContext;\n const { runs: _runs, ...documentContext } = document;\n const selectRunContext = sarifRunContextSelector(runContext);\n return array(run[\"results\"], \"SARIF results\").map((result) => ({\n result,\n rulesById,\n project,\n selectRunContext,\n driverContext,\n documentContext,\n }));\n });\n return normalizeRecords(\n entries,\n ({\n result: value,\n rulesById,\n selectRunContext,\n driverContext,\n documentContext,\n }) => {\n const result = record(value, \"SARIF result\");\n const id = requiredText(result[\"ruleId\"], \"Snyk advisory ruleId\");\n const match = rulesById.get(id);\n if (!match)\n throw new Error(\"Result must reference exactly one rule in its run.\");\n const { rule } = match;\n validateSarifRuleReference(result, id, match, \"Snyk\");\n const help = requiredText(\n record(rule[\"help\"], \"Rule help\")[\"markdown\"],\n \"Rule help markdown\",\n );\n const manager = /^\\* Package Manager: (.+)$/mu.exec(help)?.[1] ?? null;\n if (!manager || !/^\\* Vulnerable module: .+$/mu.test(help))\n throw new Error(\n \"Expected the Snyk Open Source vulnerability profile; license findings are unsupported.\",\n );\n const title = requiredText(\n record(rule[\"shortDescription\"], \"Rule shortDescription\")[\"text\"],\n \"Rule title\",\n );\n const severity =\n /^(Critical|High|Medium|Low) severity - /u\n .exec(title)?.[1]\n ?.toLowerCase() ?? \"unknown\";\n const message = requiredText(\n record(result[\"message\"], \"Result message\")[\"text\"],\n \"Result message text\",\n );\n const locations = array(\n result[\"locations\"] ?? [],\n \"Result locations\",\n ).map((v) => record(v, \"Location\"));\n const packages: {\n name: string;\n ecosystem: string;\n installed_version: string | null;\n manifest_path: string | null;\n fixed_versions: string[];\n }[] = [];\n for (const location of locations) {\n for (const logical of array(\n location[\"logicalLocations\"] ?? [],\n \"Logical locations\",\n )) {\n const coordinate = text(\n record(logical, \"Logical location\")[\"fullyQualifiedName\"],\n );\n if (!coordinate) continue;\n const split = coordinate.lastIndexOf(\"@\");\n if (split <= 0) continue;\n packages.push({\n name: coordinate.slice(0, split),\n ecosystem: manager,\n installed_version: coordinate.slice(split + 1) || null,\n manifest_path: null,\n fixed_versions: [],\n });\n }\n }\n const description = [message, help].join(\"\\n\\n\");\n // Use the project, advisory group, and literal manifest set within the caller's namespace.\n return validateExternalEvidence(\n {\n title,\n description,\n severity,\n advisory_ids: [\n ...new Set([\n id,\n ...(text(\n record(rule[\"fullDescription\"] ?? {}, \"Full description\")[\n \"text\"\n ],\n )?.match(/\\bCVE-\\d{4}-\\d+\\b/gu) ?? []),\n ]),\n ],\n packages,\n // Snyk emits target-relative paths without a Git-root offset and may\n // synthesize startLine=1. Keep both only in the original evidence.\n locations: [],\n source_data: structuredClone({\n document: documentContext,\n run: selectRunContext(result, rule, driverContext, documentContext),\n driver: driverContext,\n rule,\n result,\n }),\n },\n target,\n );\n },\n ({ result, project }) => snykIdentity(result, project),\n target,\n );\n}\n\n/** Import native `snyk test --json` Open Source vulnerability occurrences. */\nexport function normalizeSnykJson(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const projects = Array.isArray(input) ? input : [input];\n const entries = projects.flatMap((value) => {\n const project = record(value, \"Snyk Open Source project\");\n if (project[\"error\"])\n throw new Error(`Snyk scan failed: ${String(project[\"error\"])}`);\n if (project[\"docker\"] || project[\"applications\"])\n throw new Error(\n \"Snyk Container JSON is unsupported; use Open Source SCA results.\",\n );\n if (typeof project[\"ok\"] !== \"boolean\")\n throw new Error(\"Expected a completed Snyk Open Source test result.\");\n const manager = requiredText(\n project[\"packageManager\"],\n \"Snyk package manager\",\n );\n const manifest =\n text(project[\"displayTargetFile\"]) ?? text(project[\"targetFile\"]);\n const { vulnerabilities, ...context } = project;\n return array(vulnerabilities, \"Snyk vulnerabilities\").map((value) => ({\n value,\n context,\n manager,\n manifest,\n }));\n });\n return normalizeRecords(\n entries,\n ({ value, context, manager }) => {\n const vulnerability = record(value, \"Snyk vulnerability\");\n if (vulnerability[\"type\"] === \"license\")\n throw new Error(\n \"Snyk license findings are unsupported; only Open Source SCA vulnerabilities are imported.\",\n );\n const identifiers = record(\n vulnerability[\"identifiers\"] ?? {},\n \"Snyk identifiers\",\n );\n const severity = text(vulnerability[\"severity\"])?.toLowerCase();\n return validateExternalEvidence(\n {\n title: requiredText(\n vulnerability[\"title\"],\n \"Snyk vulnerability title\",\n ),\n description: text(vulnerability[\"description\"]),\n severity: [\"critical\", \"high\", \"medium\", \"low\"].includes(\n severity ?? \"\",\n )\n ? severity\n : \"unknown\",\n advisory_ids: [\n ...new Set([\n requiredText(vulnerability[\"id\"], \"Snyk advisory ID\"),\n ...strings(identifiers[\"CVE\"]),\n ]),\n ],\n packages: [\n {\n name: requiredText(\n vulnerability[\"name\"] ?? vulnerability[\"packageName\"],\n \"Snyk package name\",\n ),\n ecosystem: manager,\n installed_version: text(vulnerability[\"version\"]),\n // Native test paths are scan-target-relative, without a Git-root offset.\n manifest_path: null,\n fixed_versions: strings(vulnerability[\"fixedIn\"]),\n },\n ],\n locations: [],\n source_data: structuredClone({ project: context, vulnerability }),\n },\n target,\n );\n },\n ({ value, manager, manifest }) => {\n const vulnerability = record(value, \"Snyk vulnerability\");\n return stableId(\"snyk-json\", [\n manager,\n manifest,\n requiredText(vulnerability[\"id\"], \"Snyk advisory ID\"),\n requiredText(\n vulnerability[\"name\"] ?? vulnerability[\"packageName\"],\n \"Snyk package name\",\n ),\n text(vulnerability[\"version\"]),\n array(vulnerability[\"from\"] ?? [], \"Snyk dependency path\").map((item) =>\n requiredText(item, \"Snyk dependency\"),\n ),\n ]);\n },\n target,\n );\n}\n\nexport async function readSnykFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n const input = await readScannerJson(path);\n if (Array.isArray(input)) return normalizeSnykJson(input, target);\n const document = record(input, \"Snyk findings\");\n if (document[\"format\"] === \"snyk-findings-export/v1\")\n return normalizeSnykFindingsExport(document, target);\n if (document[\"version\"] === \"2.1.0\")\n return normalizeSnykSarif(document, target);\n return normalizeSnykJson(document, target);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SonarCapture } from "./sonar-findings.js";
|
|
2
|
+
export interface SonarCollectionOptions {
|
|
3
|
+
cwd: string;
|
|
4
|
+
project?: string;
|
|
5
|
+
sourceRepositoryUrl?: string | undefined;
|
|
6
|
+
branch?: string;
|
|
7
|
+
pullRequest?: string;
|
|
8
|
+
issueKeys?: readonly string[];
|
|
9
|
+
environment?: NodeJS.ProcessEnv;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
type SonarCommand = (args: string[]) => Promise<Record<string, unknown>>;
|
|
13
|
+
/** Fetch native SonarQube Cloud evidence through the developer's existing CLI session. */
|
|
14
|
+
export declare function collectSonarIssues(options: SonarCollectionOptions, runSonar?: SonarCommand): Promise<SonarCapture>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=sonar-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sonar-collector.d.ts","sourceRoot":"","sources":["../src/sonar-collector.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAU7B,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAmTzE,0FAA0F;AAC1F,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,YAAY,CAAC,CAgNvB"}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
5
|
+
import { boundSonarWorktree, sonarRepositoryForRemote, sonarCheckoutMatchesSource, } from "./external-findings-local.js";
|
|
6
|
+
import { localGitProtectionRoots } from "./local-git-metadata.js";
|
|
7
|
+
import { repositoryUrlKey } from "./external-import-contract.js";
|
|
8
|
+
import { forwardExternalImportSetting, requireExternalImports, } from "./external-imports-feature.js";
|
|
9
|
+
import { isRecord } from "./record.js";
|
|
10
|
+
import { array, record, relativePath, requiredText } from "./scanner-import.js";
|
|
11
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
12
|
+
import { completeSonarPages, mergeSonarIssueScope, } from "./sonar-findings.js";
|
|
13
|
+
import { gitOutput } from "./targets.js";
|
|
14
|
+
import { inspectTrustedExecutable, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
15
|
+
import { isSafeNonNegativeInteger } from "./value.js";
|
|
16
|
+
const execFile = promisify(execFileCallback);
|
|
17
|
+
async function sonarCommand(options, protectedRoots) {
|
|
18
|
+
const { environment = process.env, signal } = options;
|
|
19
|
+
const trusted = await resolveTrustedExecutable("sonar", environment, protectedRoots);
|
|
20
|
+
if (!trusted) {
|
|
21
|
+
throw new CodexSecurityError("Install the SonarQube CLI (sonar) and run 'sonar auth login', or import a saved Sonar export.");
|
|
22
|
+
}
|
|
23
|
+
const git = await inspectTrustedExecutable("git", trusted.environment, protectedRoots);
|
|
24
|
+
return async (args) => {
|
|
25
|
+
signal?.throwIfAborted();
|
|
26
|
+
let stdout;
|
|
27
|
+
try {
|
|
28
|
+
({ stdout } = await execFile(trusted.executable, args, {
|
|
29
|
+
// Authentication and raw API calls use the signed-in connection independently of checkout configuration.
|
|
30
|
+
cwd: dirname(trusted.executable),
|
|
31
|
+
env: git.environment,
|
|
32
|
+
signal,
|
|
33
|
+
maxBuffer: Infinity,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
signal?.throwIfAborted();
|
|
38
|
+
// Sonar reports authentication failures on stdout in JSON mode.
|
|
39
|
+
if (args[0] === "auth" &&
|
|
40
|
+
isRecord(error) &&
|
|
41
|
+
typeof error["stdout"] === "string" &&
|
|
42
|
+
error["stdout"].trim()) {
|
|
43
|
+
throw new CodexSecurityError(`Sonar authentication check failed. ${error["stdout"].trim()}\n${errorMessage(error)}\nCheck 'sonar auth status' or run 'sonar auth login'.`, { cause: error });
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return record(JSON.parse(stdout), `sonar ${args[0]} response`);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function checkoutOrigin(options, protectedRoots) {
|
|
51
|
+
try {
|
|
52
|
+
if (!(await boundSonarWorktree(options.cwd, protectedRoots, options.environment, options.signal)))
|
|
53
|
+
return;
|
|
54
|
+
const origin = await gitOutput(options.cwd, ["remote", "get-url", "--", "origin"], options.signal, undefined, undefined, "utf8", protectedRoots, options.environment);
|
|
55
|
+
return sonarRepositoryForRemote(origin);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
options.signal?.throwIfAborted();
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const selectProjectHint = "Select the Sonar project with --sonar-project KEY. The checkout's Git origin must identify one project in the signed-in Sonar organization for automatic discovery.";
|
|
63
|
+
async function projectFromOrigin(sonar, origin, organization, selected, selectedId) {
|
|
64
|
+
const response = await sonar([
|
|
65
|
+
"api",
|
|
66
|
+
"get",
|
|
67
|
+
`/dop-translation/project-bindings?${new URLSearchParams({ url: origin })}`,
|
|
68
|
+
]);
|
|
69
|
+
const bindings = array(response["bindings"], "Sonar repository bindings");
|
|
70
|
+
if (selectedId !== undefined) {
|
|
71
|
+
return bindings.some((item) => isRecord(item) && item["projectId"] === selectedId)
|
|
72
|
+
? selected
|
|
73
|
+
: undefined;
|
|
74
|
+
}
|
|
75
|
+
if (selected === undefined && bindings.length !== 1)
|
|
76
|
+
return;
|
|
77
|
+
for (const binding of bindings) {
|
|
78
|
+
const id = requiredText(record(binding, "Sonar repository binding")["projectId"], "Sonar bound project ID");
|
|
79
|
+
if (id.includes(","))
|
|
80
|
+
continue;
|
|
81
|
+
const result = await sonar([
|
|
82
|
+
"api",
|
|
83
|
+
"get",
|
|
84
|
+
`/api/components/search_projects?${new URLSearchParams({ projectIds: id, organization })}`,
|
|
85
|
+
]);
|
|
86
|
+
const components = array(result["components"], "Sonar bound projects");
|
|
87
|
+
const component = components.length === 1 ? components[0] : undefined;
|
|
88
|
+
if (!isRecord(component) ||
|
|
89
|
+
(component["id"] !== undefined && component["id"] !== id) ||
|
|
90
|
+
(component["organization"] !== undefined &&
|
|
91
|
+
component["organization"] !== organization))
|
|
92
|
+
continue;
|
|
93
|
+
const project = requiredText(component["key"], "Sonar bound project key");
|
|
94
|
+
if (selected === undefined || selected === project)
|
|
95
|
+
return project;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
async function verifySelectedProject(sonar, selected, organization) {
|
|
100
|
+
const result = await sonar([
|
|
101
|
+
"api",
|
|
102
|
+
"get",
|
|
103
|
+
`/api/components/show?${new URLSearchParams({ component: selected })}`,
|
|
104
|
+
]);
|
|
105
|
+
const component = result["component"];
|
|
106
|
+
if (!isRecord(component) ||
|
|
107
|
+
component["key"] !== selected ||
|
|
108
|
+
component["organization"] !== organization ||
|
|
109
|
+
component["qualifier"] !== "TRK")
|
|
110
|
+
throw new CodexSecurityError("Sonar could not verify the selected project in the signed-in organization. Check --sonar-project and 'sonar auth status'.");
|
|
111
|
+
}
|
|
112
|
+
async function resolveProject(sonar, organization, origin, selected, signal) {
|
|
113
|
+
let selectedId;
|
|
114
|
+
if (selected !== undefined) {
|
|
115
|
+
// The handoff or user has already selected this project.
|
|
116
|
+
const component = await sonar([
|
|
117
|
+
"api",
|
|
118
|
+
"get",
|
|
119
|
+
`/api/navigation/component?${new URLSearchParams({ component: selected, organization })}`,
|
|
120
|
+
]).catch(() => {
|
|
121
|
+
// Some token sessions cannot read browser navigation metadata.
|
|
122
|
+
signal?.throwIfAborted();
|
|
123
|
+
return undefined;
|
|
124
|
+
});
|
|
125
|
+
if (component &&
|
|
126
|
+
((component["key"] !== undefined && component["key"] !== selected) ||
|
|
127
|
+
(component["organization"] !== undefined &&
|
|
128
|
+
component["organization"] !== organization))) {
|
|
129
|
+
throw new CodexSecurityError("Sonar returned a different project or organization. Check --sonar-project and the organization in 'sonar auth status'.");
|
|
130
|
+
}
|
|
131
|
+
if (component?.["key"] === selected) {
|
|
132
|
+
const alm = component["alm"];
|
|
133
|
+
if (isRecord(alm) && alm["url"]) {
|
|
134
|
+
await verifySelectedProject(sonar, selected, organization);
|
|
135
|
+
return {
|
|
136
|
+
project: selected,
|
|
137
|
+
repositoryUrl: declaredScannerRepositoryUrl(alm["url"], "Sonar", "local"),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (component["organization"] === organization &&
|
|
141
|
+
typeof component["id"] === "string")
|
|
142
|
+
selectedId = component["id"];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (origin !== undefined) {
|
|
146
|
+
try {
|
|
147
|
+
const project = await projectFromOrigin(sonar, origin, organization, selected, selectedId);
|
|
148
|
+
if (project !== undefined)
|
|
149
|
+
return { project, repositoryUrl: origin };
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
signal?.throwIfAborted();
|
|
153
|
+
if (selected === undefined)
|
|
154
|
+
throw new CodexSecurityError(`${selectProjectHint}\n${errorMessage(error)}`, { cause: error });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (selected !== undefined) {
|
|
158
|
+
await verifySelectedProject(sonar, selected, organization);
|
|
159
|
+
return { project: selected };
|
|
160
|
+
}
|
|
161
|
+
throw new CodexSecurityError(selectProjectHint);
|
|
162
|
+
}
|
|
163
|
+
async function activeSonarConnection(sonar) {
|
|
164
|
+
const auth = await sonar(["auth", "status", "--format", "json"]);
|
|
165
|
+
if (auth["status"] !== "connected")
|
|
166
|
+
throw new CodexSecurityError(`Sonar CLI is not connected (${String(auth["status"])}). Run 'sonar auth login'.`);
|
|
167
|
+
const url = URL.parse(requiredText(auth["server"], "Sonar server"));
|
|
168
|
+
const server = url?.origin;
|
|
169
|
+
if (!server ||
|
|
170
|
+
url?.href !== server + "/" ||
|
|
171
|
+
!["https://sonarcloud.io", "https://sonarqube.us"].includes(server) ||
|
|
172
|
+
!auth["org"])
|
|
173
|
+
throw new CodexSecurityError("Connect the Sonar CLI to a SonarQube Cloud organization with 'sonar auth login'.");
|
|
174
|
+
const organization = requiredText(auth["org"], "Sonar organization");
|
|
175
|
+
return { server, organization };
|
|
176
|
+
}
|
|
177
|
+
async function latestAnalysisBase(sonar, project, branch, signal) {
|
|
178
|
+
try {
|
|
179
|
+
const metadata = await sonar([
|
|
180
|
+
"api",
|
|
181
|
+
"get",
|
|
182
|
+
`/api/project_analyses/search?${new URLSearchParams({ project, branch, ps: "1" })}`,
|
|
183
|
+
]);
|
|
184
|
+
const analysis = array(metadata["analyses"], "Sonar analyses")[0];
|
|
185
|
+
if (!isRecord(analysis) ||
|
|
186
|
+
typeof analysis["key"] !== "string" ||
|
|
187
|
+
!analysis["key"].trim())
|
|
188
|
+
return;
|
|
189
|
+
const base = analysis["relativePathFromScmRoot"];
|
|
190
|
+
const path = base === "" || base === "." ? "" : relativePath(base);
|
|
191
|
+
if (path !== null)
|
|
192
|
+
return { key: analysis["key"], path };
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
signal?.throwIfAborted();
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
function exactIssueBatches(server, query, keys) {
|
|
200
|
+
if (!keys.size)
|
|
201
|
+
return [keys];
|
|
202
|
+
// RFC 9110 §4.1 recommends support for URIs up to 8,000 octets. URLSearchParams
|
|
203
|
+
// emits ASCII, including three bytes for each encoded comma between issue keys.
|
|
204
|
+
const prefix = `${server}/api/issues/search?${query}&p=10000&issues=`.length;
|
|
205
|
+
const batches = [];
|
|
206
|
+
let batch = new Set();
|
|
207
|
+
let size = prefix;
|
|
208
|
+
for (const key of keys) {
|
|
209
|
+
const encoded = new URLSearchParams({ issues: key }).toString().length - "issues=".length;
|
|
210
|
+
if (batch.size && size + 3 + encoded > 8_000) {
|
|
211
|
+
batches.push(batch);
|
|
212
|
+
batch = new Set();
|
|
213
|
+
size = prefix;
|
|
214
|
+
}
|
|
215
|
+
size += encoded + (batch.size ? 3 : 0);
|
|
216
|
+
batch.add(key);
|
|
217
|
+
}
|
|
218
|
+
batches.push(batch);
|
|
219
|
+
return batches;
|
|
220
|
+
}
|
|
221
|
+
/** Fetch native SonarQube Cloud evidence through the developer's existing CLI session. */
|
|
222
|
+
export async function collectSonarIssues(options, runSonar) {
|
|
223
|
+
const suppliedEnvironment = options.environment ?? process.env;
|
|
224
|
+
requireExternalImports(suppliedEnvironment);
|
|
225
|
+
const environment = Object.create(null);
|
|
226
|
+
for (const name in suppliedEnvironment)
|
|
227
|
+
environment[name] = suppliedEnvironment[name];
|
|
228
|
+
forwardExternalImportSetting(suppliedEnvironment, environment);
|
|
229
|
+
options = { ...options, cwd: resolve(options.cwd), environment };
|
|
230
|
+
options.signal?.throwIfAborted();
|
|
231
|
+
const { pullRequest } = options;
|
|
232
|
+
let { branch } = options;
|
|
233
|
+
if (branch !== undefined && pullRequest !== undefined)
|
|
234
|
+
throw new CodexSecurityError("Select either a Sonar branch or a pull request.");
|
|
235
|
+
for (const [label, value] of [
|
|
236
|
+
["branch", branch],
|
|
237
|
+
["pull request", pullRequest],
|
|
238
|
+
["project", options.project],
|
|
239
|
+
]) {
|
|
240
|
+
if (value !== undefined)
|
|
241
|
+
requiredText(value, `Sonar ${label}`);
|
|
242
|
+
}
|
|
243
|
+
const keys = new Set(options.issueKeys);
|
|
244
|
+
if (options.issueKeys !== undefined && keys.size === 0)
|
|
245
|
+
throw new CodexSecurityError("The Sonar issue selection is empty.");
|
|
246
|
+
for (const key of keys) {
|
|
247
|
+
if (!key.trim() || key.includes(","))
|
|
248
|
+
throw new CodexSecurityError("Provide individual, nonempty Sonar issue keys.");
|
|
249
|
+
}
|
|
250
|
+
if (options.project?.includes(","))
|
|
251
|
+
throw new CodexSecurityError("Select one Sonar project key.");
|
|
252
|
+
const protectedRoots = [options.cwd];
|
|
253
|
+
for (const root of new Set([options.cwd, process.cwd()])) {
|
|
254
|
+
protectedRoots.push(...(await localGitProtectionRoots(root, environment, options.signal)));
|
|
255
|
+
}
|
|
256
|
+
const expected = options.sourceRepositoryUrl === undefined
|
|
257
|
+
? undefined
|
|
258
|
+
: declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Sonar", "local");
|
|
259
|
+
const origin = await checkoutOrigin(options, protectedRoots);
|
|
260
|
+
const checkExpectedRepository = (boundUrl) => {
|
|
261
|
+
if (expected &&
|
|
262
|
+
boundUrl &&
|
|
263
|
+
repositoryUrlKey(expected) !== repositoryUrlKey(boundUrl))
|
|
264
|
+
throw new CodexSecurityError("The selected Sonar repository does not match --source-repository-url.");
|
|
265
|
+
};
|
|
266
|
+
if (options.project === undefined)
|
|
267
|
+
checkExpectedRepository(origin);
|
|
268
|
+
if (options.project === undefined && origin === undefined)
|
|
269
|
+
throw new CodexSecurityError(selectProjectHint);
|
|
270
|
+
const sonar = runSonar ?? (await sonarCommand(options, protectedRoots));
|
|
271
|
+
const { server, organization } = await activeSonarConnection(sonar);
|
|
272
|
+
const { project, repositoryUrl } = await resolveProject(sonar, organization, origin, options.project, options.signal);
|
|
273
|
+
checkExpectedRepository(repositoryUrl);
|
|
274
|
+
if (project.includes(","))
|
|
275
|
+
throw new CodexSecurityError("Select one Sonar project key.");
|
|
276
|
+
if (branch === undefined && pullRequest === undefined) {
|
|
277
|
+
const response = await sonar([
|
|
278
|
+
"api",
|
|
279
|
+
"get",
|
|
280
|
+
`/api/project_branches/list?${new URLSearchParams({ project })}`,
|
|
281
|
+
]);
|
|
282
|
+
const main = array(response["branches"], "Sonar branches").find((item) => isRecord(item) && item["isMain"] === true);
|
|
283
|
+
if (!isRecord(main) ||
|
|
284
|
+
typeof main["name"] !== "string" ||
|
|
285
|
+
!main["name"].trim())
|
|
286
|
+
throw new CodexSecurityError("Sonar did not return its main branch. Select the source branch with --sonar-branch.");
|
|
287
|
+
branch = main["name"];
|
|
288
|
+
}
|
|
289
|
+
let analysis;
|
|
290
|
+
if (branch !== undefined && repositoryUrl !== undefined) {
|
|
291
|
+
const matched = (origin &&
|
|
292
|
+
repositoryUrlKey(origin) === repositoryUrlKey(repositoryUrl)) ||
|
|
293
|
+
(await sonarCheckoutMatchesSource(options.cwd, repositoryUrl, protectedRoots, environment, options.signal).catch(() => {
|
|
294
|
+
options.signal?.throwIfAborted();
|
|
295
|
+
return false;
|
|
296
|
+
}));
|
|
297
|
+
if (matched)
|
|
298
|
+
analysis = await latestAnalysisBase(sonar, project, branch, options.signal);
|
|
299
|
+
}
|
|
300
|
+
const query = new URLSearchParams({
|
|
301
|
+
organization,
|
|
302
|
+
componentKeys: project,
|
|
303
|
+
impactSoftwareQualities: "SECURITY",
|
|
304
|
+
additionalFields: "rules",
|
|
305
|
+
ps: "500",
|
|
306
|
+
});
|
|
307
|
+
if (branch !== undefined)
|
|
308
|
+
query.set("branch", branch);
|
|
309
|
+
if (pullRequest !== undefined)
|
|
310
|
+
query.set("pullRequest", pullRequest);
|
|
311
|
+
const pages = [];
|
|
312
|
+
const queryPageCounts = [];
|
|
313
|
+
const missing = new Set(keys);
|
|
314
|
+
const scope = {
|
|
315
|
+
organization,
|
|
316
|
+
project,
|
|
317
|
+
...(branch === undefined ? {} : { branch }),
|
|
318
|
+
...(pullRequest === undefined ? {} : { pullRequest }),
|
|
319
|
+
};
|
|
320
|
+
for (const batch of exactIssueBatches(server, query, keys)) {
|
|
321
|
+
if (batch.size)
|
|
322
|
+
query.set("issues", [...batch].join(","));
|
|
323
|
+
else
|
|
324
|
+
query.set("issueStatuses", "OPEN,CONFIRMED");
|
|
325
|
+
const queryPages = [];
|
|
326
|
+
for (let index = 1;; index++) {
|
|
327
|
+
options.signal?.throwIfAborted();
|
|
328
|
+
query.set("p", String(index));
|
|
329
|
+
const page = await sonar(["api", "get", `/api/issues/search?${query}`]);
|
|
330
|
+
const issues = array(page["issues"], "Sonar issues");
|
|
331
|
+
const paging = record(page["paging"], "Sonar paging");
|
|
332
|
+
const size = paging["pageSize"], total = paging["total"];
|
|
333
|
+
if (paging["pageIndex"] !== index ||
|
|
334
|
+
!isSafeNonNegativeInteger(size) ||
|
|
335
|
+
size === 0 ||
|
|
336
|
+
!isSafeNonNegativeInteger(total) ||
|
|
337
|
+
(!issues.length && index * size < total)) {
|
|
338
|
+
throw new CodexSecurityError(`Incomplete pagination in Sonar issues page ${index}.`);
|
|
339
|
+
}
|
|
340
|
+
queryPages.push(page);
|
|
341
|
+
if (total > 10_000)
|
|
342
|
+
throw new CodexSecurityError("Sonar issue search returns at most 10,000 results. Narrow the selection with --sonar-issue KEY or select a different branch or pull request.");
|
|
343
|
+
if (index * size >= total)
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
for (const { issues } of completeSonarPages(queryPages)) {
|
|
347
|
+
for (const issue of issues) {
|
|
348
|
+
const key = requiredText(issue["key"], "Sonar issue key");
|
|
349
|
+
if (issue["project"] !== project || (batch.size && !batch.has(key)))
|
|
350
|
+
throw new CodexSecurityError(`Sonar returned issue ${key} outside the selected project or issue keys.`);
|
|
351
|
+
mergeSonarIssueScope(scope, issue);
|
|
352
|
+
missing.delete(key);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
pages.push(...queryPages);
|
|
356
|
+
queryPageCounts.push(queryPages.length);
|
|
357
|
+
}
|
|
358
|
+
if (missing.size)
|
|
359
|
+
throw new CodexSecurityError(`Selected Sonar security issues were not returned for this project and ref: ${[...missing].join(", ")}.`);
|
|
360
|
+
// Keep native paths when a newer analysis may have changed their repository base during collection.
|
|
361
|
+
const latest = analysis && branch !== undefined
|
|
362
|
+
? await latestAnalysisBase(sonar, project, branch, options.signal)
|
|
363
|
+
: undefined;
|
|
364
|
+
const projectBase = analysis && latest?.key === analysis.key && latest.path === analysis.path
|
|
365
|
+
? analysis.path
|
|
366
|
+
: undefined;
|
|
367
|
+
const active = await activeSonarConnection(sonar);
|
|
368
|
+
if (active.server !== server || active.organization !== organization)
|
|
369
|
+
throw new CodexSecurityError("The active Sonar connection changed during collection. Select the intended connection and collect again.");
|
|
370
|
+
return {
|
|
371
|
+
format: "sonar-issues/v1",
|
|
372
|
+
server,
|
|
373
|
+
organization,
|
|
374
|
+
project,
|
|
375
|
+
branch,
|
|
376
|
+
pullRequest,
|
|
377
|
+
repositoryUrl,
|
|
378
|
+
projectBase,
|
|
379
|
+
pages,
|
|
380
|
+
...(queryPageCounts.length > 1 ? { queryPageCounts } : {}),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=sonar-collector.js.map
|