@openai/codex-security 0.8.3 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -151
- package/_bundled_plugin/.mcp.json +5 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- 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/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +71 -7
- package/_bundled_plugin/scripts/workbench_cli.py +30 -12
- package/_bundled_plugin/scripts/workbench_constants.py +10 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +369 -137
- package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
- package/_bundled_plugin/scripts/workbench_progress.py +10 -1
- package/_bundled_plugin/scripts/workbench_publication.py +14 -10
- package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
- package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
- package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +13 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +127 -56
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
- package/_bundled_plugin/shared/workbench-migrations.json +34 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/dist/api.d.ts +39 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +774 -292
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -6
- package/dist/auth.js.map +1 -1
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +35 -20
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +2 -4
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +11 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1734 -1238
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +27 -2
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +100 -66
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +80 -12
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +483 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +2 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +25 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +3 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +1 -1
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +28 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +103 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +7 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +7 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +337 -89
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +8 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1318 -258
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +20 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +148 -66
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +42 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +5 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +23 -9
- 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/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +15 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +55 -30
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/hosted-scanner-v1.d.ts +6 -0
- package/dist/hosted-scanner-v1.d.ts.map +1 -0
- package/dist/hosted-scanner-v1.js +60 -0
- package/dist/hosted-scanner-v1.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +47 -65
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +68 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +1 -1
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +1 -2
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +138 -65
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +1 -0
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +17 -13
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +97 -2
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +58 -34
- package/dist/private-finding-import.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +8 -1
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/reader-selection.d.ts +2 -0
- package/dist/reader-selection.d.ts.map +1 -1
- package/dist/reader-selection.js +8 -0
- package/dist/reader-selection.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -7
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +313 -110
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +18 -15
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +60 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +6 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +75 -42
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +22 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +9 -19
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +106 -77
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +20 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +200 -8
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +107 -43
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +207 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +983 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/semgrep-platform-v1.d.ts +6 -0
- package/dist/semgrep-platform-v1.d.ts.map +1 -0
- package/dist/semgrep-platform-v1.js +83 -0
- package/dist/semgrep-platform-v1.js.map +1 -0
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +7 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +93 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +76 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +1051 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-rest-v1.d.ts +28 -0
- package/dist/snyk-rest-v1.d.ts.map +1 -0
- package/dist/snyk-rest-v1.js +132 -0
- package/dist/snyk-rest-v1.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +2 -4
- package/dist/sonar-import.js.map +1 -1
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +2 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +56 -20
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +9 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +435 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +2 -0
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +49 -11
- package/dist/veracode-findings.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +4 -0
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +57 -3
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +497 -550
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +66 -39
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +50 -42
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +18 -15
- package/schemas/external-findings.schema.json +3 -1
- 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/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/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
|
@@ -1,8 +1,68 @@
|
|
|
1
|
-
import { canonicalNumber, validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
|
-
import {
|
|
1
|
+
import { DEFAULT_CLOUD_STRING_BYTES, validateCodeLineRange, canonicalNumber, validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
|
+
import { hostedRepositoryMatches, normalizeHostedGitRepositoryUrl, hostedRepositoryUrlKey, isPublicGitHost as publicGitHost, gitServiceHostname, } from "./hosted-git-repository.js";
|
|
3
|
+
import { isGitHubCloudHost } from "./git-remote.js";
|
|
3
4
|
import { position, weaknessIds } from "./native-json-findings.js";
|
|
4
|
-
import { array, normalizeRecords, record, relativePath, repositoryFilePath, requiredText, stableId, text, } from "./scanner-import.js";
|
|
5
|
-
import {
|
|
5
|
+
import { array, hostedRepositoryPath, normalizeRecords, record, relativePath, repositoryFilePath, scannerSeverity, strings, requiredText, stableId, text, } from "./scanner-import.js";
|
|
6
|
+
import { hostedNumberToken, hostedNativeRepositoryUrl, hostedRepositoryUrl, } from "./hosted-scanner-http.js";
|
|
7
|
+
import { isRecord } from "./record.js";
|
|
8
|
+
import { declaredScannerRepositoryUrl, validScannerRepositoryUrl, } from "./scanner-repository-url.js";
|
|
9
|
+
import { legacyDecimalInteger, restoreLegacyHostedNumbers, } from "./hosted-scanner-v1.js";
|
|
10
|
+
import { semgrepV1Id, upgradeSemgrepPlatformReport, } from "./semgrep-platform-v1.js";
|
|
11
|
+
export const semgrepPlatformFormat = "semgrep-platform-findings/v2";
|
|
12
|
+
export const semgrepPlatformLegacyFormat = "semgrep-platform-findings/v1";
|
|
13
|
+
export const SEMGREP_PLATFORM_PRODUCTS = ["sast", "sca", "ai_sast"];
|
|
14
|
+
export const semgrepSelectionFormat = "semgrep-platform-selection/v1";
|
|
15
|
+
export function isSemgrepPlatformFormat(format) {
|
|
16
|
+
return (format === semgrepSelectionFormat ||
|
|
17
|
+
format === semgrepPlatformFormat ||
|
|
18
|
+
format === semgrepPlatformLegacyFormat);
|
|
19
|
+
}
|
|
20
|
+
function selectedProjectUrl(value, label) {
|
|
21
|
+
return declaredScannerRepositoryUrl(value, label, "local");
|
|
22
|
+
}
|
|
23
|
+
/** Recover the native collection scope, including when every row was excluded. */
|
|
24
|
+
export function semgrepPlatformReportScope(input, provider, references = []) {
|
|
25
|
+
const format = "sourceFormat" in input ? input.sourceFormat : undefined;
|
|
26
|
+
if ("semgrepPlatformScope" in input &&
|
|
27
|
+
input.semgrepPlatformScope !== undefined &&
|
|
28
|
+
!isSemgrepPlatformFormat(format))
|
|
29
|
+
throw new Error("A normalized Semgrep Platform report scope requires its source format.");
|
|
30
|
+
if (format === undefined &&
|
|
31
|
+
provider === "semgrep" &&
|
|
32
|
+
"sourceRepositoryUrl" in input &&
|
|
33
|
+
input.sourceRepositoryUrl !== undefined &&
|
|
34
|
+
(input.findings.length === 0 ||
|
|
35
|
+
input.findings.some((row) => isSemgrepPlatformEvidence(row, provider)))) {
|
|
36
|
+
// The object-row SDK retained only the binding on the envelope, including empty reports.
|
|
37
|
+
return {
|
|
38
|
+
url: hostedRepositoryUrl(input.sourceRepositoryUrl, "Semgrep Platform"),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!isSemgrepPlatformFormat(format))
|
|
42
|
+
return;
|
|
43
|
+
const scope = record("semgrepPlatformScope" in input ? input.semgrepPlatformScope : undefined, "Normalized Semgrep report scope");
|
|
44
|
+
const readUrl = format === semgrepSelectionFormat
|
|
45
|
+
? selectedProjectUrl
|
|
46
|
+
: hostedRepositoryUrl;
|
|
47
|
+
const url = readUrl("sourceRepositoryUrl" in input ? input.sourceRepositoryUrl : undefined, "Semgrep Platform");
|
|
48
|
+
if (format !== semgrepSelectionFormat && references.length)
|
|
49
|
+
selectionRepository(url, references);
|
|
50
|
+
return {
|
|
51
|
+
format,
|
|
52
|
+
deployment: requiredText(scope["deployment"], "Semgrep deployment"),
|
|
53
|
+
projectId: savedPlatformId(requiredText(scope["projectId"], "Semgrep project ID")),
|
|
54
|
+
ref: requiredText(scope["ref"], "Semgrep ref"),
|
|
55
|
+
product: scopeProduct(scope["product"], format !== semgrepSelectionFormat),
|
|
56
|
+
url,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function semgrepPlatformReportRepository(input, provider) {
|
|
60
|
+
return semgrepPlatformReportScope(input, provider)?.url;
|
|
61
|
+
}
|
|
62
|
+
// Raw JSON numbers are represented as JavaScript objects during lossless parsing.
|
|
63
|
+
export function responseRecord(value, label) {
|
|
64
|
+
return record(hostedNumberToken(value) === undefined ? value : undefined, label);
|
|
65
|
+
}
|
|
6
66
|
// These v1 Findings API response fields belong only to AI detections or Supply Chain.
|
|
7
67
|
const nonSastFields = [
|
|
8
68
|
"ai_impact",
|
|
@@ -24,23 +84,19 @@ function identifiesNonSastProduct(value) {
|
|
|
24
84
|
}
|
|
25
85
|
// Node 22 supports JSON source text and raw values. The SDK targets the ES2022 type library.
|
|
26
86
|
const wireJson = JSON;
|
|
27
|
-
|
|
28
|
-
function responseRecord(value, label) {
|
|
29
|
-
return record(wireJson.isRawJSON(value) ? undefined : value, label);
|
|
30
|
-
}
|
|
31
|
-
function sourceLine(value) {
|
|
87
|
+
function sourceLine(value, coerceStrings) {
|
|
32
88
|
if (value == null)
|
|
33
89
|
return null;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
90
|
+
const token = hostedNumberToken(value);
|
|
91
|
+
// A long fraction can round to an integer if it is converted before checking its decimal value.
|
|
92
|
+
if (token !== undefined)
|
|
93
|
+
return position(Number(legacyDecimalInteger(token)), "Semgrep source line");
|
|
94
|
+
return position(coerceStrings ? Number(semgrepPlatformId(value)) : value, "Semgrep source line");
|
|
38
95
|
}
|
|
39
|
-
|
|
40
|
-
function parseSemgrepResponse(json) {
|
|
96
|
+
export function parseSemgrepResponse(json) {
|
|
41
97
|
return responseRecord(JSON.parse(json.replace(/^\uFEFF/u, ""), (_key, value, context) => typeof value === "number" ? wireJson.rawJSON(context.source) : value), "Semgrep API response");
|
|
42
98
|
}
|
|
43
|
-
function
|
|
99
|
+
export function semgrepPlatformIdOrUndefined(value) {
|
|
44
100
|
let token;
|
|
45
101
|
if (wireJson.isRawJSON(value))
|
|
46
102
|
token = value.rawJSON;
|
|
@@ -57,71 +113,319 @@ function platformId(value) {
|
|
|
57
113
|
? id
|
|
58
114
|
: undefined;
|
|
59
115
|
}
|
|
60
|
-
function
|
|
61
|
-
const id =
|
|
62
|
-
if (
|
|
116
|
+
export function semgrepPlatformId(value) {
|
|
117
|
+
const id = semgrepPlatformIdOrUndefined(value);
|
|
118
|
+
if (id === undefined)
|
|
63
119
|
throw new Error("Expected an exact, positive Semgrep Platform ID.");
|
|
64
120
|
return id;
|
|
65
121
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
122
|
+
// Older selections retained full decimal ID tokens beyond Semgrep's native int64 range.
|
|
123
|
+
function archivedPlatformId(value) {
|
|
124
|
+
const token = wireJson.isRawJSON(value)
|
|
125
|
+
? canonicalNumber(value.rawJSON, Math.max(21, value.rawJSON.length))
|
|
126
|
+
: value;
|
|
127
|
+
return typeof token === "string" && /^[1-9][0-9]*$/u.test(token)
|
|
128
|
+
? token
|
|
129
|
+
: semgrepPlatformId(value);
|
|
130
|
+
}
|
|
131
|
+
function savedPlatformId(value) {
|
|
132
|
+
if (typeof value !== "string")
|
|
133
|
+
return semgrepPlatformId(value);
|
|
134
|
+
const canonical = semgrepPlatformId(wireJson.rawJSON(value));
|
|
135
|
+
if (canonical !== value && !/^[1-9][0-9]*$/u.test(value))
|
|
136
|
+
throw new Error("Invalid saved Semgrep project ID.");
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
function scopeOf(deployment, project, ref, readId = semgrepPlatformId, readUrl = hostedRepositoryUrl) {
|
|
140
|
+
const row = responseRecord(project, "Semgrep project");
|
|
141
|
+
const id = readId(row["id"]);
|
|
142
|
+
return {
|
|
143
|
+
deployment: requiredText(deployment, "Semgrep deployment"),
|
|
71
144
|
project: {
|
|
72
|
-
id:
|
|
73
|
-
name: requiredText(
|
|
74
|
-
url:
|
|
145
|
+
id: text(row["id"]) ?? id,
|
|
146
|
+
name: requiredText(row["name"], "Semgrep project name"),
|
|
147
|
+
url: readUrl(row["url"], "Semgrep Platform"),
|
|
75
148
|
},
|
|
76
|
-
ref: requiredText(
|
|
149
|
+
ref: requiredText(ref, "Semgrep ref"),
|
|
77
150
|
product: "sast",
|
|
78
151
|
};
|
|
152
|
+
}
|
|
153
|
+
export function projectAliases(name, url, references = [], earlyV1 = false) {
|
|
154
|
+
const { hostname, pathname } = new URL(url);
|
|
155
|
+
const path = pathname.slice(1).replace(/\/$/u, "");
|
|
156
|
+
const decodePath = (decode) => path
|
|
157
|
+
.split("/")
|
|
158
|
+
.map((segment) => {
|
|
159
|
+
try {
|
|
160
|
+
// Keep encoded separators within their original segment.
|
|
161
|
+
const label = decode(segment);
|
|
162
|
+
return /[/\\]/u.test(label) ? segment : label;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return segment;
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
.join("/");
|
|
169
|
+
const { name: key, source } = repositoryContext(url, references);
|
|
170
|
+
const paths = [path, decodePath(decodeURIComponent)];
|
|
171
|
+
const publicHost = publicGitHost(gitServiceHostname(hostname));
|
|
172
|
+
const knownGitSuffix = source.platform === "github" || source.platform === "gitlab" || publicHost;
|
|
173
|
+
if (knownGitSuffix)
|
|
174
|
+
paths.push(...paths.map((path) => path.replace(/\.git$/u, "")));
|
|
175
|
+
const pathKeys = new Set(paths.flatMap((path) => [
|
|
176
|
+
key(path),
|
|
177
|
+
key(path.slice(path.lastIndexOf("/") + 1)),
|
|
178
|
+
]));
|
|
179
|
+
const shortName = name.slice(name.lastIndexOf("/") + 1);
|
|
180
|
+
const historicalPaths = [];
|
|
181
|
+
if (earlyV1) {
|
|
182
|
+
// Older exports used decodeURI, which preserves escaped reserved delimiters.
|
|
183
|
+
for (const historical of [path, decodePath(decodeURI)]) {
|
|
184
|
+
if (!publicGitHost(hostname))
|
|
185
|
+
historicalPaths.push(historical);
|
|
186
|
+
if (publicHost || source.platform === "github")
|
|
187
|
+
historicalPaths.push(historical.replace(/\.git$/u, ""));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const hasHistoricalPath = (label) => historicalPaths.some((path) => label === path || label === path.slice(path.lastIndexOf("/") + 1));
|
|
191
|
+
return {
|
|
192
|
+
hasHistoricalPath,
|
|
193
|
+
has: (label) => label === name ||
|
|
194
|
+
label === shortName ||
|
|
195
|
+
pathKeys.has(key(label)) ||
|
|
196
|
+
hasHistoricalPath(label),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Older captures could derive a row label from their verified HTTP mapping for an SSH project. */
|
|
200
|
+
export function legacyProjectAliases(name, url, references, mapping) {
|
|
201
|
+
const native = projectAliases(name, url, references, true);
|
|
202
|
+
const mapped = mapping && mapping !== url
|
|
203
|
+
? projectAliases(name, mapping, references, true)
|
|
204
|
+
: undefined;
|
|
205
|
+
return {
|
|
206
|
+
has: (label) => native.has(label) || !!mapped?.hasHistoricalPath(label),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Compare HTTP origins canonically without folding paths on independent custom Git hosts. */
|
|
210
|
+
export function semgrepRepositoryUrlKey(value) {
|
|
211
|
+
return hostedRepositoryUrlKey(nativeHttp(value));
|
|
212
|
+
}
|
|
213
|
+
/** A real HTTP URL can elide its default port. Git transport serializations retain explicit ports. */
|
|
214
|
+
function nativeHttp(url) {
|
|
215
|
+
return URL.parse(url)?.href ?? url;
|
|
216
|
+
}
|
|
217
|
+
/** Readers may pass the SCM web link from the project response or its equivalent Git transport. */
|
|
218
|
+
export function semgrepReferenceMatches(source, url) {
|
|
219
|
+
// A standard explicit Git HTTP(S) helper carries the same fetch URL.
|
|
220
|
+
const helper = /^(?:https?|ftps?)::(?=([a-zA-Z]+):\/\/)/u.exec(url);
|
|
221
|
+
if (helper)
|
|
222
|
+
return (/^https?$/iu.test(helper[1]) &&
|
|
223
|
+
hostedRepositoryMatches(source, url.slice(helper[0].length)));
|
|
224
|
+
if (hostedRepositoryMatches(source, url))
|
|
225
|
+
return true;
|
|
226
|
+
try {
|
|
227
|
+
// Serialize only a valid repository link. Git checkout URLs retain their original bytes.
|
|
228
|
+
const link = hostedRepositoryUrl(url, "Semgrep");
|
|
229
|
+
return hostedRepositoryMatches(source, new URL(link).href);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
export function semgrepPlatformRepositoryReference(url, references) {
|
|
236
|
+
const projectUrl = nativeHttp(url);
|
|
237
|
+
const source = { url: projectUrl };
|
|
238
|
+
const nativeHost = gitServiceHostname(URL.parse(url)?.hostname ?? "");
|
|
239
|
+
const ownPlatformMatches = ({ url, platform }) => platform !== undefined &&
|
|
240
|
+
semgrepReferenceMatches({ url: projectUrl, platform }, url);
|
|
241
|
+
const platform = isGitHubCloudHost(nativeHost)
|
|
242
|
+
? "github"
|
|
243
|
+
: references.find(ownPlatformMatches)?.platform;
|
|
244
|
+
if (platform) {
|
|
245
|
+
source.platform = platform;
|
|
246
|
+
if (references.some((ref) => ref.platform &&
|
|
247
|
+
ref.platform !== platform &&
|
|
248
|
+
(ownPlatformMatches(ref) || semgrepReferenceMatches(source, ref.url))))
|
|
249
|
+
throw new Error("Conflicting SCM platforms for the selected Semgrep repository.");
|
|
250
|
+
}
|
|
251
|
+
return source;
|
|
252
|
+
}
|
|
253
|
+
/** Keep provider transport spelling independently of its resolved HTTP repository. */
|
|
254
|
+
export function semgrepProjectUrlEvidence(raw, resolved, mapping) {
|
|
255
|
+
if (resolved === undefined)
|
|
256
|
+
return { sourceRepositoryUrl: mapping };
|
|
257
|
+
if (typeof raw === "string" && raw !== resolved)
|
|
258
|
+
return {
|
|
259
|
+
nativeProjectUrl: raw,
|
|
260
|
+
...(mapping && { sourceRepositoryUrl: mapping }),
|
|
261
|
+
};
|
|
262
|
+
return {};
|
|
263
|
+
}
|
|
264
|
+
/** Interpret a project's native SSH spelling only when its Git host is known. */
|
|
265
|
+
export function semgrepNativeProjectUrl(value, references) {
|
|
266
|
+
if (value == null || value === "")
|
|
267
|
+
return;
|
|
268
|
+
const label = "Semgrep project repository";
|
|
269
|
+
if (typeof value === "string" &&
|
|
270
|
+
value.trim() === value &&
|
|
271
|
+
typeof references !== "function" &&
|
|
272
|
+
references.length) {
|
|
273
|
+
// Derive only a candidate from the native SSH spelling. The reader's Git fetch address must match.
|
|
274
|
+
const candidate = normalizeHostedGitRepositoryUrl(value, undefined, true);
|
|
275
|
+
if (candidate !== value &&
|
|
276
|
+
references.some(({ platform, url }) => (platform === "github" || platform === "gitlab") &&
|
|
277
|
+
semgrepReferenceMatches({ url: candidate, platform }, url)))
|
|
278
|
+
return hostedRepositoryUrl(candidate, label);
|
|
279
|
+
}
|
|
280
|
+
return hostedNativeRepositoryUrl(value, label);
|
|
281
|
+
}
|
|
282
|
+
function referenceRepositoryKey(references, target = "local") {
|
|
283
|
+
return (url) => repositoryContext(url, references, target).key(url);
|
|
284
|
+
}
|
|
285
|
+
function repositoryContext(projectUrl, references = [], target = "local") {
|
|
286
|
+
const source = semgrepPlatformRepositoryReference(projectUrl, typeof references === "function" ? [] : references);
|
|
287
|
+
const github = source.platform === "github";
|
|
288
|
+
return {
|
|
289
|
+
source,
|
|
290
|
+
selectableProject: validScannerRepositoryUrl(projectUrl, "local"),
|
|
291
|
+
key: (url) => typeof references === "function"
|
|
292
|
+
? references(nativeHttp(url))
|
|
293
|
+
: hostedRepositoryUrlKey(target === "cloud" ? url : nativeHttp(url), github, source.platform === "gitlab", target),
|
|
294
|
+
name: (name) => (github ? name.toLowerCase() : name),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export function selectionRepository(projectUrl, references = [], target = "local") {
|
|
298
|
+
const repository = repositoryContext(projectUrl, references, target);
|
|
299
|
+
if (!references.every(({ url }) => {
|
|
300
|
+
if (target === "local")
|
|
301
|
+
return semgrepReferenceMatches(repository.source, url);
|
|
302
|
+
const mapped = normalizeHostedGitRepositoryUrl(url, projectUrl, repository.source.platform !== undefined);
|
|
303
|
+
return repository.key(mapped) === repository.key(projectUrl);
|
|
304
|
+
}))
|
|
305
|
+
throw new Error("The reader's source repository does not match the selected Semgrep project.");
|
|
306
|
+
return repository;
|
|
307
|
+
}
|
|
308
|
+
function repositoryWithOnlyAlias(finding, names) {
|
|
309
|
+
const repo = record(finding["repository"] ?? {}, "Semgrep finding repository");
|
|
310
|
+
const label = text(repo["name"]);
|
|
311
|
+
return label && !names.has(label) && repo["id"] == null && !text(repo["url"])
|
|
312
|
+
? label
|
|
313
|
+
: undefined;
|
|
314
|
+
}
|
|
315
|
+
function hasSemgrepScaEvidence(finding) {
|
|
316
|
+
return (finding["found_dependency"] != null ||
|
|
317
|
+
finding["vulnerability_identifier"] != null);
|
|
318
|
+
}
|
|
319
|
+
/** Complete reports record the repository labels returned by the project-ID-scoped request. */
|
|
320
|
+
export function checkSemgrepPlatformRow(finding, scope, aliases, repository = repositoryContext(scope.project.url), readId = semgrepPlatformId, repositoryUrl = hostedNativeRepositoryUrl, capture = false) {
|
|
321
|
+
const repo = responseRecord(finding["repository"] ?? (aliases ? {} : undefined), "Semgrep finding repository");
|
|
322
|
+
const repositoryId = repo["id"] == null ? undefined : readId(repo["id"]);
|
|
323
|
+
const hasUrl = repo["url"] != null && (!aliases || repo["url"] !== "");
|
|
324
|
+
const name = repo["name"];
|
|
325
|
+
const encodedPath = new URL(scope.project.url).pathname.replace(/^\/|\/$/gu, "");
|
|
326
|
+
const decodedPath = decodeURIComponent(encodedPath);
|
|
327
|
+
// Archived captures may retain the encoded path spelling as their repository name.
|
|
328
|
+
const matchesQualifiedName = (normalize) => {
|
|
329
|
+
const label = typeof name === "string" ? normalize(name) : null;
|
|
330
|
+
return (!!label?.includes("/") &&
|
|
331
|
+
(label === normalize(decodedPath) ||
|
|
332
|
+
(!capture && label === normalize(encodedPath))));
|
|
333
|
+
};
|
|
334
|
+
const selectionRepositoryMatches = hasUrl ||
|
|
335
|
+
(repo["url"] == null &&
|
|
336
|
+
repositoryId !== undefined &&
|
|
337
|
+
matchesQualifiedName(repository.name));
|
|
338
|
+
if (!aliases) {
|
|
339
|
+
readId(finding["id"]);
|
|
340
|
+
if (!selectionRepositoryMatches)
|
|
341
|
+
throw new Error("Semgrep finding repository does not match the selected project and ref.");
|
|
342
|
+
}
|
|
343
|
+
if (repositoryId !== undefined &&
|
|
344
|
+
repositoryId !== semgrepPlatformId(wireJson.rawJSON(scope.project.id)))
|
|
345
|
+
throw new Error("Semgrep finding repository does not match the selected project and ref.");
|
|
346
|
+
const declaredProduct = scope.product === "sast" ? ["sast", "code"] : [scope.product];
|
|
347
|
+
for (const product of [finding["issue_type"], finding["product"]]) {
|
|
348
|
+
if (product != null &&
|
|
349
|
+
(typeof product !== "string" ||
|
|
350
|
+
!declaredProduct.includes(product.toLowerCase())))
|
|
351
|
+
throw new Error(scope.product === "sast"
|
|
352
|
+
? "Select Semgrep Code (SAST) findings."
|
|
353
|
+
: "Semgrep finding does not match the selected product.");
|
|
354
|
+
}
|
|
355
|
+
if ((!aliases || finding["ref"] !== undefined) &&
|
|
356
|
+
finding["ref"] !== scope.ref)
|
|
357
|
+
throw new Error("Semgrep finding does not belong to the selected project and ref.");
|
|
358
|
+
if (hasUrl) {
|
|
359
|
+
const url = repositoryUrl(repo["url"], "Semgrep finding repository", repository.source.platform === "github" ||
|
|
360
|
+
repository.source.platform === "gitlab"
|
|
361
|
+
? new URL(repository.source.url).hostname
|
|
362
|
+
: undefined);
|
|
363
|
+
if (repository.key(url) !== repository.key(scope.project.url))
|
|
364
|
+
throw new Error("Semgrep finding repository does not match the selected project and ref.");
|
|
365
|
+
}
|
|
366
|
+
// A verified ID or URL can identify a bulk row whose optional display name is blank.
|
|
367
|
+
const alias = typeof name === "string" && (repositoryId !== undefined || hasUrl)
|
|
368
|
+
? text(name)
|
|
369
|
+
: name;
|
|
370
|
+
if (aliases &&
|
|
371
|
+
alias != null &&
|
|
372
|
+
!aliases.has(requiredText(alias, "Semgrep repository name")))
|
|
373
|
+
throw new Error("Semgrep finding repository does not match the selected project and ref.");
|
|
374
|
+
if ((scope.product === "sast" &&
|
|
375
|
+
!capture &&
|
|
376
|
+
identifiesNonSastProduct(finding)) ||
|
|
377
|
+
(scope.product === "ai_sast" && hasSemgrepScaEvidence(finding)))
|
|
378
|
+
throw new Error("Select Semgrep Code (SAST) findings.");
|
|
379
|
+
return (scope.product === "sast" &&
|
|
380
|
+
repository.selectableProject &&
|
|
381
|
+
// A replayable selection requires a repository on the native project response.
|
|
382
|
+
(scope.sourceRepositoryUrl === undefined ||
|
|
383
|
+
scope.nativeProjectUrl !== undefined) &&
|
|
384
|
+
finding["ref"] === scope.ref &&
|
|
385
|
+
selectionRepositoryMatches &&
|
|
386
|
+
[finding["id"], repo["id"]].every((id) => id == null || semgrepPlatformIdOrUndefined(id) !== undefined) &&
|
|
387
|
+
// Before a reader hint promotes a backlog row, check its complete selected projection.
|
|
388
|
+
(!aliases ||
|
|
389
|
+
hasUrl ||
|
|
390
|
+
matchesQualifiedName(repositoryContext(scope.project.url).name) ||
|
|
391
|
+
normalizePlatformRows([{ finding, selectable: true }], scope, "local")
|
|
392
|
+
.excluded.length === 0));
|
|
393
|
+
}
|
|
394
|
+
export function requireSemgrepFullRef(ref) {
|
|
79
395
|
// git-check-ref-format distinguishes literal branch/tag names from revision expressions.
|
|
80
|
-
const refParts =
|
|
396
|
+
const refParts = ref.split("/");
|
|
81
397
|
if (refParts[0] !== "refs" ||
|
|
82
398
|
refParts.length < 2 ||
|
|
83
399
|
refParts.some((part) => !part || part.startsWith(".") || part.endsWith(".lock")) ||
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/[\u0000-\u0020\u007f~^:?*\[\\]/u.test(
|
|
400
|
+
ref.endsWith(".") ||
|
|
401
|
+
ref.includes("..") ||
|
|
402
|
+
ref.includes("@{") ||
|
|
403
|
+
/[\u0000-\u0020\u007f~^:?*\[\\]/u.test(ref))
|
|
88
404
|
throw new Error("Use a fully qualified Semgrep ref such as refs/heads/topic.");
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
405
|
+
}
|
|
406
|
+
function selectedRows(options, repositoryFor, repositoryUrl = hostedNativeRepositoryUrl) {
|
|
407
|
+
const scope = scopeOf(options.deployment, parseSemgrepResponse(options.projectResponse)["project"], options.ref, semgrepPlatformId, selectedProjectUrl);
|
|
408
|
+
requireSemgrepFullRef(scope.ref);
|
|
409
|
+
const repository = repositoryFor(scope);
|
|
410
|
+
const wanted = new Set(options.findingIds.map((id) => semgrepPlatformId(requiredText(id, "Selected Semgrep finding ID"))));
|
|
92
411
|
if (!wanted.size)
|
|
93
412
|
throw new Error("Select at least one Semgrep finding ID.");
|
|
94
413
|
const selected = new Map();
|
|
95
414
|
const pages = typeof options.findingsResponses === "string"
|
|
96
415
|
? [options.findingsResponses]
|
|
97
416
|
: options.findingsResponses;
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const findings = array(parseSemgrepResponse(response)["findings"], "Semgrep findings");
|
|
417
|
+
for (const page of pages) {
|
|
418
|
+
const findings = array(parseSemgrepResponse(page)["findings"], "Semgrep findings");
|
|
101
419
|
const previousCount = selected.size;
|
|
102
420
|
for (const finding of findings) {
|
|
103
421
|
if (!isRecord(finding))
|
|
104
422
|
continue;
|
|
105
|
-
const id =
|
|
423
|
+
const id = semgrepPlatformIdOrUndefined(finding["id"]);
|
|
106
424
|
if (!id || !wanted.has(id))
|
|
107
425
|
continue;
|
|
108
426
|
if (selected.has(id))
|
|
109
427
|
throw new Error(`Duplicate selected Semgrep finding ${id}.`);
|
|
110
|
-
|
|
111
|
-
const repositoryId = repo["id"] == null ? undefined : requiredPlatformId(repo["id"]);
|
|
112
|
-
const url = repo["url"];
|
|
113
|
-
const name = repo["name"];
|
|
114
|
-
const matchesQualifiedPath = name === projectPath && projectPath.includes("/");
|
|
115
|
-
if (finding["ref"] !== scope.ref ||
|
|
116
|
-
(repositoryId !== undefined && repositoryId !== scope.project.id) ||
|
|
117
|
-
(url != null
|
|
118
|
-
? url !== scope.project.url
|
|
119
|
-
: repositoryId === undefined || !matchesQualifiedPath))
|
|
120
|
-
throw new Error("Selected Semgrep finding does not belong to the selected project and ref.");
|
|
121
|
-
if ([finding["issue_type"], finding["product"]].some((product) => product != null &&
|
|
122
|
-
(typeof product !== "string" ||
|
|
123
|
-
!["sast", "code"].includes(product.toLowerCase()))))
|
|
124
|
-
throw new Error("Select Semgrep Code (SAST) findings.");
|
|
428
|
+
checkSemgrepPlatformRow(finding, scope, undefined, repository, semgrepPlatformId, repositoryUrl, true);
|
|
125
429
|
selected.set(id, finding);
|
|
126
430
|
}
|
|
127
431
|
// The v1 findings endpoint returns a single product per response page.
|
|
@@ -130,33 +434,635 @@ export function normalizeSelectedSemgrepPlatformFindings(options) {
|
|
|
130
434
|
throw new Error("Select Semgrep Code (SAST) findings.");
|
|
131
435
|
}
|
|
132
436
|
const rows = Array.from(wanted, (id) => {
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
135
|
-
throw new Error(`Selected Semgrep finding ${id} is missing.`);
|
|
136
|
-
return
|
|
437
|
+
const value = selected.get(id);
|
|
438
|
+
if (!value)
|
|
439
|
+
throw new Error(`Selected Semgrep finding ${id} is missing from the supplied pages.`);
|
|
440
|
+
return value;
|
|
137
441
|
});
|
|
138
|
-
|
|
442
|
+
return { scope, rows };
|
|
443
|
+
}
|
|
444
|
+
/** Select existing SAST findings from native Web API responses for one project and ref. */
|
|
445
|
+
export function selectSemgrepPlatformFindings(options) {
|
|
446
|
+
const { scope, rows } = selectedRows(options, (scope) => selectionRepository(scope.project.url, options.sourceRepositories));
|
|
447
|
+
return {
|
|
448
|
+
format: semgrepSelectionFormat,
|
|
449
|
+
...scope,
|
|
450
|
+
findings: rows.map((row) => stringifySemgrepFinding(row)),
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
/** Select SAST findings using the operator's exact, independently supplied HTTP(S) spelling. */
|
|
454
|
+
export function normalizeSelectedSemgrepPlatformFindings(options) {
|
|
455
|
+
const url = hostedRepositoryUrl(options.sourceRepositoryUrl, "Semgrep");
|
|
456
|
+
const { scope, rows } = selectedRows(options, (scope) => {
|
|
457
|
+
if (scope.project.url !== url)
|
|
458
|
+
throw new Error("Selected Semgrep project does not match the operator's source repository URL.");
|
|
459
|
+
const exact = (value) => value;
|
|
460
|
+
return {
|
|
461
|
+
source: { url },
|
|
462
|
+
selectableProject: true,
|
|
463
|
+
key: exact,
|
|
464
|
+
name: exact,
|
|
465
|
+
};
|
|
466
|
+
}, hostedRepositoryUrl);
|
|
467
|
+
return {
|
|
468
|
+
...normalizePlatformRows(rows.map((finding) => ({ finding, selectable: true })), scope, "local"),
|
|
469
|
+
sourceRepositoryUrl: scope.project.url,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function sourceId(scope, finding, readId = semgrepPlatformId) {
|
|
473
|
+
// Keep the same tuple for a selected import and a subsequent scoped Platform collection.
|
|
139
474
|
const exact = (id) => Number.isSafeInteger(Number(id)) ? Number(id) : id;
|
|
140
|
-
return
|
|
475
|
+
return stableId("semgrep-platform", [
|
|
476
|
+
scope.deployment,
|
|
477
|
+
exact(readId(wireJson.rawJSON(scope.project.id))),
|
|
478
|
+
scope.product,
|
|
479
|
+
scope.ref,
|
|
480
|
+
exact(readId(finding["id"])),
|
|
481
|
+
]);
|
|
482
|
+
}
|
|
483
|
+
function scopeProduct(native, complete) {
|
|
484
|
+
const product = SEMGREP_PLATFORM_PRODUCTS.find((value) => value === native);
|
|
485
|
+
if (!product || (!complete && product !== "sast"))
|
|
486
|
+
throw new Error("Select a supported Semgrep Platform product for this report.");
|
|
487
|
+
return product;
|
|
488
|
+
}
|
|
489
|
+
function readScope(input, references, target = "local") {
|
|
490
|
+
const complete = input["format"] === semgrepPlatformFormat ||
|
|
491
|
+
input["format"] === semgrepPlatformLegacyFormat;
|
|
492
|
+
const product = scopeProduct(input["product"], complete);
|
|
493
|
+
const project = responseRecord(input["project"], "Semgrep project");
|
|
494
|
+
if (input["format"] === semgrepPlatformFormat &&
|
|
495
|
+
typeof project["id"] !== "string")
|
|
496
|
+
throw new Error("A Semgrep Platform v2 project ID must be a positive decimal string.");
|
|
497
|
+
if (!complete)
|
|
498
|
+
requiredText(project["id"], "Semgrep selected project ID");
|
|
499
|
+
const mapping = complete && input["sourceRepositoryUrl"] !== undefined
|
|
500
|
+
? hostedRepositoryUrl(input["sourceRepositoryUrl"], "Semgrep source repository")
|
|
501
|
+
: undefined;
|
|
502
|
+
// Captures expose an HTTP URL; stored occurrences retain the provider's SSH spelling.
|
|
503
|
+
const projectUrl = project["url"];
|
|
504
|
+
const suppliedNative = complete ? input["nativeProjectUrl"] : undefined;
|
|
505
|
+
const raw = suppliedNative !== undefined
|
|
506
|
+
? requiredText(suppliedNative, "Semgrep native project URL")
|
|
507
|
+
: complete &&
|
|
508
|
+
typeof projectUrl === "string" &&
|
|
509
|
+
!/^https?:\/\//iu.test(projectUrl)
|
|
510
|
+
? projectUrl
|
|
511
|
+
: undefined;
|
|
512
|
+
const native = raw === undefined ? undefined : semgrepNativeProjectUrl(raw, references);
|
|
513
|
+
if (suppliedNative !== undefined &&
|
|
514
|
+
(!native || native === raw || native !== projectUrl))
|
|
515
|
+
throw new Error("Semgrep native project URL does not match its recorded HTTP repository.");
|
|
516
|
+
if (mapping && projectUrl != null) {
|
|
517
|
+
const key = native && repositoryContext(native, references, target).key;
|
|
518
|
+
if (key ? key(native) !== key(mapping) : projectUrl !== mapping)
|
|
519
|
+
throw new Error("Semgrep project does not match its recorded source repository URL.");
|
|
520
|
+
}
|
|
521
|
+
const scope = {
|
|
522
|
+
...scopeOf(input["deployment"], { ...project, url: native ?? mapping ?? project["url"] }, input["ref"], savedPlatformId, complete ? hostedRepositoryUrl : selectedProjectUrl),
|
|
523
|
+
...(mapping && { sourceRepositoryUrl: mapping }),
|
|
524
|
+
...(native && { nativeProjectUrl: raw }),
|
|
525
|
+
product,
|
|
526
|
+
};
|
|
527
|
+
const aliases = complete
|
|
528
|
+
? new Set(array(input["repositoryAliases"], "Semgrep repository aliases").map((value) => requiredText(value, "Semgrep repository alias")))
|
|
529
|
+
: undefined;
|
|
530
|
+
return { scope, aliases };
|
|
531
|
+
}
|
|
532
|
+
function matchesNativeInteger(value, expected) {
|
|
533
|
+
if (expected == null)
|
|
534
|
+
return value == null;
|
|
535
|
+
const token = hostedNumberToken(value);
|
|
536
|
+
if (token === undefined)
|
|
537
|
+
return value === expected;
|
|
538
|
+
return expected === 0
|
|
539
|
+
? /^-?0(?:\.0+)?(?:e[+-]?\d+)?$/iu.test(token)
|
|
540
|
+
: legacyDecimalInteger(token) === String(expected);
|
|
541
|
+
}
|
|
542
|
+
const generatedId = /^semgrep-platform:[0-9a-f]{64}$/u;
|
|
543
|
+
/** Current occurrences carry a provider-specific key; older v1 rows retain their native scope and finding. */
|
|
544
|
+
export function isSemgrepPlatformEvidence(finding, provider) {
|
|
545
|
+
const data = finding.evidence.source_data;
|
|
546
|
+
if (generatedId.test(finding.source_finding_id))
|
|
547
|
+
return true;
|
|
548
|
+
if (!data)
|
|
549
|
+
return false;
|
|
550
|
+
if (isSemgrepPlatformFormat(data["format"]) ||
|
|
551
|
+
Object.hasOwn(data, "semgrepPlatformFindingJson"))
|
|
552
|
+
return true;
|
|
553
|
+
// Other scanners can use the same project and finding fields, including numeric IDs.
|
|
554
|
+
if (provider !== "semgrep")
|
|
555
|
+
return false;
|
|
556
|
+
const project = data["project"];
|
|
557
|
+
const row = data["finding"];
|
|
558
|
+
return (isRecord(row) &&
|
|
559
|
+
"id" in row &&
|
|
560
|
+
isRecord(project) &&
|
|
561
|
+
project["id"] != null &&
|
|
562
|
+
typeof project["name"] === "string" &&
|
|
563
|
+
typeof data["ref"] === "string" &&
|
|
564
|
+
typeof data["deployment"] === "string" &&
|
|
565
|
+
SEMGREP_PLATFORM_PRODUCTS.some((product) => product === data["product"]));
|
|
566
|
+
}
|
|
567
|
+
function upgradeOriginalSemgrepFinding(data, references, target) {
|
|
568
|
+
const { numericFields: _witness, finding: original, ...context } = restoreLegacyHostedNumbers(data);
|
|
569
|
+
const converted = upgradeSemgrepPlatformReport({ ...context, findings: [original], findingCount: 1 }, undefined, typeof references === "function"
|
|
570
|
+
? references
|
|
571
|
+
: referenceRepositoryKey(references, target), references);
|
|
572
|
+
return {
|
|
573
|
+
...converted,
|
|
574
|
+
semgrepPlatformFindingJson: array(converted["findings"], "Semgrep findings")[0],
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/** Keep caller-supplied metadata while replacing the scanner's old wire representation. */
|
|
578
|
+
function canonicalSourceDataWithExtensions(retained, canonical, original) {
|
|
579
|
+
const extensions = (original, verified, replaced = []) => Object.fromEntries(Object.entries(original).filter(([key]) => !Object.hasOwn(verified, key) && !replaced.includes(key)));
|
|
580
|
+
return {
|
|
581
|
+
...canonical,
|
|
582
|
+
...extensions(retained, canonical, [
|
|
583
|
+
...(original ? ["finding", "numericFields", "sourceRepositoryUrl"] : []),
|
|
584
|
+
"nativeProjectUrl",
|
|
585
|
+
"repositoryAliases",
|
|
586
|
+
"repositoryWitnessJson",
|
|
587
|
+
"idEncoding",
|
|
588
|
+
]),
|
|
589
|
+
project: {
|
|
590
|
+
...canonical.project,
|
|
591
|
+
...extensions(record(retained["project"], "Semgrep project"), canonical.project),
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function legacyWitnessKey(scope, projectUrlKey, label) {
|
|
596
|
+
return JSON.stringify([
|
|
597
|
+
scope.deployment,
|
|
598
|
+
scope.project.id,
|
|
599
|
+
scope.product,
|
|
600
|
+
scope.ref,
|
|
601
|
+
projectUrlKey,
|
|
602
|
+
label,
|
|
603
|
+
]);
|
|
604
|
+
}
|
|
605
|
+
function nativeOccurrence(retained, references, target) {
|
|
606
|
+
let data = !isSemgrepPlatformFormat(retained["format"])
|
|
607
|
+
? {
|
|
608
|
+
...retained,
|
|
609
|
+
format: (!Object.hasOwn(retained, "semgrepPlatformFindingJson") &&
|
|
610
|
+
"finding" in retained) ||
|
|
611
|
+
retained["idEncoding"] === "v1-decimal"
|
|
612
|
+
? semgrepPlatformLegacyFormat
|
|
613
|
+
: "repositoryAliases" in retained
|
|
614
|
+
? semgrepPlatformFormat
|
|
615
|
+
: semgrepSelectionFormat,
|
|
616
|
+
}
|
|
617
|
+
: retained;
|
|
618
|
+
const legacy = data["format"] === semgrepPlatformLegacyFormat;
|
|
619
|
+
const original = legacy && !Object.hasOwn(data, "semgrepPlatformFindingJson");
|
|
620
|
+
if (original)
|
|
621
|
+
data = upgradeOriginalSemgrepFinding(data, references, target);
|
|
622
|
+
const { scope, aliases } = readScope(data, references, target);
|
|
623
|
+
const repository = repositoryContext(scope.project.url, references, target);
|
|
624
|
+
const row = parseSemgrepResponse(requiredText(data["semgrepPlatformFindingJson"], "Semgrep finding JSON"));
|
|
625
|
+
return { data, legacy, original, scope, aliases, repository, row };
|
|
626
|
+
}
|
|
627
|
+
/** Original v1 occurrences could keep only the observed repository label on a row. */
|
|
628
|
+
export function semgrepLegacyRepositoryWitnesses(findings, provider, references = [], target = "local") {
|
|
629
|
+
const witnesses = new Map();
|
|
630
|
+
// Current occurrences carry their own witness. Only original rows need a sibling lookup.
|
|
631
|
+
if (!findings.some(({ evidence }) => isRecord(evidence.source_data?.["finding"])))
|
|
632
|
+
return witnesses;
|
|
633
|
+
for (const finding of findings) {
|
|
634
|
+
const data = finding.evidence.source_data;
|
|
635
|
+
if (!data || !isSemgrepPlatformEvidence(finding, provider))
|
|
636
|
+
continue;
|
|
637
|
+
const { scope, aliases, repository, row, legacy } = nativeOccurrence(data, references, target);
|
|
638
|
+
const repo = row["repository"];
|
|
639
|
+
if (!isRecord(repo))
|
|
640
|
+
continue;
|
|
641
|
+
const label = text(repo["name"]);
|
|
642
|
+
if (!label || (repo["id"] == null && !text(repo["url"])))
|
|
643
|
+
continue;
|
|
644
|
+
checkSemgrepPlatformRow(row, scope, aliases, repository, legacy ? semgrepV1Id : semgrepPlatformId);
|
|
645
|
+
witnesses.set(legacyWitnessKey(scope, repository.key(scope.project.url), label), JSON.stringify({ id: scope.project.id, name: label }));
|
|
646
|
+
}
|
|
647
|
+
return witnesses;
|
|
648
|
+
}
|
|
649
|
+
/** Recheck the source repository when an SDK caller supplies normalized evidence directly. */
|
|
650
|
+
export function semgrepPlatformFindingRepository(finding, provider, references = [], legacyWitnesses) {
|
|
651
|
+
return semgrepPlatformFindingBinding(finding, provider, references, legacyWitnesses)?.url;
|
|
652
|
+
}
|
|
653
|
+
export function platformLocationPath(value) {
|
|
654
|
+
const path = text(value);
|
|
655
|
+
const relative = relativePath(path);
|
|
656
|
+
return relative && !relative.endsWith("/.") && repositoryFilePath(relative)
|
|
657
|
+
? path
|
|
658
|
+
: null;
|
|
659
|
+
}
|
|
660
|
+
function platformLocation(location, product, selectable, bulk) {
|
|
661
|
+
const path = platformLocationPath(location["file_path"]);
|
|
662
|
+
const oldPath = bulk?.legacy
|
|
663
|
+
? hostedRepositoryPath(location["file_path"])
|
|
664
|
+
: null;
|
|
665
|
+
const unprojected = { locations: [], endLine: null };
|
|
666
|
+
if (!path && !oldPath)
|
|
667
|
+
return unprojected;
|
|
668
|
+
// V1 retained coordinates for unprojected paths without validating them.
|
|
669
|
+
const newlyProjectable = !!bulk?.legacy && !oldPath;
|
|
670
|
+
const coerce = newlyProjectable || (!!bulk && !bulk.legacy && !selectable);
|
|
671
|
+
try {
|
|
672
|
+
const line = sourceLine(location["line"], coerce);
|
|
673
|
+
const endLine = line !== null && product !== "sca"
|
|
674
|
+
? sourceLine(location["end_line"], coerce)
|
|
675
|
+
: null;
|
|
676
|
+
if (bulk?.legacy && oldPath !== path)
|
|
677
|
+
validateCodeLineRange(line, endLine);
|
|
678
|
+
return path ? { locations: [{ path, line }], endLine } : unprojected;
|
|
679
|
+
}
|
|
680
|
+
catch (error) {
|
|
681
|
+
if (newlyProjectable)
|
|
682
|
+
return unprojected;
|
|
683
|
+
throw error;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function platformSeverity(value, selectable) {
|
|
687
|
+
const severity = text(value)?.toLowerCase();
|
|
688
|
+
return scannerSeverity(selectable && severity === "informational" ? null : severity);
|
|
689
|
+
}
|
|
690
|
+
/** Upgrade only values produced by the original object-row reader; keep SDK-authored evidence. */
|
|
691
|
+
function migrateLegacyProjection(evidence, row, scope, selectable, references) {
|
|
692
|
+
const severity = text(row["severity"]);
|
|
693
|
+
const oldSeverity = scannerSeverity(severity === "informational" ? null : severity);
|
|
694
|
+
const upgradeSeverity = evidence.severity === oldSeverity &&
|
|
695
|
+
oldSeverity !== scannerSeverity(severity?.toLowerCase());
|
|
696
|
+
const location = isRecord(row["location"]) ? row["location"] : {};
|
|
697
|
+
const oldPath = hostedRepositoryPath(location["file_path"]);
|
|
698
|
+
const first = evidence.locations?.[0];
|
|
699
|
+
// Only replace the exact location and end line produced by the original object-row reader.
|
|
700
|
+
const oldLocation = oldPath !== platformLocationPath(location["file_path"]) &&
|
|
701
|
+
(oldPath
|
|
702
|
+
? evidence.locations?.length === 1 &&
|
|
703
|
+
first?.path === oldPath &&
|
|
704
|
+
matchesNativeInteger(location["line"], first.line)
|
|
705
|
+
: evidence.locations?.length === 0) &&
|
|
706
|
+
matchesNativeInteger(oldPath && scope.product !== "sca" && first?.line != null
|
|
707
|
+
? location["end_line"]
|
|
708
|
+
: null, evidence.details?.code?.end_line);
|
|
709
|
+
if (!upgradeSeverity && !oldLocation)
|
|
710
|
+
return;
|
|
711
|
+
const projected = normalizePlatformRows([{ finding: row, selectable }], scope, "local", {
|
|
712
|
+
legacy: true,
|
|
713
|
+
projectNames: projectAliases(scope.project.name, scope.project.url, references),
|
|
714
|
+
}).findings[0]?.evidence;
|
|
715
|
+
if (!projected)
|
|
716
|
+
return;
|
|
717
|
+
return {
|
|
718
|
+
...(upgradeSeverity && { severity: projected.severity }),
|
|
719
|
+
...(oldLocation && { locations: projected.locations }),
|
|
720
|
+
...(oldLocation &&
|
|
721
|
+
evidence.details?.code &&
|
|
722
|
+
projected.details?.code && {
|
|
723
|
+
details: {
|
|
724
|
+
...evidence.details,
|
|
725
|
+
code: {
|
|
726
|
+
...evidence.details.code,
|
|
727
|
+
end_line: projected.details.code.end_line,
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
}),
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function qualifiedBranch(ref) {
|
|
734
|
+
return ref.startsWith("refs/") ? ref : `refs/heads/${ref}`;
|
|
735
|
+
}
|
|
736
|
+
function checkProjectedProduct(finding, product, native = false) {
|
|
737
|
+
const kind = finding.evidence.details?.kind;
|
|
738
|
+
if ((product === "sca" && kind === "sast") ||
|
|
739
|
+
(native && (kind === "secret" || kind === "iac")))
|
|
740
|
+
throw new Error("The projected finding kind does not match the Semgrep report product.");
|
|
741
|
+
}
|
|
742
|
+
/** A marked report reserves the v1 finding's repository, ref and product for Semgrep scope. */
|
|
743
|
+
export function hasRetainedSemgrepScope(finding) {
|
|
744
|
+
if (!isRecord(finding))
|
|
745
|
+
return false;
|
|
746
|
+
const repository = finding["repository"];
|
|
747
|
+
if (finding["ref"] !== undefined ||
|
|
748
|
+
hasSemgrepScaEvidence(finding) ||
|
|
749
|
+
(isRecord(repository) &&
|
|
750
|
+
(repository["id"] != null ||
|
|
751
|
+
!!text(repository["url"]) ||
|
|
752
|
+
!!text(repository["name"]))))
|
|
753
|
+
return true;
|
|
754
|
+
return [finding["product"], finding["issue_type"]].some((value) => {
|
|
755
|
+
if (typeof value !== "string")
|
|
756
|
+
return false;
|
|
757
|
+
const product = value.toLowerCase();
|
|
758
|
+
return (product === "code" ||
|
|
759
|
+
SEMGREP_PLATFORM_PRODUCTS.some((known) => known === product));
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
export function semgrepPlatformFindingBinding(finding, provider, references = [], legacyWitnesses, reportScope, projectedSources = [], target = "local", replayApprovedRequest = false) {
|
|
763
|
+
const retained = finding.evidence.source_data;
|
|
764
|
+
if (!isSemgrepPlatformEvidence(finding, provider)) {
|
|
765
|
+
// Previously approved Cloud requests keep the released projection and native checks below.
|
|
766
|
+
if (!replayApprovedRequest &&
|
|
767
|
+
provider === "semgrep" &&
|
|
768
|
+
reportScope?.format !== undefined &&
|
|
769
|
+
hasRetainedSemgrepScope(retained?.["finding"]))
|
|
770
|
+
throw new Error("Retained Semgrep finding scope requires the original collection scope in a marked Platform report.");
|
|
771
|
+
if (reportScope && reportScope.format !== semgrepSelectionFormat) {
|
|
772
|
+
const source = repositoryContext(reportScope.url, references).source;
|
|
773
|
+
const claims = [
|
|
774
|
+
{
|
|
775
|
+
url: finding.evidence.details?.repository?.url,
|
|
776
|
+
branch: finding.evidence.branch,
|
|
777
|
+
},
|
|
778
|
+
...projectedSources,
|
|
779
|
+
];
|
|
780
|
+
if (claims.some((claim) => claim?.url && !semgrepReferenceMatches(source, claim.url)))
|
|
781
|
+
throw new Error("The projected repository does not match the Semgrep report repository.");
|
|
782
|
+
const ref = reportScope.ref && qualifiedBranch(reportScope.ref);
|
|
783
|
+
if (ref &&
|
|
784
|
+
claims.some((claim) => claim?.branch && qualifiedBranch(claim.branch) !== ref))
|
|
785
|
+
throw new Error("The projected branch does not match the Semgrep report ref.");
|
|
786
|
+
checkProjectedProduct(finding, reportScope.product);
|
|
787
|
+
}
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (!retained)
|
|
791
|
+
throw new Error("Missing the original Semgrep finding evidence.");
|
|
792
|
+
const { data, legacy, original, scope, aliases, repository, row } = nativeOccurrence(retained, references, target);
|
|
793
|
+
checkProjectedProduct(finding, scope.product, true);
|
|
794
|
+
if (reportScope?.deployment !== undefined &&
|
|
795
|
+
(scope.deployment !== reportScope.deployment ||
|
|
796
|
+
scope.project.id !== reportScope.projectId ||
|
|
797
|
+
scope.ref !== reportScope.ref ||
|
|
798
|
+
scope.product !== reportScope.product))
|
|
799
|
+
throw new Error("The Semgrep report repository scope does not match the finding's deployment, project ID, ref, or product.");
|
|
800
|
+
const other = data["finding"];
|
|
801
|
+
if ((legacy && Object.hasOwn(data, "finding")) ||
|
|
802
|
+
(isRecord(other) && Object.hasOwn(other, "id"))) {
|
|
803
|
+
const restored = restoreLegacyHostedNumbers(data)["finding"];
|
|
804
|
+
const originalRow = parseSemgrepResponse(JSON.stringify(restored));
|
|
805
|
+
const id = originalRow["id"];
|
|
806
|
+
const nativeId = semgrepPlatformIdOrUndefined(id) ??
|
|
807
|
+
(typeof id === "string" ? legacyDecimalInteger(id) : undefined);
|
|
808
|
+
if ((legacy || nativeId !== undefined) &&
|
|
809
|
+
stringifySemgrepFinding(originalRow) !== stringifySemgrepFinding(row))
|
|
810
|
+
throw new Error("The retained Semgrep finding representations disagree.");
|
|
811
|
+
}
|
|
812
|
+
const selectable = checkSemgrepPlatformRow(row, scope, aliases, repository, legacy ? semgrepV1Id : semgrepPlatformId);
|
|
813
|
+
if (reportScope?.format === semgrepSelectionFormat && !selectable)
|
|
814
|
+
throw new Error("Semgrep finding does not belong to the selected project and ref.");
|
|
815
|
+
let occurrenceId = legacy ? semgrepV1Id : semgrepPlatformId;
|
|
816
|
+
const nativeId = sourceId(scope, row, occurrenceId);
|
|
817
|
+
if (generatedId.test(finding.source_finding_id) &&
|
|
818
|
+
finding.source_finding_id !== nativeId) {
|
|
819
|
+
if (legacy ||
|
|
820
|
+
finding.source_finding_id !== sourceId(scope, row, archivedPlatformId))
|
|
821
|
+
throw new Error("The generated Semgrep finding ID does not match its native occurrence.");
|
|
822
|
+
occurrenceId = archivedPlatformId;
|
|
823
|
+
}
|
|
824
|
+
const { name, url } = scope.project;
|
|
825
|
+
let namedOnly = aliases && repositoryWithOnlyAlias(row, projectAliases(name, url));
|
|
826
|
+
const raw = original
|
|
827
|
+
? namedOnly &&
|
|
828
|
+
legacyWitnesses?.get(legacyWitnessKey(scope, repository.key(url), namedOnly))
|
|
829
|
+
: data["repositoryWitnessJson"];
|
|
830
|
+
// Only rely on the reader's platform hint when there is no independent proof.
|
|
831
|
+
if (namedOnly &&
|
|
832
|
+
raw === undefined &&
|
|
833
|
+
projectAliases(name, url, references).has(namedOnly))
|
|
834
|
+
namedOnly = undefined;
|
|
835
|
+
const legacyPath = original &&
|
|
836
|
+
namedOnly &&
|
|
837
|
+
legacyProjectAliases(name, url, references, scope.sourceRepositoryUrl).has(namedOnly);
|
|
838
|
+
if (raw !== undefined || (namedOnly && !legacyPath)) {
|
|
839
|
+
const label = text(record(row["repository"], "Semgrep finding repository")["name"]);
|
|
840
|
+
const witness = parseSemgrepResponse(requiredText(raw, "Semgrep repository alias witness"));
|
|
841
|
+
if (!label ||
|
|
842
|
+
witness["name"] !== label ||
|
|
843
|
+
(witness["id"] == null && !text(witness["url"])))
|
|
844
|
+
throw new Error("Semgrep repository alias lacks a matching project ID or URL.");
|
|
845
|
+
checkSemgrepPlatformRow({ repository: witness }, scope, aliases ?? new Set([label]), repository, legacy
|
|
846
|
+
? semgrepV1Id
|
|
847
|
+
: (id) => semgrepPlatformId(wireJson.rawJSON(savedPlatformId(id))));
|
|
848
|
+
}
|
|
849
|
+
const claimed = finding.evidence.details?.repository?.url;
|
|
850
|
+
if (finding.evidence.branch !== scope.ref ||
|
|
851
|
+
(!claimed && scope.product !== "sca") ||
|
|
852
|
+
(!!claimed &&
|
|
853
|
+
repository.key(hostedRepositoryUrl(claimed, "Semgrep evidence repository")) !== repository.key(scope.project.url)))
|
|
854
|
+
throw new Error("The normalized finding does not match its original Semgrep repository and ref.");
|
|
855
|
+
const canonical = platformSourceData(row, scope, selectable, aliases ? { legacy } : undefined, namedOnly, occurrenceId);
|
|
856
|
+
let migration = original
|
|
857
|
+
? migrateLegacyProjection(finding.evidence, row, scope, selectable, references)
|
|
858
|
+
: undefined;
|
|
859
|
+
if (!original &&
|
|
860
|
+
data["format"] === semgrepPlatformFormat &&
|
|
861
|
+
canonical.format === semgrepSelectionFormat) {
|
|
862
|
+
const selectedSeverity = platformSeverity(row["severity"], true);
|
|
863
|
+
if (selectedSeverity !== finding.evidence.severity &&
|
|
864
|
+
finding.evidence.severity === platformSeverity(row["severity"], false))
|
|
865
|
+
migration = { severity: selectedSeverity };
|
|
866
|
+
}
|
|
867
|
+
// The original reader projected the HTTP mapping when the native project URL used SSH.
|
|
868
|
+
const oldMappedUrl = original &&
|
|
869
|
+
scope.product !== "sca" &&
|
|
870
|
+
scope.nativeProjectUrl !== undefined &&
|
|
871
|
+
claimed === scope.sourceRepositoryUrl &&
|
|
872
|
+
claimed !== scope.project.url;
|
|
873
|
+
const details = migration?.details ?? finding.evidence.details;
|
|
874
|
+
return {
|
|
875
|
+
url: scope.project.url,
|
|
876
|
+
nativeId,
|
|
877
|
+
migration: oldMappedUrl && details?.repository
|
|
878
|
+
? {
|
|
879
|
+
...migration,
|
|
880
|
+
details: {
|
|
881
|
+
...details,
|
|
882
|
+
repository: { ...details.repository, url: scope.project.url },
|
|
883
|
+
},
|
|
884
|
+
}
|
|
885
|
+
: migration,
|
|
886
|
+
sourceData: canonicalSourceDataWithExtensions(retained, canonical, original),
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
/** Normalize a saved selection or Platform project export. The default target is local. */
|
|
890
|
+
export function normalizeSemgrepPlatformFindings(report, options = {}, target = "local", references = typeof options === "object"
|
|
891
|
+
? (options.sourceRepositories ?? [])
|
|
892
|
+
: []) {
|
|
893
|
+
const declaredUrl = typeof options === "string" ? options : options.sourceRepositoryUrl;
|
|
894
|
+
const saved = record(report, "Semgrep Platform report");
|
|
895
|
+
const sourceFormat = saved["format"];
|
|
896
|
+
if (!isSemgrepPlatformFormat(sourceFormat))
|
|
897
|
+
throw new Error("Expected a Semgrep Platform selection or project export.");
|
|
898
|
+
const legacy = sourceFormat === semgrepPlatformLegacyFormat;
|
|
899
|
+
const readId = legacy ? semgrepV1Id : semgrepPlatformId;
|
|
900
|
+
const input = legacy
|
|
901
|
+
? upgradeSemgrepPlatformReport(saved, declaredUrl, referenceRepositoryKey(references, target), references)
|
|
902
|
+
: saved;
|
|
903
|
+
const { scope, aliases } = readScope(input, references, target);
|
|
904
|
+
const repository = selectionRepository(scope.project.url, references, target);
|
|
905
|
+
if (declaredUrl &&
|
|
906
|
+
repository.key(hostedRepositoryUrl(declaredUrl, "Semgrep")) !==
|
|
907
|
+
repository.key(scope.project.url))
|
|
908
|
+
throw new Error("Semgrep project does not match the declared source repository URL.");
|
|
909
|
+
const verifiedLabels = new Set();
|
|
910
|
+
const projectNames = projectAliases(scope.project.name, scope.project.url, references);
|
|
911
|
+
const entries = array(input["findings"], "Semgrep Platform findings");
|
|
912
|
+
if (!aliases && !entries.length)
|
|
913
|
+
throw new Error("A saved Semgrep selection must contain at least one finding.");
|
|
914
|
+
const rows = entries.map((value) => {
|
|
915
|
+
const raw = requiredText(value, "Semgrep finding JSON");
|
|
916
|
+
const finding = parseSemgrepResponse(raw);
|
|
917
|
+
const selectable = checkSemgrepPlatformRow(finding, scope, aliases, repository, readId);
|
|
918
|
+
if (aliases) {
|
|
919
|
+
const repo = record(finding["repository"] ?? {}, "Semgrep finding repository");
|
|
920
|
+
const label = text(repo["name"]);
|
|
921
|
+
if (label && (repo["id"] != null || text(repo["url"])))
|
|
922
|
+
verifiedLabels.add(label);
|
|
923
|
+
}
|
|
924
|
+
return { finding, selectable };
|
|
925
|
+
});
|
|
926
|
+
if (aliases && !matchesNativeInteger(input["findingCount"], rows.length))
|
|
927
|
+
throw new Error("Incomplete Semgrep Platform export: finding count does not match.");
|
|
928
|
+
if (aliases) {
|
|
929
|
+
// v1 also accepted decodeURI path labels. Keep a witness for their current-format replay.
|
|
930
|
+
const archiveNames = legacy
|
|
931
|
+
? legacyProjectAliases(scope.project.name, scope.project.url, references, scope.sourceRepositoryUrl)
|
|
932
|
+
: projectNames;
|
|
933
|
+
for (const { finding } of rows) {
|
|
934
|
+
const name = repositoryWithOnlyAlias(finding, archiveNames);
|
|
935
|
+
if (name && !verifiedLabels.has(name))
|
|
936
|
+
throw new Error("Semgrep finding repository lacks a matching project name, ID or URL.");
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
const unhintedNames = projectAliases(scope.project.name, scope.project.url);
|
|
940
|
+
const result = normalizePlatformRows(rows, scope, target, aliases
|
|
941
|
+
? {
|
|
942
|
+
legacy,
|
|
943
|
+
projectNames: {
|
|
944
|
+
has: (name) => (verifiedLabels.has(name) ? unhintedNames : projectNames).has(name),
|
|
945
|
+
},
|
|
946
|
+
}
|
|
947
|
+
: undefined, aliases ? readId : archivedPlatformId);
|
|
948
|
+
return {
|
|
949
|
+
...result,
|
|
950
|
+
sourceFormat,
|
|
951
|
+
sourceRepositoryUrl: scope.project.url,
|
|
952
|
+
semgrepPlatformScope: {
|
|
953
|
+
deployment: scope.deployment,
|
|
954
|
+
projectId: scope.project.id,
|
|
955
|
+
ref: scope.ref,
|
|
956
|
+
product: scope.product,
|
|
957
|
+
},
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
export function stringifySemgrepFinding(finding, idOf = semgrepPlatformIdOrUndefined) {
|
|
961
|
+
const repo = finding["repository"];
|
|
962
|
+
const nativeIds = [finding["id"], isRecord(repo) ? repo["id"] : undefined];
|
|
963
|
+
return JSON.stringify(finding, (_key, value) => {
|
|
964
|
+
if (wireJson.isRawJSON(value)) {
|
|
965
|
+
const id = nativeIds.includes(value) ? idOf(value) : undefined;
|
|
966
|
+
return wireJson.rawJSON(id ?? canonicalNumber(value.rawJSON));
|
|
967
|
+
}
|
|
968
|
+
if (isRecord(value))
|
|
969
|
+
return Object.fromEntries(Object.keys(value)
|
|
970
|
+
.sort()
|
|
971
|
+
.map((key) => [key, value[key]]));
|
|
972
|
+
return value;
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
function platformSourceData(finding, scope, selectable, bulk, namedOnly, idOf = semgrepPlatformId) {
|
|
976
|
+
const repo = record(finding["repository"] ?? {}, "Semgrep finding repository");
|
|
977
|
+
const label = text(repo["name"]);
|
|
978
|
+
// Ordinary v1 and v2 rows share one stored representation on replay.
|
|
979
|
+
// Preserve the legacy discriminator only when reopening the raw IDs needs it.
|
|
980
|
+
const { nativeProjectUrl, ...evidenceScope } = scope;
|
|
981
|
+
const nativeBulkScope = !selectable ||
|
|
982
|
+
scope.sourceRepositoryUrl !== undefined ||
|
|
983
|
+
nativeProjectUrl !== undefined;
|
|
984
|
+
const needsLegacyId = bulk?.legacy &&
|
|
985
|
+
[finding["id"], repo["id"]].some((id) => typeof id === "string" &&
|
|
986
|
+
semgrepPlatformIdOrUndefined(id) === undefined);
|
|
987
|
+
// Native SAST rows with their own repository and ref replay identically in either import mode.
|
|
988
|
+
const needsBulkScope = bulk && (nativeBulkScope || needsLegacyId);
|
|
989
|
+
return {
|
|
990
|
+
format: needsLegacyId
|
|
991
|
+
? semgrepPlatformLegacyFormat
|
|
992
|
+
: needsBulkScope
|
|
993
|
+
? semgrepPlatformFormat
|
|
994
|
+
: semgrepSelectionFormat,
|
|
995
|
+
...evidenceScope,
|
|
996
|
+
project: {
|
|
997
|
+
...scope.project,
|
|
998
|
+
url: nativeProjectUrl ??
|
|
999
|
+
(scope.sourceRepositoryUrl ? null : scope.project.url),
|
|
1000
|
+
},
|
|
1001
|
+
...(needsLegacyId && { idEncoding: "v1-decimal" }),
|
|
1002
|
+
...(needsBulkScope && { repositoryAliases: label ? [label] : [] }),
|
|
1003
|
+
// Store the verified binding independently of the native fields retained on its proving row.
|
|
1004
|
+
...(namedOnly && {
|
|
1005
|
+
repositoryWitnessJson: JSON.stringify({
|
|
1006
|
+
id: scope.project.id,
|
|
1007
|
+
name: namedOnly,
|
|
1008
|
+
}),
|
|
1009
|
+
}),
|
|
1010
|
+
semgrepPlatformFindingJson: stringifySemgrepFinding(finding, idOf),
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
// Selected rows and complete captures share their evidence projection and identity tuple.
|
|
1014
|
+
function normalizePlatformRows(rows, scope, target, bulk, readId = bulk?.legacy ? semgrepV1Id : semgrepPlatformId) {
|
|
1015
|
+
const legacy = bulk?.legacy;
|
|
1016
|
+
return normalizeRecords(rows, ({ finding, selectable }) => {
|
|
141
1017
|
const rule = responseRecord(finding["rule"] ?? {}, "Semgrep rule");
|
|
142
1018
|
const name = text(rule["name"]) ?? text(finding["rule_name"]);
|
|
143
|
-
const severity = text(finding["severity"])?.toLowerCase() ?? "";
|
|
144
1019
|
const description = text(rule["message"]) ?? text(finding["rule_message"]);
|
|
145
1020
|
const location = responseRecord(finding["location"] ?? {}, "Semgrep location");
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
? rawPath
|
|
150
|
-
: null;
|
|
151
|
-
const startLine = path ? sourceLine(location["line"]) : null;
|
|
152
|
-
return validateExternalEvidence({
|
|
153
|
-
title: requiredText(name ?? description, "Semgrep finding title"),
|
|
1021
|
+
const { locations, endLine } = platformLocation(location, scope.product, selectable, bulk);
|
|
1022
|
+
const namedOnly = bulk && repositoryWithOnlyAlias(finding, bulk.projectNames);
|
|
1023
|
+
const common = {
|
|
154
1024
|
description,
|
|
155
|
-
severity: ["
|
|
156
|
-
|
|
157
|
-
: "unknown",
|
|
158
|
-
locations: path ? [{ path, line: startLine }] : [],
|
|
1025
|
+
severity: platformSeverity(finding["severity"], selectable),
|
|
1026
|
+
locations,
|
|
159
1027
|
branch: scope.ref,
|
|
1028
|
+
source_data: platformSourceData(finding, scope, selectable, bulk, namedOnly, readId),
|
|
1029
|
+
};
|
|
1030
|
+
let messageTitle = description ??
|
|
1031
|
+
(legacy || scope.product === "sast"
|
|
1032
|
+
? null
|
|
1033
|
+
: `Semgrep finding ${readId(finding["id"])}`);
|
|
1034
|
+
if (target === "cloud" &&
|
|
1035
|
+
description &&
|
|
1036
|
+
Buffer.byteLength(description) > DEFAULT_CLOUD_STRING_BYTES) {
|
|
1037
|
+
const id = finding["id"];
|
|
1038
|
+
messageTitle = `Semgrep finding ${text(id) ?? readId(id)}`;
|
|
1039
|
+
}
|
|
1040
|
+
if (scope.product === "sca") {
|
|
1041
|
+
const dependency = responseRecord(finding["found_dependency"] ?? {}, "Semgrep found dependency");
|
|
1042
|
+
const packages = [];
|
|
1043
|
+
if (dependency["package"] !== undefined) {
|
|
1044
|
+
const name = requiredText(dependency["package"], "Semgrep package name");
|
|
1045
|
+
const fixes = array(finding["fix_recommendations"] ?? [], "Semgrep fix recommendations");
|
|
1046
|
+
packages.push({
|
|
1047
|
+
name,
|
|
1048
|
+
ecosystem: text(dependency["ecosystem"]),
|
|
1049
|
+
installed_version: text(dependency["version"]),
|
|
1050
|
+
fixed_versions: strings(fixes.flatMap((fix) => isRecord(fix) && fix["package"] === name
|
|
1051
|
+
? [fix["version"]]
|
|
1052
|
+
: [])),
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
const advisory = text(finding["vulnerability_identifier"]);
|
|
1056
|
+
return validateExternalEvidence({
|
|
1057
|
+
...common,
|
|
1058
|
+
title: requiredText(name ?? advisory ?? packages[0]?.name ?? messageTitle, "Semgrep finding title"),
|
|
1059
|
+
advisory_ids: advisory ? [advisory] : [],
|
|
1060
|
+
packages,
|
|
1061
|
+
}, target);
|
|
1062
|
+
}
|
|
1063
|
+
return validateExternalEvidence({
|
|
1064
|
+
...common,
|
|
1065
|
+
title: requiredText(name ?? messageTitle, "Semgrep finding title"),
|
|
160
1066
|
details: {
|
|
161
1067
|
kind: "sast",
|
|
162
1068
|
repository: { url: scope.project.url },
|
|
@@ -164,35 +1070,9 @@ export function normalizeSelectedSemgrepPlatformFindings(options) {
|
|
|
164
1070
|
rule: name ? { id: name } : null,
|
|
165
1071
|
source_status: text(finding["status"]),
|
|
166
1072
|
weakness_ids: weaknessIds(rule["cwe_names"]),
|
|
167
|
-
code: {
|
|
168
|
-
end_line: startLine !== null ? sourceLine(location["end_line"]) : null,
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
source_data: {
|
|
172
|
-
format: "semgrep-platform-selection/v1",
|
|
173
|
-
...scope,
|
|
174
|
-
project: {
|
|
175
|
-
...scope.project,
|
|
176
|
-
id: text(native["id"]) ?? scope.project.id,
|
|
177
|
-
},
|
|
178
|
-
semgrepPlatformFindingJson: JSON.stringify(finding, (_key, value) => {
|
|
179
|
-
if (wireJson.isRawJSON(value))
|
|
180
|
-
return wireJson.rawJSON(canonicalNumber(value.rawJSON));
|
|
181
|
-
// Native object key order can vary across otherwise identical reads.
|
|
182
|
-
if (isRecord(value))
|
|
183
|
-
return Object.fromEntries(Object.keys(value)
|
|
184
|
-
.sort()
|
|
185
|
-
.map((key) => [key, value[key]]));
|
|
186
|
-
return value;
|
|
187
|
-
}),
|
|
1073
|
+
code: { end_line: endLine },
|
|
188
1074
|
},
|
|
189
|
-
},
|
|
190
|
-
}, (finding) =>
|
|
191
|
-
scope.deployment,
|
|
192
|
-
exact(scope.project.id),
|
|
193
|
-
scope.product,
|
|
194
|
-
scope.ref,
|
|
195
|
-
exact(requiredPlatformId(finding["id"])),
|
|
196
|
-
]), "local");
|
|
1075
|
+
}, target);
|
|
1076
|
+
}, ({ finding }) => sourceId(scope, finding, readId), target);
|
|
197
1077
|
}
|
|
198
1078
|
//# sourceMappingURL=semgrep-platform-findings.js.map
|