@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semgrep-findings.js","sourceRoot":"","sources":["../src/semgrep-findings.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,QAAQ,EACR,uBAAuB,EACvB,mBAAmB,EACnB,WAAW,EACX,WAAW,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,EACL,kCAAkC,EAClC,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EAC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cloudRepositoryUrlKey,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport {\n messageText,\n parseNativeJsonResult,\n position,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n ungatedText,\n weaknessIds,\n} from \"./native-json-findings.js\";\nimport {\n array,\n hasSarifExternalPropertyReferences,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n sarifRunResults,\n stableId,\n text,\n validateSarifRuleReference,\n} from \"./scanner-import.js\";\n\nexport interface SemgrepImportOptions {\n /** Source repository declared by the caller; never inferred from the destination. */\n sourceRepositoryUrl: string;\n}\n\nfunction sourceRepository(options: SemgrepImportOptions): string {\n return sourceRepositoryUrl(options?.sourceRepositoryUrl, \"Semgrep\");\n}\n\nfunction severity(value: unknown): string {\n const levels: Record<string, string> = {\n CRITICAL: \"critical\",\n HIGH: \"high\",\n MEDIUM: \"medium\",\n LOW: \"low\",\n ERROR: \"high\",\n WARNING: \"medium\",\n INFO: \"low\",\n };\n return typeof value === \"string\" ? (levels[value] ?? \"unknown\") : \"unknown\";\n}\n\nfunction identity(\n rule: string,\n path: string,\n line: number,\n column: number,\n endLine: number,\n endColumn: number,\n): string {\n // CE omits fingerprints and source snippets. Its fallback is stable only while the range is stable.\n return stableId(\"semgrep-location\", [\n rule,\n path,\n line,\n column,\n endLine,\n endColumn,\n ]);\n}\n\nfunction jsonIdentity(value: unknown): string {\n const result = record(value, \"Semgrep result\");\n const extra = record(result[\"extra\"], \"Semgrep extra\");\n const supplied = ungatedText(extra[\"fingerprint\"]);\n if (supplied) return stableId(\"semgrep\", [supplied]);\n const start = record(result[\"start\"], \"Semgrep start\");\n const end = record(result[\"end\"], \"Semgrep end\");\n return identity(\n requiredText(result[\"check_id\"], \"Semgrep check_id\"),\n requiredText(result[\"path\"], \"Semgrep path\"),\n position(start[\"line\"], \"Start line\"),\n position(start[\"col\"], \"Start column\"),\n position(end[\"line\"], \"End line\"),\n position(end[\"col\"], \"End column\"),\n );\n}\n\nfunction sarifArtifactUri(\n artifact: Record<string, unknown>,\n runContext: Record<string, unknown>,\n): string | null {\n const base = artifact[\"uriBaseId\"];\n // Native Semgrep uses %SRCROOT% without defining a base. Keep other references raw.\n if (\n artifact[\"index\"] !== undefined ||\n (base !== undefined &&\n (base !== \"%SRCROOT%\" ||\n record(runContext[\"originalUriBaseIds\"] ?? {}, \"SARIF URI bases\")[\n base\n ] !== undefined))\n )\n return null;\n const uri = requiredText(artifact[\"uri\"], \"Semgrep artifact URI\");\n // Semgrep's native formatter copies filesystem paths without URI encoding.\n return base === \"%SRCROOT%\" ? uri : decodeURIComponent(uri);\n}\n\nfunction primarySarifLocation(result: Record<string, unknown>) {\n const locations = array(result[\"locations\"] ?? [], \"Semgrep locations\");\n if (locations.length !== 1)\n throw new Error(\"Expected Semgrep's single primary result location.\");\n const location = record(locations[0], \"Location\");\n const physical = record(location[\"physicalLocation\"], \"Physical location\");\n const artifact = record(physical[\"artifactLocation\"], \"Artifact location\");\n return { physical, artifact };\n}\n\nfunction sarifIdentity(\n value: unknown,\n runContext: Record<string, unknown>,\n): string {\n const result = record(value, \"Semgrep result\");\n const supplied = ungatedText(\n record(result[\"fingerprints\"] ?? {}, \"Semgrep fingerprints\")[\n \"matchBasedId/v1\"\n ],\n );\n if (supplied) return stableId(\"semgrep\", [supplied]);\n const { physical, artifact } = primarySarifLocation(result);\n const uri = sarifArtifactUri(artifact, runContext);\n if (uri === null)\n throw new Error(\n \"Cannot derive a Semgrep CE identity from an indexed or unresolved base-relative artifact URI.\",\n );\n const region = record(physical[\"region\"], \"Semgrep region\");\n const line = position(region[\"startLine\"], \"Start line\");\n const column = position(region[\"startColumn\"] ?? 1, \"Start column\");\n return identity(\n requiredText(result[\"ruleId\"], \"Semgrep ruleId\"),\n uri,\n line,\n column,\n position(region[\"endLine\"] ?? line, \"End line\"),\n position(region[\"endColumn\"] ?? column, \"End column\"),\n );\n}\n\nexport function normalizeSemgrepFindings(\n input: unknown,\n options: SemgrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Semgrep report\");\n if (document[\"version\"] === \"2.1.0\" && document[\"runs\"] !== undefined)\n return normalizeSemgrepSarif(document, options, target);\n const repositoryUrl = sourceRepository(options);\n requiredText(document[\"version\"], \"Semgrep version\");\n if (array(document[\"errors\"] ?? [], \"Semgrep errors\").length)\n throw new Error(\n \"The Semgrep report contains scan errors; supply a successful report before importing findings.\",\n );\n const { results, paths: _paths, time: _time, ...context } = document;\n return normalizeRecords(\n array(results, \"Semgrep results\"),\n (value) =>\n projectNativeJsonResult(parseNativeJsonResult(value, \"Semgrep\"), {\n origin: \"Semgrep\",\n repositoryUrl,\n severity,\n reportContext: context,\n target,\n }),\n jsonIdentity,\n target,\n );\n}\n\nexport function normalizeSemgrepSarif(\n input: unknown,\n options: SemgrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const repositoryUrl = sourceRepository(options);\n const document = record(input, \"Semgrep SARIF\");\n if (document[\"version\"] !== \"2.1.0\")\n throw new Error(\"Expected Semgrep SARIF 2.1.0.\");\n const entries = array(document[\"runs\"], \"SARIF runs\").flatMap((value) => {\n const run = record(value, \"SARIF run\");\n for (const entry of array(\n run[\"versionControlProvenance\"] ?? [],\n \"Version control provenance\",\n )) {\n const declared = text(\n record(entry, \"Repository provenance\")[\"repositoryUri\"],\n );\n if (\n declared &&\n cloudRepositoryUrlKey(declared) !== cloudRepositoryUrlKey(repositoryUrl)\n )\n throw new Error(\n \"SARIF source repository does not match the declared source repository URL.\",\n );\n }\n const tool = record(run[\"tool\"], \"SARIF tool\");\n const driver = record(tool[\"driver\"], \"SARIF driver\");\n if (\n ![\"semgrep\", \"semgrep oss\", \"semgrep pro\"].includes(\n requiredText(driver[\"name\"], \"SARIF producer\").toLowerCase(),\n )\n )\n throw new Error(\"Expected a Semgrep SARIF producer.\");\n if (\n hasSarifExternalPropertyReferences(run[\"externalPropertyFileReferences\"])\n )\n throw new Error(\"Use a self-contained Semgrep SARIF report.\");\n for (const invocation of array(\n run[\"invocations\"] ?? [],\n \"Semgrep invocations\",\n )) {\n const details = record(invocation, \"Semgrep invocation\");\n if (details[\"executionSuccessful\"] === false)\n throw new Error(\"Semgrep SARIF contains an unsuccessful invocation.\");\n if (\n array(\n details[\"toolExecutionNotifications\"] ?? [],\n \"Semgrep scan notifications\",\n ).length\n )\n throw new Error(\"Semgrep SARIF contains scan error notifications.\");\n }\n return sarifRunResults(document, run, tool, driver, \"Semgrep\");\n });\n return normalizeRecords(\n entries,\n ({ result: value, context }) => {\n const result = record(value, \"Semgrep result\");\n const properties = record(\n result[\"properties\"] ?? {},\n \"Semgrep result properties\",\n );\n if (\n properties[\"exposure\"] != null ||\n properties[\"dependencyPaths\"] != null\n )\n throw new Error(\n \"This adapter supports Semgrep SAST; Supply Chain reports need separate qualification.\",\n );\n const ruleId = requiredText(result[\"ruleId\"], \"Semgrep ruleId\");\n const selectedRule = context.rulesById.get(ruleId) ?? undefined;\n if (context.rulesById.size > 0 && !selectedRule)\n throw new Error(\n \"Semgrep result must reference exactly one rule in its run.\",\n );\n const rule = selectedRule?.rule;\n validateSarifRuleReference(result, ruleId, selectedRule, \"Semgrep\");\n const { physical, artifact } = primarySarifLocation(result);\n const rawPath = sarifArtifactUri(artifact, context.runContext);\n const region = record(physical[\"region\"], \"Semgrep region\");\n const line = position(region[\"startLine\"], \"Start line\");\n const column = position(region[\"startColumn\"] ?? 1, \"Start column\");\n const endLine = position(region[\"endLine\"] ?? line, \"End line\");\n const endColumn = position(region[\"endColumn\"] ?? column, \"End column\");\n if (endLine < line || (endLine === line && endColumn < column))\n throw new Error(\"Semgrep source range ends before it starts.\");\n const message = record(result[\"message\"], \"Semgrep message\");\n const configuration = record(\n rule?.[\"defaultConfiguration\"] ?? {},\n \"Rule configuration\",\n );\n const level = text(result[\"level\"]) ?? text(configuration[\"level\"]);\n // SARIF collapses severity categories; retain its diagnostic level and all original metadata.\n const mappedSeverity =\n level === \"error\"\n ? \"high\"\n : level === \"warning\"\n ? \"medium\"\n : level === \"note\"\n ? \"low\"\n : \"unknown\";\n // Native %SRCROOT% values are filesystem paths; direct URIs can name other targets.\n const absoluteUri =\n artifact[\"uriBaseId\"] !== \"%SRCROOT%\" &&\n typeof artifact[\"uri\"] === \"string\" &&\n /^[a-z][a-z\\d+.-]*:/iu.test(artifact[\"uri\"]);\n const path =\n rawPath === null || absoluteUri ? null : relativePath(rawPath);\n return validateExternalEvidence(\n {\n title: ruleId,\n description:\n text(message[\"markdown\"]) ??\n messageText(message[\"text\"], \"Semgrep\"),\n severity: mappedSeverity,\n locations: path ? [{ path, line }] : [],\n details: {\n kind: \"sast\",\n repository: { url: repositoryUrl },\n scanner_origin: \"Semgrep\",\n rule: { id: ruleId },\n weakness_ids: weaknessIds(\n record(rule?.[\"properties\"] ?? {}, \"Rule properties\")[\"tags\"],\n ),\n code: {\n end_line: path ? endLine : null,\n snippet: ungatedText(\n record(region[\"snippet\"] ?? {}, \"Snippet\")[\"text\"],\n ),\n },\n source_status:\n Array.isArray(result[\"suppressions\"]) &&\n result[\"suppressions\"].some((value) => {\n const status = record(value, \"Suppression\")[\"status\"];\n return status === undefined || status === \"accepted\";\n })\n ? \"suppressed\"\n : null,\n },\n source_data: context.sourceData(result, rule),\n },\n target,\n );\n },\n ({ result, context }) => sarifIdentity(result, context.runContext),\n target,\n );\n}\n\nexport async function readSemgrepFindings(\n path: string,\n options: SemgrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeSemgrepFindings(await readScannerJson(path), options, target);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"semgrep-findings.js","sourceRoot":"","sources":["../src/semgrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,g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CAAC,MAAM,CAAC;YAChB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,2BAA2B;gBAC/C,MAAM,CAAC,QAAQ,CAAC,KAAK,qBAAqB,CAAC;YAC3C,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QACjB,OAAO,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,OAAO,GAAkC,EAAE,EAC3C,MAAM,GAAyB,OAAO;IAEtC,OAAO,wBAAwB,CAC7B,MAAM,iBAAiB,CAAC,IAAI,CAAC,EAC7B,OAAO,EACP,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { markPreviousCloudProjection } from \"./reader-selection.js\";\nimport {\n normalizeSemgrepPlatformFindings,\n isSemgrepPlatformFormat,\n semgrepPlatformLegacyFormat,\n semgrepPlatformFormat,\n} from \"./semgrep-platform-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n guardianSelectionFormat,\n normalizeGuardianSelection,\n} from \"./semgrep-guardian-findings.js\";\nimport { parseHostedScannerJson } from \"./hosted-scanner-http.js\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport {\n cloudRepositoryUrlKey,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type {\n ExternalFindings,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport {\n messageText,\n nativeResultPath,\n parseNativeJsonResult,\n position,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n ungatedText,\n weaknessIds,\n} from \"./native-json-findings.js\";\nimport {\n array,\n normalizeRecords,\n optionalArray,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n sarifRunRepositories,\n sarifRunResults,\n stableId,\n readSarifRuns,\n text,\n validateSarifRuleReference,\n} from \"./scanner-import.js\";\n\nexport interface SemgrepImportOptions {\n /** Independent source references from the SDK reader. */\n sourceRepositories?: readonly ExternalSourceRepository[];\n /** Source repository declared by the caller; never inferred from the destination. */\n sourceRepositoryUrl: string;\n}\n\nfunction sourceRepository(options: Partial<SemgrepImportOptions>): string {\n return sourceRepositoryUrl(options?.sourceRepositoryUrl, \"Semgrep\");\n}\n\nconst severityLevels = new Map([\n [\"CRITICAL\", \"critical\"],\n [\"HIGH\", \"high\"],\n [\"MEDIUM\", \"medium\"],\n [\"LOW\", \"low\"],\n [\"ERROR\", \"high\"],\n [\"WARNING\", \"medium\"],\n [\"INFO\", \"low\"],\n]);\n\nfunction severity(value: unknown): string {\n return typeof value === \"string\"\n ? (severityLevels.get(value) ?? \"unknown\")\n : \"unknown\";\n}\n\nfunction identity(\n rule: string,\n path: string,\n line: number,\n column: number,\n endLine: number,\n endColumn: number,\n): string {\n // CE omits fingerprints and source snippets. Its fallback is stable only while the range is stable.\n return stableId(\"semgrep-location\", [\n rule,\n path,\n line,\n column,\n endLine,\n endColumn,\n ]);\n}\n\nfunction jsonIdentity(value: unknown): string {\n const result = record(value, \"Semgrep result\");\n const extra = record(result[\"extra\"], \"Semgrep extra\");\n const supplied = ungatedText(extra[\"fingerprint\"]);\n if (supplied) return stableId(\"semgrep\", [supplied]);\n const start = record(result[\"start\"], \"Semgrep start\");\n const end = record(result[\"end\"], \"Semgrep end\");\n return identity(\n requiredText(result[\"check_id\"], \"Semgrep check_id\"),\n requiredText(result[\"path\"], \"Semgrep path\"),\n position(start[\"line\"], \"Start line\"),\n position(start[\"col\"], \"Start column\"),\n position(end[\"line\"], \"End line\"),\n position(end[\"col\"], \"End column\"),\n );\n}\n\nfunction sarifArtifactUri(\n artifact: Record<string, unknown>,\n runContext: Record<string, unknown>,\n): string | null {\n const base = artifact[\"uriBaseId\"];\n // Native Semgrep uses %SRCROOT% without defining a base. Keep other references raw.\n if (\n artifact[\"index\"] !== undefined ||\n (base !== undefined &&\n (base !== \"%SRCROOT%\" ||\n record(runContext[\"originalUriBaseIds\"] ?? {}, \"SARIF URI bases\")[\n base\n ] !== undefined))\n )\n return null;\n const uri = requiredText(artifact[\"uri\"], \"Semgrep artifact URI\");\n // Semgrep's native formatter copies filesystem paths without URI encoding.\n return base === \"%SRCROOT%\" ? uri : decodeURIComponent(uri);\n}\n\nfunction primarySarifLocation(result: Record<string, unknown>) {\n const locations = array(result[\"locations\"] ?? [], \"Semgrep locations\");\n if (locations.length !== 1)\n throw new Error(\"Expected Semgrep's single primary result location.\");\n const location = record(locations[0], \"Location\");\n const physical = record(location[\"physicalLocation\"], \"Physical location\");\n const artifact = record(physical[\"artifactLocation\"], \"Artifact location\");\n return { physical, artifact };\n}\n\nfunction sarifIdentity(\n value: unknown,\n runContext: Record<string, unknown>,\n): string {\n const result = record(value, \"Semgrep result\");\n const supplied = ungatedText(\n record(result[\"fingerprints\"] ?? {}, \"Semgrep fingerprints\")[\n \"matchBasedId/v1\"\n ],\n );\n if (supplied) return stableId(\"semgrep\", [supplied]);\n const { physical, artifact } = primarySarifLocation(result);\n const uri = sarifArtifactUri(artifact, runContext);\n if (uri === null)\n throw new Error(\n \"Cannot derive a Semgrep CE identity from an indexed or unresolved base-relative artifact URI.\",\n );\n const region = record(physical[\"region\"], \"Semgrep region\");\n const line = position(region[\"startLine\"], \"Start line\");\n const column = position(region[\"startColumn\"] ?? 1, \"Start column\");\n return identity(\n requiredText(result[\"ruleId\"], \"Semgrep ruleId\"),\n uri,\n line,\n column,\n position(region[\"endLine\"] ?? line, \"End line\"),\n position(region[\"endColumn\"] ?? column, \"End column\"),\n );\n}\n\nexport function normalizeSemgrepFindings(\n input: unknown,\n options: Partial<SemgrepImportOptions> = {},\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Semgrep report\");\n if (document[\"format\"] === guardianSelectionFormat) {\n return normalizeGuardianSelection(\n document,\n target,\n options.sourceRepositoryUrl,\n options.sourceRepositories,\n );\n }\n if (isSemgrepPlatformFormat(document[\"format\"])) {\n return normalizeSemgrepPlatformFindings(\n document,\n options?.sourceRepositoryUrl,\n target,\n options?.sourceRepositories,\n );\n }\n if (document[\"version\"] === \"2.1.0\" && document[\"runs\"] !== undefined)\n return normalizeSemgrepSarif(\n document,\n { ...options, sourceRepositoryUrl: options?.sourceRepositoryUrl ?? \"\" },\n target,\n );\n return normalizeSemgrepJson(document, options, target);\n}\n\nfunction nativeProjection(target: ExternalImportTarget, previous: boolean) {\n let changed = false;\n return {\n location(raw: string) {\n const oldPath = relativePath(raw);\n if (previous) return oldPath;\n // Semgrep retains its raw spelling; OpenGrep groups by the normalized path.\n const path = nativeResultPath(raw, oldPath) === null ? null : raw;\n if (path !== oldPath) changed = true;\n return path;\n },\n finish(findings: ExternalFindings, omittedExplanations = false) {\n if (target === \"cloud\" && (changed || omittedExplanations))\n markPreviousCloudProjection(findings);\n return findings;\n },\n };\n}\n\n/** @internal Rebuild the native JSON or SARIF that an earlier reader approved. */\nexport function normalizePreviousSemgrepFindings(\n input: unknown,\n options: Partial<SemgrepImportOptions>,\n): ExternalFindings {\n const document = record(input, \"Semgrep report\");\n return document[\"version\"] === \"2.1.0\" && document[\"runs\"] !== undefined\n ? normalizeSarif(document, options, \"cloud\", true)\n : normalizeSemgrepJson(document, options, \"cloud\", true);\n}\n\nfunction normalizeSemgrepJson(\n document: Record<string, unknown>,\n options: Partial<SemgrepImportOptions>,\n target: ExternalImportTarget,\n previous = false,\n): ExternalFindings {\n const repositoryUrl = sourceRepository(options);\n requiredText(document[\"version\"], \"Semgrep version\");\n const { results, paths: _paths, time: _time, ...context } = document;\n const omitExplanations = !previous && Object.hasOwn(context, \"explanations\");\n if (omitExplanations) delete context[\"explanations\"];\n const rows = array(results, \"Semgrep results\");\n if (!rows.length && document[\"errors\"] === undefined)\n throw new Error(\"An empty Semgrep report must include its errors array.\");\n if (optionalArray(document[\"errors\"], \"Semgrep errors\").length)\n throw new Error(\n \"The Semgrep report contains scan errors; supply a successful report before importing findings.\",\n );\n const projection = nativeProjection(target, previous);\n const findings = normalizeRecords(\n rows,\n (value) =>\n projectNativeJsonResult(\n parseNativeJsonResult(value, \"Semgrep\", projection.location),\n {\n origin: \"Semgrep\",\n repositoryUrl,\n severity,\n reportContext: context,\n target,\n },\n ),\n jsonIdentity,\n target,\n );\n return projection.finish(findings, omitExplanations);\n}\n\nexport function isSemgrepSarifDriver(name: string): boolean {\n return [\"semgrep\", \"semgrep oss\", \"semgrep pro\"].includes(name.toLowerCase());\n}\n\nexport function normalizeSemgrepSarif(\n input: unknown,\n options: SemgrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n return normalizeSarif(input, options, target);\n}\n\nfunction normalizeSarif(\n input: unknown,\n options: Partial<SemgrepImportOptions>,\n target: ExternalImportTarget,\n previous = false,\n): ExternalFindings {\n const repositoryUrl = sourceRepository(options);\n const repositoryKey = cloudRepositoryUrlKey(repositoryUrl);\n const verifiedUrls = new Set([repositoryUrl]);\n const entries = readSarifRuns(input, \"Semgrep\", (context) => {\n for (const { url: declared } of sarifRunRepositories(\n context.run,\n \"Semgrep\",\n )) {\n if (verifiedUrls.has(declared)) continue;\n if (cloudRepositoryUrlKey(declared) !== repositoryKey)\n throw new Error(\n \"SARIF source repository does not match the declared source repository URL.\",\n );\n verifiedUrls.add(declared);\n }\n if (\n !isSemgrepSarifDriver(\n requiredText(context.driver[\"name\"], \"SARIF producer\"),\n )\n )\n throw new Error(\"Expected a Semgrep SARIF producer.\");\n return sarifRunResults(context, \"Semgrep\");\n });\n const projection = nativeProjection(target, previous);\n const findings = normalizeRecords(\n entries,\n ({ result: value, context }) => {\n const result = record(value, \"Semgrep result\");\n const properties = record(\n result[\"properties\"] ?? {},\n \"Semgrep result properties\",\n );\n if (\n properties[\"exposure\"] != null ||\n properties[\"dependencyPaths\"] != null\n )\n throw new Error(\n \"This adapter supports Semgrep SAST; Supply Chain reports need separate qualification.\",\n );\n const ruleId = requiredText(result[\"ruleId\"], \"Semgrep ruleId\");\n const selectedRule = context.rulesById.get(ruleId) ?? undefined;\n if (context.rulesById.size > 0 && !selectedRule)\n throw new Error(\n \"Semgrep result must reference exactly one rule in its run.\",\n );\n const rule = selectedRule?.rule;\n validateSarifRuleReference(result, ruleId, selectedRule, \"Semgrep\");\n const { physical, artifact } = primarySarifLocation(result);\n const rawPath = sarifArtifactUri(artifact, context.runContext);\n const region = record(physical[\"region\"], \"Semgrep region\");\n const line = position(region[\"startLine\"], \"Start line\");\n const column = position(region[\"startColumn\"] ?? 1, \"Start column\");\n const endLine = position(region[\"endLine\"] ?? line, \"End line\");\n const endColumn = position(region[\"endColumn\"] ?? column, \"End column\");\n if (endLine < line || (endLine === line && endColumn < column))\n throw new Error(\"Semgrep source range ends before it starts.\");\n const message = record(result[\"message\"], \"Semgrep message\");\n const configuration = record(\n rule?.[\"defaultConfiguration\"] ?? {},\n \"Rule configuration\",\n );\n const level = text(result[\"level\"]) ?? text(configuration[\"level\"]);\n // SARIF collapses severity categories; retain its diagnostic level and all original metadata.\n const mappedSeverity =\n level === \"error\"\n ? \"high\"\n : level === \"warning\"\n ? \"medium\"\n : level === \"note\"\n ? \"low\"\n : \"unknown\";\n // Native %SRCROOT% values are filesystem paths; direct URIs can name other targets.\n const absoluteUri =\n artifact[\"uriBaseId\"] !== \"%SRCROOT%\" &&\n typeof artifact[\"uri\"] === \"string\" &&\n /^[a-z][a-z\\d+.-]*:/iu.test(artifact[\"uri\"]);\n const path =\n rawPath === null || absoluteUri ? null : projection.location(rawPath);\n return validateExternalEvidence(\n {\n title: ruleId,\n description:\n text(message[\"markdown\"]) ??\n messageText(message[\"text\"], \"Semgrep\"),\n severity: mappedSeverity,\n locations: path ? [{ path, line }] : [],\n details: {\n kind: \"sast\",\n repository: { url: repositoryUrl },\n scanner_origin: \"Semgrep\",\n rule: { id: ruleId },\n weakness_ids: weaknessIds(\n record(rule?.[\"properties\"] ?? {}, \"Rule properties\")[\"tags\"],\n ),\n code: {\n end_line: path ? endLine : null,\n snippet: ungatedText(\n record(region[\"snippet\"] ?? {}, \"Snippet\")[\"text\"],\n ),\n },\n source_status:\n Array.isArray(result[\"suppressions\"]) &&\n result[\"suppressions\"].some((value) => {\n const status = record(value, \"Suppression\")[\"status\"];\n return status === undefined || status === \"accepted\";\n })\n ? \"suppressed\"\n : null,\n },\n source_data: context.sourceData(result, rule),\n },\n target,\n );\n },\n ({ result, context }) => sarifIdentity(result, context.runContext),\n target,\n );\n return projection.finish(findings);\n}\n\n/** @internal Read the original file before resolving repository provenance. */\nexport async function readSemgrepReport(path: string): Promise<unknown> {\n return readScannerJson(path, (json) => {\n // Pick a parser before allocating the findings array. Verify the root:\n // the member can be nested in a native report or escaped in a Platform one.\n const parser = /\"format\"\\s*:\\s*\"semgrep-platform-findings\\/v[12]\"/u.test(\n json,\n )\n ? parseHostedScannerJson\n : JSON.parse;\n const parsed: unknown = parser(json);\n const requiredParser =\n isRecord(parsed) &&\n (parsed[\"format\"] === semgrepPlatformLegacyFormat ||\n parsed[\"format\"] === semgrepPlatformFormat)\n ? parseHostedScannerJson\n : JSON.parse;\n return parser === requiredParser ? parsed : requiredParser(json);\n });\n}\n\nexport async function readSemgrepFindings(\n path: string,\n options: Partial<SemgrepImportOptions> = {},\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeSemgrepFindings(\n await readSemgrepReport(path),\n options,\n target,\n );\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ExternalImportTarget } from "./external-import-contract.js";
|
|
2
|
+
import type { ExternalFinding, ExternalSourceRepository } from "./external-findings.js";
|
|
3
|
+
export declare const guardianSelectionFormat = "semgrep-guardian-selection/v1";
|
|
4
|
+
export declare const guardianFindingId: RegExp;
|
|
5
|
+
export declare function guardianFindingRepository({ source_finding_id, evidence }: ExternalFinding, target: ExternalImportTarget): string | undefined;
|
|
6
|
+
type GuardianTool = "get_semgrep_sast_findings" | "get_semgrep_supply_chain_findings";
|
|
7
|
+
/** The request passed to the signed-in Guardian MCP client. */
|
|
8
|
+
interface GuardianRequest {
|
|
9
|
+
name: GuardianTool;
|
|
10
|
+
arguments: {
|
|
11
|
+
deployment_name: string;
|
|
12
|
+
repository_name: string;
|
|
13
|
+
ref: string;
|
|
14
|
+
states?: string[] | null;
|
|
15
|
+
severities?: string[] | null;
|
|
16
|
+
max_num_findings?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Use the caller's connected Guardian MCP client. Only selected rows enter the saved capture. */
|
|
20
|
+
export declare function collectSelectedSemgrepGuardianFindings(selection: {
|
|
21
|
+
request: GuardianRequest;
|
|
22
|
+
findingIds: readonly string[];
|
|
23
|
+
sourceRepositoryUrl: string;
|
|
24
|
+
}, dependencies: {
|
|
25
|
+
callTool: (request: GuardianRequest) => Promise<unknown>;
|
|
26
|
+
environment?: NodeJS.ProcessEnv;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
format: string;
|
|
29
|
+
sourceRepositoryUrl: string;
|
|
30
|
+
request: GuardianRequest;
|
|
31
|
+
findingIds: string[];
|
|
32
|
+
structuredContent: {
|
|
33
|
+
findings: Record<string, unknown>[];
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
36
|
+
export declare function normalizeGuardianSelection(document: Record<string, unknown>, target: ExternalImportTarget, declaredUrl?: string, references?: readonly ExternalSourceRepository[]): import("./external-findings.js").ExternalFindings;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=semgrep-guardian-findings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-guardian-findings.d.ts","sourceRoot":"","sources":["../src/semgrep-guardian-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAkBhC,eAAO,MAAM,uBAAuB,kCAAkC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,QAAqC,CAAC;AA0BpE,wBAAgB,yBAAyB,CACvC,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE,eAAe,EAChD,MAAM,EAAE,oBAAoB,sBAqB7B;AAED,KAAK,YAAY,GACf,2BAA2B,GAAG,mCAAmC,CAAC;AAEpE,+DAA+D;AAC/D,UAAU,eAAe;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE;QACT,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAwED,kGAAkG;AAClG,wBAAsB,sCAAsC,CAC1D,SAAS,EAAE;IACT,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;CAC7B,EACD,YAAY,EAAE;IACZ,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACjC;;;;;;QAgCG,QAAQ;;GAGb;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,MAAM,EAAE,oBAAoB,EAC5B,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,GAAE,SAAS,wBAAwB,EAAO,qDAmErD"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
|
+
import { CodexSecurityError } from "./errors.js";
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
import { array, normalizeRecords, record, requiredText, scannerSeverity, stableId, text, } from "./scanner-import.js";
|
|
5
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
6
|
+
import { platformLocationPath, requireSemgrepFullRef, selectionRepository, } from "./semgrep-platform-findings.js";
|
|
7
|
+
export const guardianSelectionFormat = "semgrep-guardian-selection/v1";
|
|
8
|
+
export const guardianFindingId = /^semgrep-guardian:[0-9a-f]{64}$/u;
|
|
9
|
+
function guardianScope(data) {
|
|
10
|
+
const tool = data["tool"];
|
|
11
|
+
if (tool !== "get_semgrep_sast_findings" &&
|
|
12
|
+
tool !== "get_semgrep_supply_chain_findings")
|
|
13
|
+
throw new Error("Select a Guardian SAST or Supply Chain findings tool.");
|
|
14
|
+
const deployment = requiredText(data["deployment"], "Guardian deployment");
|
|
15
|
+
const repository = requiredText(data["repository"], "Guardian repository");
|
|
16
|
+
const ref = requiredText(data["ref"], "Guardian Git ref");
|
|
17
|
+
requireSemgrepFullRef(ref);
|
|
18
|
+
return { tool, deployment, repository, ref };
|
|
19
|
+
}
|
|
20
|
+
function guardianId(scope, id) {
|
|
21
|
+
return stableId("semgrep-guardian", [
|
|
22
|
+
scope.deployment,
|
|
23
|
+
scope.repository,
|
|
24
|
+
scope.tool,
|
|
25
|
+
scope.ref,
|
|
26
|
+
requiredText(id, "Guardian finding ID"),
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
export function guardianFindingRepository({ source_finding_id, evidence }, target) {
|
|
30
|
+
const data = evidence.source_data ?? {};
|
|
31
|
+
const generated = guardianFindingId.test(source_finding_id);
|
|
32
|
+
if (data["format"] !== guardianSelectionFormat && !generated)
|
|
33
|
+
return;
|
|
34
|
+
const row = record(data["finding"], "Original Guardian finding");
|
|
35
|
+
const scope = guardianScope(data);
|
|
36
|
+
requireGuardianRowScope(scope, row);
|
|
37
|
+
if (evidence.branch != null && evidence.branch !== scope.ref)
|
|
38
|
+
throw new CodexSecurityError("The Guardian finding branch does not match the selected ref.");
|
|
39
|
+
if (source_finding_id !== guardianId(scope, row["id"]))
|
|
40
|
+
throw new CodexSecurityError("The normalized finding ID does not match the original Guardian finding.");
|
|
41
|
+
return declaredScannerRepositoryUrl(data["sourceRepositoryUrl"], "Guardian", target);
|
|
42
|
+
}
|
|
43
|
+
function selectionScope(request, findingIds) {
|
|
44
|
+
const tool = record(request, "Guardian tool request");
|
|
45
|
+
const args = record(tool["arguments"], "Guardian tool arguments");
|
|
46
|
+
const scope = guardianScope({
|
|
47
|
+
tool: tool["name"],
|
|
48
|
+
deployment: args["deployment_name"],
|
|
49
|
+
repository: args["repository_name"],
|
|
50
|
+
ref: args["ref"],
|
|
51
|
+
});
|
|
52
|
+
const ids = new Set(array(findingIds, "Guardian finding IDs").map((id) => requiredText(id, "Guardian finding ID")));
|
|
53
|
+
if (!ids.size)
|
|
54
|
+
throw new Error("Select at least one Guardian finding ID.");
|
|
55
|
+
return { ...scope, ids };
|
|
56
|
+
}
|
|
57
|
+
function requireGuardianRowScope(scope, row) {
|
|
58
|
+
const id = row["id"];
|
|
59
|
+
const repository = record(row["repository"], "Guardian finding repository");
|
|
60
|
+
if (repository["name"] !== scope.repository ||
|
|
61
|
+
(row["ref"] != null && row["ref"] !== scope.ref))
|
|
62
|
+
throw new Error(`Guardian finding ${id} does not match the selected repository and ref.`);
|
|
63
|
+
const expected = scope.tool === "get_semgrep_sast_findings" ? "sast" : "sca";
|
|
64
|
+
if (row["issueType"] != null &&
|
|
65
|
+
text(row["issueType"])
|
|
66
|
+
?.toLowerCase()
|
|
67
|
+
.replace(/^issue_type_/u, "") !== expected)
|
|
68
|
+
throw new Error(`Guardian finding ${id} does not match the selected product.`);
|
|
69
|
+
}
|
|
70
|
+
function selectedRows(scope, structuredContent) {
|
|
71
|
+
const { findings } = record(structuredContent, "Guardian structuredContent");
|
|
72
|
+
const rows = new Map();
|
|
73
|
+
for (const row of array(findings ?? [], "Guardian findings")) {
|
|
74
|
+
if (!isRecord(row) ||
|
|
75
|
+
typeof row["id"] !== "string" ||
|
|
76
|
+
!scope.ids.has(row["id"]))
|
|
77
|
+
continue;
|
|
78
|
+
const id = row["id"];
|
|
79
|
+
if (rows.has(id))
|
|
80
|
+
throw new Error(`Guardian returned duplicate finding ID ${id}.`);
|
|
81
|
+
requireGuardianRowScope(scope, row);
|
|
82
|
+
rows.set(id, row);
|
|
83
|
+
}
|
|
84
|
+
return Array.from(scope.ids, (id) => {
|
|
85
|
+
const row = rows.get(id);
|
|
86
|
+
if (!row)
|
|
87
|
+
throw new Error(`Guardian did not return selected finding ${id}.`);
|
|
88
|
+
return row;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Use the caller's connected Guardian MCP client. Only selected rows enter the saved capture. */
|
|
92
|
+
export async function collectSelectedSemgrepGuardianFindings(selection, dependencies) {
|
|
93
|
+
const query = structuredClone(selection.request);
|
|
94
|
+
const scope = selectionScope(query, selection.findingIds);
|
|
95
|
+
const sourceRepositoryUrl = declaredScannerRepositoryUrl(selection.sourceRepositoryUrl, "Guardian", "local");
|
|
96
|
+
const result = record(await dependencies.callTool(query), "Guardian MCP result");
|
|
97
|
+
if (result["isError"]) {
|
|
98
|
+
const content = result["content"];
|
|
99
|
+
const messages = Array.isArray(content)
|
|
100
|
+
? content
|
|
101
|
+
.map((part) => isRecord(part) && part["type"] === "text"
|
|
102
|
+
? text(part["text"])
|
|
103
|
+
: null)
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
: [];
|
|
106
|
+
throw new Error(messages.join("\n") || "Guardian MCP request failed.");
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
format: guardianSelectionFormat,
|
|
110
|
+
sourceRepositoryUrl,
|
|
111
|
+
request: query,
|
|
112
|
+
findingIds: [...scope.ids],
|
|
113
|
+
structuredContent: {
|
|
114
|
+
findings: selectedRows(scope, result["structuredContent"]),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function normalizeGuardianSelection(document, target, declaredUrl, references = []) {
|
|
119
|
+
// Guardian returns a repository name. The caller supplies its verified SCM mapping.
|
|
120
|
+
const url = declaredScannerRepositoryUrl(document["sourceRepositoryUrl"], "Guardian", target);
|
|
121
|
+
const repositoryBinding = selectionRepository(url, references, target);
|
|
122
|
+
if (declaredUrl !== undefined &&
|
|
123
|
+
repositoryBinding.key(declaredScannerRepositoryUrl(declaredUrl, "Guardian", target)) !== repositoryBinding.key(url))
|
|
124
|
+
throw new Error("Guardian selection does not match the declared source repository URL.");
|
|
125
|
+
const scope = selectionScope(document["request"], document["findingIds"]);
|
|
126
|
+
const { tool, deployment, repository, ref } = scope;
|
|
127
|
+
return normalizeRecords(selectedRows(scope, document["structuredContent"]), (finding) => {
|
|
128
|
+
const rule = text(finding["rulePath"]);
|
|
129
|
+
const message = text(finding["message"]);
|
|
130
|
+
const path = platformLocationPath(finding["filePath"]);
|
|
131
|
+
const line = finding["line"];
|
|
132
|
+
return validateExternalEvidence({
|
|
133
|
+
title: rule ?? message ?? `Semgrep finding ${finding["id"]}`,
|
|
134
|
+
description: message,
|
|
135
|
+
severity: scannerSeverity(text(finding["severity"])
|
|
136
|
+
?.toLowerCase()
|
|
137
|
+
.replace(/^severity_/u, "")),
|
|
138
|
+
branch: ref,
|
|
139
|
+
locations: path
|
|
140
|
+
? [{ path, line: line === 0 ? null : (line ?? null) }]
|
|
141
|
+
: [],
|
|
142
|
+
...(tool === "get_semgrep_sast_findings" && {
|
|
143
|
+
details: {
|
|
144
|
+
kind: "sast",
|
|
145
|
+
scanner_origin: "Semgrep",
|
|
146
|
+
repository: { name: repository, url },
|
|
147
|
+
rule: rule ? { id: rule } : null,
|
|
148
|
+
source_status: text(finding["status"]),
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
source_data: {
|
|
152
|
+
format: guardianSelectionFormat,
|
|
153
|
+
tool,
|
|
154
|
+
deployment,
|
|
155
|
+
repository,
|
|
156
|
+
ref,
|
|
157
|
+
sourceRepositoryUrl: url,
|
|
158
|
+
finding,
|
|
159
|
+
},
|
|
160
|
+
}, target);
|
|
161
|
+
},
|
|
162
|
+
// Guardian's string ID has not been verified against Web API occurrence IDs.
|
|
163
|
+
(finding) => guardianId(scope, finding["id"]), target, { report: { format: guardianSelectionFormat, repositoryUrl: url } });
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=semgrep-guardian-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-guardian-findings.js","sourceRoot":"","sources":["../src/semgrep-guardian-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAKjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AAExC,MAAM,CAAC,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAEpE,SAAS,aAAa,CAAC,IAA6B;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,IACE,IAAI,KAAK,2BAA2B;QACpC,IAAI,KAAK,mCAAmC;QAE5C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC3E,MAAM,G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AE,MAAM,EAAE,EAAE,MAAM,EAAE,uBAAuB,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,CACpE,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ExternalImportTarget,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type {\n ExternalFinding,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n record,\n requiredText,\n scannerSeverity,\n stableId,\n text,\n} from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\nimport {\n platformLocationPath,\n requireSemgrepFullRef,\n selectionRepository,\n} from \"./semgrep-platform-findings.js\";\n\nexport const guardianSelectionFormat = \"semgrep-guardian-selection/v1\";\n\nexport const guardianFindingId = /^semgrep-guardian:[0-9a-f]{64}$/u;\n\nfunction guardianScope(data: Record<string, unknown>) {\n const tool = data[\"tool\"];\n if (\n tool !== \"get_semgrep_sast_findings\" &&\n tool !== \"get_semgrep_supply_chain_findings\"\n )\n throw new Error(\"Select a Guardian SAST or Supply Chain findings tool.\");\n const deployment = requiredText(data[\"deployment\"], \"Guardian deployment\");\n const repository = requiredText(data[\"repository\"], \"Guardian repository\");\n const ref = requiredText(data[\"ref\"], \"Guardian Git ref\");\n requireSemgrepFullRef(ref);\n return { tool, deployment, repository, ref };\n}\n\nfunction guardianId(scope: ReturnType<typeof guardianScope>, id: unknown) {\n return stableId(\"semgrep-guardian\", [\n scope.deployment,\n scope.repository,\n scope.tool,\n scope.ref,\n requiredText(id, \"Guardian finding ID\"),\n ]);\n}\n\nexport function guardianFindingRepository(\n { source_finding_id, evidence }: ExternalFinding,\n target: ExternalImportTarget,\n) {\n const data = evidence.source_data ?? {};\n const generated = guardianFindingId.test(source_finding_id);\n if (data[\"format\"] !== guardianSelectionFormat && !generated) return;\n const row = record(data[\"finding\"], \"Original Guardian finding\");\n const scope = guardianScope(data);\n requireGuardianRowScope(scope, row);\n if (evidence.branch != null && evidence.branch !== scope.ref)\n throw new CodexSecurityError(\n \"The Guardian finding branch does not match the selected ref.\",\n );\n if (source_finding_id !== guardianId(scope, row[\"id\"]))\n throw new CodexSecurityError(\n \"The normalized finding ID does not match the original Guardian finding.\",\n );\n return declaredScannerRepositoryUrl(\n data[\"sourceRepositoryUrl\"],\n \"Guardian\",\n target,\n );\n}\n\ntype GuardianTool =\n \"get_semgrep_sast_findings\" | \"get_semgrep_supply_chain_findings\";\n\n/** The request passed to the signed-in Guardian MCP client. */\ninterface GuardianRequest {\n name: GuardianTool;\n arguments: {\n deployment_name: string;\n repository_name: string;\n ref: string;\n states?: string[] | null;\n severities?: string[] | null;\n max_num_findings?: number;\n };\n}\n\nfunction selectionScope(request: unknown, findingIds: unknown) {\n const tool = record(request, \"Guardian tool request\");\n const args = record(tool[\"arguments\"], \"Guardian tool arguments\");\n const scope = guardianScope({\n tool: tool[\"name\"],\n deployment: args[\"deployment_name\"],\n repository: args[\"repository_name\"],\n ref: args[\"ref\"],\n });\n const ids = new Set(\n array(findingIds, \"Guardian finding IDs\").map((id) =>\n requiredText(id, \"Guardian finding ID\"),\n ),\n );\n if (!ids.size) throw new Error(\"Select at least one Guardian finding ID.\");\n return { ...scope, ids };\n}\n\nfunction requireGuardianRowScope(\n scope: ReturnType<typeof guardianScope>,\n row: Record<string, unknown>,\n): void {\n const id = row[\"id\"];\n const repository = record(row[\"repository\"], \"Guardian finding repository\");\n if (\n repository[\"name\"] !== scope.repository ||\n (row[\"ref\"] != null && row[\"ref\"] !== scope.ref)\n )\n throw new Error(\n `Guardian finding ${id} does not match the selected repository and ref.`,\n );\n const expected = scope.tool === \"get_semgrep_sast_findings\" ? \"sast\" : \"sca\";\n if (\n row[\"issueType\"] != null &&\n text(row[\"issueType\"])\n ?.toLowerCase()\n .replace(/^issue_type_/u, \"\") !== expected\n )\n throw new Error(\n `Guardian finding ${id} does not match the selected product.`,\n );\n}\n\nfunction selectedRows(\n scope: ReturnType<typeof selectionScope>,\n structuredContent: unknown,\n) {\n const { findings } = record(structuredContent, \"Guardian structuredContent\");\n const rows = new Map<string, Record<string, unknown>>();\n for (const row of array(findings ?? [], \"Guardian findings\")) {\n if (\n !isRecord(row) ||\n typeof row[\"id\"] !== \"string\" ||\n !scope.ids.has(row[\"id\"])\n )\n continue;\n const id = row[\"id\"];\n if (rows.has(id))\n throw new Error(`Guardian returned duplicate finding ID ${id}.`);\n requireGuardianRowScope(scope, row);\n rows.set(id, row);\n }\n return Array.from(scope.ids, (id) => {\n const row = rows.get(id);\n if (!row)\n throw new Error(`Guardian did not return selected finding ${id}.`);\n return row;\n });\n}\n\n/** Use the caller's connected Guardian MCP client. Only selected rows enter the saved capture. */\nexport async function collectSelectedSemgrepGuardianFindings(\n selection: {\n request: GuardianRequest;\n findingIds: readonly string[];\n sourceRepositoryUrl: string;\n },\n dependencies: {\n callTool: (request: GuardianRequest) => Promise<unknown>;\n environment?: NodeJS.ProcessEnv;\n },\n) {\n const query = structuredClone(selection.request);\n const scope = selectionScope(query, selection.findingIds);\n const sourceRepositoryUrl = declaredScannerRepositoryUrl(\n selection.sourceRepositoryUrl,\n \"Guardian\",\n \"local\",\n );\n const result = record(\n await dependencies.callTool(query),\n \"Guardian MCP result\",\n );\n if (result[\"isError\"]) {\n const content = result[\"content\"];\n const messages = Array.isArray(content)\n ? content\n .map((part: unknown) =>\n isRecord(part) && part[\"type\"] === \"text\"\n ? text(part[\"text\"])\n : null,\n )\n .filter(Boolean)\n : [];\n throw new Error(messages.join(\"\\n\") || \"Guardian MCP request failed.\");\n }\n return {\n format: guardianSelectionFormat,\n sourceRepositoryUrl,\n request: query,\n findingIds: [...scope.ids],\n structuredContent: {\n findings: selectedRows(scope, result[\"structuredContent\"]),\n },\n };\n}\n\nexport function normalizeGuardianSelection(\n document: Record<string, unknown>,\n target: ExternalImportTarget,\n declaredUrl?: string,\n references: readonly ExternalSourceRepository[] = [],\n) {\n // Guardian returns a repository name. The caller supplies its verified SCM mapping.\n const url = declaredScannerRepositoryUrl(\n document[\"sourceRepositoryUrl\"],\n \"Guardian\",\n target,\n );\n const repositoryBinding = selectionRepository(url, references, target);\n if (\n declaredUrl !== undefined &&\n repositoryBinding.key(\n declaredScannerRepositoryUrl(declaredUrl, \"Guardian\", target),\n ) !== repositoryBinding.key(url)\n )\n throw new Error(\n \"Guardian selection does not match the declared source repository URL.\",\n );\n const scope = selectionScope(document[\"request\"], document[\"findingIds\"]);\n const { tool, deployment, repository, ref } = scope;\n return normalizeRecords(\n selectedRows(scope, document[\"structuredContent\"]),\n (finding) => {\n const rule = text(finding[\"rulePath\"]);\n const message = text(finding[\"message\"]);\n const path = platformLocationPath(finding[\"filePath\"]);\n const line = finding[\"line\"];\n return validateExternalEvidence(\n {\n title: rule ?? message ?? `Semgrep finding ${finding[\"id\"]}`,\n description: message,\n severity: scannerSeverity(\n text(finding[\"severity\"])\n ?.toLowerCase()\n .replace(/^severity_/u, \"\"),\n ),\n branch: ref,\n locations: path\n ? [{ path, line: line === 0 ? null : (line ?? null) }]\n : [],\n ...(tool === \"get_semgrep_sast_findings\" && {\n details: {\n kind: \"sast\",\n scanner_origin: \"Semgrep\",\n repository: { name: repository, url },\n rule: rule ? { id: rule } : null,\n source_status: text(finding[\"status\"]),\n },\n }),\n source_data: {\n format: guardianSelectionFormat,\n tool,\n deployment,\n repository,\n ref,\n sourceRepositoryUrl: url,\n finding,\n },\n },\n target,\n );\n },\n // Guardian's string ID has not been verified against Web API occurrence IDs.\n (finding) => guardianId(scope, finding[\"id\"]),\n target,\n { report: { format: guardianSelectionFormat, repositoryUrl: url } },\n );\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ExternalSourceRepository } from "./external-findings.js";
|
|
2
|
+
import { type HostedScannerHttpOptions } from "./hosted-scanner-http.js";
|
|
3
|
+
import { semgrepPlatformFormat, SEMGREP_PLATFORM_PRODUCTS, type SemgrepPlatformProduct, type SemgrepPlatformScope } from "./semgrep-platform-findings.js";
|
|
4
|
+
export { SEMGREP_PLATFORM_PRODUCTS };
|
|
5
|
+
export interface SemgrepPlatformOptions {
|
|
6
|
+
deployment: string;
|
|
7
|
+
project: string;
|
|
8
|
+
ref: string;
|
|
9
|
+
product?: SemgrepPlatformProduct;
|
|
10
|
+
sourceRepositoryUrl?: string;
|
|
11
|
+
sourceRepositories?: readonly ExternalSourceRepository[];
|
|
12
|
+
token?: string;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
export interface SemgrepPlatformReport extends SemgrepPlatformScope {
|
|
16
|
+
/** The original transport address when the provider supplied an SSH repository. */
|
|
17
|
+
nativeProjectUrl?: string;
|
|
18
|
+
/** The operator's binding when the native URL is missing or uses SSH. */
|
|
19
|
+
sourceRepositoryUrl?: string;
|
|
20
|
+
format: typeof semgrepPlatformFormat;
|
|
21
|
+
findingCount: number;
|
|
22
|
+
findings: string[];
|
|
23
|
+
repositoryAliases: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function collectSemgrepPlatformFindings(options: SemgrepPlatformOptions, dependencies?: HostedScannerHttpOptions): Promise<SemgrepPlatformReport>;
|
|
26
|
+
//# sourceMappingURL=semgrep-platform-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-platform-collector.d.ts","sourceRoot":"","sources":["../src/semgrep-platform-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,qBAAqB,EAOrB,yBAAyB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IACjE,mFAAmF;IACnF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,qBAAqB,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,sBAAsB,EAC/B,YAAY,GAAE,wBAA6B,GAC1C,OAAO,CAAC,qBAAqB,CAAC,CA6IhC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { snapshotSourceRepositories, } from "./external-findings.js";
|
|
2
|
+
import { hostedScannerToken, hostedRepositoryUrl, hostedScannerHttp, } from "./hosted-scanner-http.js";
|
|
3
|
+
import { checkSemgrepPlatformRow, projectAliases, responseRecord, semgrepPlatformFormat, selectionRepository, semgrepNativeProjectUrl, semgrepProjectUrlEvidence, semgrepPlatformId, semgrepPlatformIdOrUndefined, stringifySemgrepFinding, SEMGREP_PLATFORM_PRODUCTS, } from "./semgrep-platform-findings.js";
|
|
4
|
+
import { array, requiredText, stableId, text } from "./scanner-import.js";
|
|
5
|
+
export { SEMGREP_PLATFORM_PRODUCTS };
|
|
6
|
+
export async function collectSemgrepPlatformFindings(options, dependencies = {}) {
|
|
7
|
+
const environment = dependencies.environment ?? process.env;
|
|
8
|
+
const token = requiredText(hostedScannerToken(environment, "SEMGREP_APP_TOKEN", options.token, "https://semgrep.dev", "SEMGREP_URL", "SEMGREP_APP_URL"), "Semgrep Web API token (SEMGREP_APP_TOKEN)");
|
|
9
|
+
const { getJson, signal } = hostedScannerHttp(dependencies, options.signal);
|
|
10
|
+
const deployment = requiredText(options.deployment, "Semgrep deployment");
|
|
11
|
+
const name = requiredText(options.project, "Semgrep project name");
|
|
12
|
+
if (deployment.includes("/") ||
|
|
13
|
+
[deployment, name].some((part) => part === "." || part === ".."))
|
|
14
|
+
throw new Error("Invalid Semgrep deployment slug or project name.");
|
|
15
|
+
const ref = requiredText(options.ref, "Semgrep ref");
|
|
16
|
+
const { sourceRepositoryUrl } = options;
|
|
17
|
+
const sourceRepositories = snapshotSourceRepositories(options.sourceRepositories);
|
|
18
|
+
const product = options.product ?? "sast";
|
|
19
|
+
if (!SEMGREP_PLATFORM_PRODUCTS.includes(product))
|
|
20
|
+
throw new Error("Select a Semgrep Platform product: sast, sca or ai_sast.");
|
|
21
|
+
const base = `https://semgrep.dev/api/v1/deployments/${encodeURIComponent(deployment)}`;
|
|
22
|
+
const get = async (url) => responseRecord(await getJson(url, `Bearer ${token}`), "Semgrep API response");
|
|
23
|
+
const lookup = await get(new URL(`${base}/projects/${encodeURIComponent(name)}`));
|
|
24
|
+
const native = responseRecord(lookup["project"], "Semgrep project");
|
|
25
|
+
if (native["name"] !== name)
|
|
26
|
+
throw new Error("Semgrep returned a different project than requested.");
|
|
27
|
+
const nativeUrl = semgrepNativeProjectUrl(native["url"], sourceRepositories);
|
|
28
|
+
const mappedUrl = hostedRepositoryUrl(sourceRepositoryUrl ?? nativeUrl, "Semgrep project repository");
|
|
29
|
+
const url = nativeUrl ?? mappedUrl;
|
|
30
|
+
const source = selectionRepository(url, sourceRepositories);
|
|
31
|
+
if (source.key(mappedUrl) !== source.key(url))
|
|
32
|
+
throw new Error("Semgrep project does not match the selected source repository URL.");
|
|
33
|
+
const project = { id: semgrepPlatformId(native["id"]), name, url };
|
|
34
|
+
const scope = { deployment, project, ref, product };
|
|
35
|
+
const endpoint = new URL(`${base}/findings`);
|
|
36
|
+
const pageSize = 3000;
|
|
37
|
+
endpoint.search = new URLSearchParams({
|
|
38
|
+
repository_ids: project.id,
|
|
39
|
+
issue_type: product,
|
|
40
|
+
ref,
|
|
41
|
+
dedup: "false",
|
|
42
|
+
page_size: String(pageSize),
|
|
43
|
+
}).toString();
|
|
44
|
+
const names = projectAliases(name, url, sourceRepositories);
|
|
45
|
+
const witnessed = new Set();
|
|
46
|
+
const verified = {
|
|
47
|
+
has: (label) => names.has(label) || witnessed.has(label),
|
|
48
|
+
};
|
|
49
|
+
const observed = new Set();
|
|
50
|
+
async function readPage(page, collecting = true) {
|
|
51
|
+
endpoint.searchParams.set("page", String(page));
|
|
52
|
+
const document = await get(new URL(endpoint));
|
|
53
|
+
return array(document["findings"], "Semgrep findings").map((entry) => {
|
|
54
|
+
const finding = responseRecord(entry, "Semgrep finding");
|
|
55
|
+
const repository = responseRecord(finding["repository"] ?? {}, "Semgrep finding repository");
|
|
56
|
+
const label = text(repository["name"]);
|
|
57
|
+
if (collecting && label)
|
|
58
|
+
observed.add(label);
|
|
59
|
+
checkSemgrepPlatformRow(finding, scope, collecting ? observed : verified, source);
|
|
60
|
+
if (collecting &&
|
|
61
|
+
label &&
|
|
62
|
+
(repository["id"] != null || text(repository["url"])))
|
|
63
|
+
witnessed.add(label);
|
|
64
|
+
const raw = JSON.stringify(finding);
|
|
65
|
+
return {
|
|
66
|
+
key: semgrepPlatformIdOrUndefined(finding["id"]) ??
|
|
67
|
+
stringifySemgrepFinding(finding),
|
|
68
|
+
raw,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const pageId = (batch) => stableId("page", batch.map((row) => row.key).sort());
|
|
73
|
+
const findings = [];
|
|
74
|
+
const previousKeys = new Set();
|
|
75
|
+
let firstPage;
|
|
76
|
+
for (let page = 0;; page++) {
|
|
77
|
+
const batch = await readPage(page);
|
|
78
|
+
// Compare only with prior pages; same-page ambiguities are reported per finding on import.
|
|
79
|
+
if (batch.some((row) => previousKeys.has(row.key)))
|
|
80
|
+
throw new Error("Semgrep Platform repeated findings across pages; retry the collection.");
|
|
81
|
+
for (const row of batch)
|
|
82
|
+
findings.push(row.raw);
|
|
83
|
+
if (batch.length < pageSize)
|
|
84
|
+
break;
|
|
85
|
+
for (const row of batch)
|
|
86
|
+
previousKeys.add(row.key);
|
|
87
|
+
if (page === 0)
|
|
88
|
+
firstPage = pageId(batch);
|
|
89
|
+
}
|
|
90
|
+
// A name-only finding can precede the row that binds this label to the project.
|
|
91
|
+
for (const label of observed) {
|
|
92
|
+
if (!verified.has(label))
|
|
93
|
+
throw new Error(`Semgrep finding repository name "${label}" has no matching project name, repository ID or URL.`);
|
|
94
|
+
}
|
|
95
|
+
// Offset pagination can skip a row if the first page changes between reads.
|
|
96
|
+
if (firstPage && firstPage !== pageId(await readPage(0, false)))
|
|
97
|
+
throw new Error("Semgrep Platform findings changed across pages; retry the collection.");
|
|
98
|
+
signal?.throwIfAborted();
|
|
99
|
+
return {
|
|
100
|
+
format: semgrepPlatformFormat,
|
|
101
|
+
...scope,
|
|
102
|
+
...semgrepProjectUrlEvidence(native["url"], nativeUrl, sourceRepositoryUrl),
|
|
103
|
+
repositoryAliases: [...observed].sort(),
|
|
104
|
+
findingCount: findings.length,
|
|
105
|
+
findings,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=semgrep-platform-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-platform-collector.js","sourceRoot":"","sources":["../src/semgrep-platform-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,mBA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ourceRepositories,\n type ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport {\n hostedScannerToken,\n hostedRepositoryUrl,\n hostedScannerHttp,\n type HostedScannerHttpOptions,\n} from \"./hosted-scanner-http.js\";\nimport {\n checkSemgrepPlatformRow,\n projectAliases,\n responseRecord,\n semgrepPlatformFormat,\n selectionRepository,\n semgrepNativeProjectUrl,\n semgrepProjectUrlEvidence,\n semgrepPlatformId,\n semgrepPlatformIdOrUndefined,\n stringifySemgrepFinding,\n SEMGREP_PLATFORM_PRODUCTS,\n type SemgrepPlatformProduct,\n type SemgrepPlatformScope,\n} from \"./semgrep-platform-findings.js\";\nimport { array, requiredText, stableId, text } from \"./scanner-import.js\";\n\nexport { SEMGREP_PLATFORM_PRODUCTS };\n\nexport interface SemgrepPlatformOptions {\n deployment: string;\n project: string;\n ref: string;\n product?: SemgrepPlatformProduct;\n sourceRepositoryUrl?: string;\n sourceRepositories?: readonly ExternalSourceRepository[];\n token?: string;\n signal?: AbortSignal;\n}\n\nexport interface SemgrepPlatformReport extends SemgrepPlatformScope {\n /** The original transport address when the provider supplied an SSH repository. */\n nativeProjectUrl?: string;\n /** The operator's binding when the native URL is missing or uses SSH. */\n sourceRepositoryUrl?: string;\n format: typeof semgrepPlatformFormat;\n findingCount: number;\n findings: string[];\n repositoryAliases: string[];\n}\n\nexport async function collectSemgrepPlatformFindings(\n options: SemgrepPlatformOptions,\n dependencies: HostedScannerHttpOptions = {},\n): Promise<SemgrepPlatformReport> {\n const environment = dependencies.environment ?? process.env;\n const token = requiredText(\n hostedScannerToken(\n environment,\n \"SEMGREP_APP_TOKEN\",\n options.token,\n \"https://semgrep.dev\",\n \"SEMGREP_URL\",\n \"SEMGREP_APP_URL\",\n ),\n \"Semgrep Web API token (SEMGREP_APP_TOKEN)\",\n );\n const { getJson, signal } = hostedScannerHttp(dependencies, options.signal);\n const deployment = requiredText(options.deployment, \"Semgrep deployment\");\n const name = requiredText(options.project, \"Semgrep project name\");\n if (\n deployment.includes(\"/\") ||\n [deployment, name].some((part) => part === \".\" || part === \"..\")\n )\n throw new Error(\"Invalid Semgrep deployment slug or project name.\");\n const ref = requiredText(options.ref, \"Semgrep ref\");\n const { sourceRepositoryUrl } = options;\n const sourceRepositories = snapshotSourceRepositories(\n options.sourceRepositories,\n );\n const product = options.product ?? \"sast\";\n if (!SEMGREP_PLATFORM_PRODUCTS.includes(product))\n throw new Error(\"Select a Semgrep Platform product: sast, sca or ai_sast.\");\n\n const base = `https://semgrep.dev/api/v1/deployments/${encodeURIComponent(deployment)}`;\n const get = async (url: URL) =>\n responseRecord(\n await getJson(url, `Bearer ${token}`),\n \"Semgrep API response\",\n );\n const lookup = await get(\n new URL(`${base}/projects/${encodeURIComponent(name)}`),\n );\n const native = responseRecord(lookup[\"project\"], \"Semgrep project\");\n if (native[\"name\"] !== name)\n throw new Error(\"Semgrep returned a different project than requested.\");\n const nativeUrl = semgrepNativeProjectUrl(native[\"url\"], sourceRepositories);\n const mappedUrl = hostedRepositoryUrl(\n sourceRepositoryUrl ?? nativeUrl,\n \"Semgrep project repository\",\n );\n const url = nativeUrl ?? mappedUrl;\n const source = selectionRepository(url, sourceRepositories);\n if (source.key(mappedUrl) !== source.key(url))\n throw new Error(\n \"Semgrep project does not match the selected source repository URL.\",\n );\n const project = { id: semgrepPlatformId(native[\"id\"]), name, url };\n const scope = { deployment, project, ref, product };\n const endpoint = new URL(`${base}/findings`);\n const pageSize = 3000;\n endpoint.search = new URLSearchParams({\n repository_ids: project.id,\n issue_type: product,\n ref,\n dedup: \"false\",\n page_size: String(pageSize),\n }).toString();\n const names = projectAliases(name, url, sourceRepositories);\n const witnessed = new Set<string>();\n const verified = {\n has: (label: string) => names.has(label) || witnessed.has(label),\n };\n const observed = new Set<string>();\n async function readPage(page: number, collecting = true) {\n endpoint.searchParams.set(\"page\", String(page));\n const document = await get(new URL(endpoint));\n return array(document[\"findings\"], \"Semgrep findings\").map((entry) => {\n const finding = responseRecord(entry, \"Semgrep finding\");\n const repository = responseRecord(\n finding[\"repository\"] ?? {},\n \"Semgrep finding repository\",\n );\n const label = text(repository[\"name\"]);\n if (collecting && label) observed.add(label);\n checkSemgrepPlatformRow(\n finding,\n scope,\n collecting ? observed : verified,\n source,\n );\n if (\n collecting &&\n label &&\n (repository[\"id\"] != null || text(repository[\"url\"]))\n )\n witnessed.add(label);\n const raw = JSON.stringify(finding);\n return {\n key:\n semgrepPlatformIdOrUndefined(finding[\"id\"]) ??\n stringifySemgrepFinding(finding),\n raw,\n };\n });\n }\n\n const pageId = (batch: Awaited<ReturnType<typeof readPage>>) =>\n stableId(\"page\", batch.map((row) => row.key).sort());\n const findings: string[] = [];\n const previousKeys = new Set<string>();\n let firstPage: string | undefined;\n for (let page = 0; ; page++) {\n const batch = await readPage(page);\n // Compare only with prior pages; same-page ambiguities are reported per finding on import.\n if (batch.some((row) => previousKeys.has(row.key)))\n throw new Error(\n \"Semgrep Platform repeated findings across pages; retry the collection.\",\n );\n for (const row of batch) findings.push(row.raw);\n if (batch.length < pageSize) break;\n for (const row of batch) previousKeys.add(row.key);\n if (page === 0) firstPage = pageId(batch);\n }\n // A name-only finding can precede the row that binds this label to the project.\n for (const label of observed) {\n if (!verified.has(label))\n throw new Error(\n `Semgrep finding repository name \"${label}\" has no matching project name, repository ID or URL.`,\n );\n }\n // Offset pagination can skip a row if the first page changes between reads.\n if (firstPage && firstPage !== pageId(await readPage(0, false)))\n throw new Error(\n \"Semgrep Platform findings changed across pages; retry the collection.\",\n );\n signal?.throwIfAborted();\n return {\n format: semgrepPlatformFormat,\n ...scope,\n ...semgrepProjectUrlEvidence(native[\"url\"], nativeUrl, sourceRepositoryUrl),\n repositoryAliases: [...observed].sort(),\n findingCount: findings.length,\n findings,\n };\n}\n"]}
|