@openai/codex-security 0.8.2 → 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 +201 -178
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +6 -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 +51 -14
- 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/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +33 -0
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +19 -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/references/threat-model.md +1 -0
- 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 +188 -454
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +317 -377
- package/_bundled_plugin/scripts/finding_preview.py +25 -29
- 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 +198 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +167 -178
- 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 +9 -7
- package/_bundled_plugin/scripts/windows_scan_local_files.py +600 -72
- 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 +38 -75
- 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 +152 -248
- 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 +121 -14
- package/_bundled_plugin/scripts/workbench_constants.py +19 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +550 -492
- 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 +90 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +29 -33
- 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 +508 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +139 -80
- package/_bundled_plugin/scripts/workbench_scan_start.py +84 -25
- package/_bundled_plugin/scripts/workbench_scan_usage.py +666 -117
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +251 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +33 -23
- package/_bundled_plugin/scripts/workbench_target.py +330 -66
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +44 -12
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -16
- package/_bundled_plugin/shared/workbench-migrations.json +53 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +6 -4
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -2
- package/_bundled_plugin/skills/publish-findings/SKILL.md +81 -45
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +5 -24
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +36 -9
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +12 -6
- package/dist/api.d.ts +45 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1144 -411
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +10 -7
- 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 +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +320 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/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 +6 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +9 -21
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +30 -13
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +14 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2112 -1266
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +32 -6
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +221 -65
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +225 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +30 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +78 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -115
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +61 -4
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2560 -100
- 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/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +5 -10
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.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 +13 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +262 -7
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +108 -80
- 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 +9 -2
- 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 +11 -16
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +15 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +619 -225
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +20 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +2356 -308
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +28 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +174 -81
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +17 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +153 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +33 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +335 -51
- 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/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/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/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -31
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +22 -20
- 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 +392 -79
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-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 +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +71 -44
- 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 +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +58 -81
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +86 -10
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +130 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +160 -77
- 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 +49 -31
- 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/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- 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 +341 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +411 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +11 -3
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +80 -11
- 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/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- 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 +15 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +89 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +3 -1
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +28 -2
- 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 +6 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -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 +22 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +408 -162
- 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 +172 -64
- 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 +68 -25
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +7 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +91 -79
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +12 -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 +31 -28
- 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 +64 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +406 -48
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +17 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +71 -0
- package/dist/scanner-repository-url.js.map +1 -0
- 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 +124 -88
- 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 +213 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +1078 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- 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/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/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 +108 -84
- 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 +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +380 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +277 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/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 +5 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +73 -31
- 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-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/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.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +1 -17
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +9 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +409 -0
- package/dist/veracode-findings.js.map +1 -0
- 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 +27 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +14 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +143 -50
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +28 -13
- package/docs/cli.md +623 -843
- package/docs/dedupe-records.md +54 -24
- package/docs/findings-service.md +87 -47
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +64 -41
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +19 -17
- package/schemas/external-findings.schema.json +14 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -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/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
- 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 -120
- package/dist/finding-normalization.js.map +0 -1
package/dist/semgrep-findings.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
+
import { markPreviousCloudProjection } from "./reader-selection.js";
|
|
2
|
+
import { normalizeSemgrepPlatformFindings, isSemgrepPlatformFormat, semgrepPlatformLegacyFormat, semgrepPlatformFormat, } from "./semgrep-platform-findings.js";
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
import { guardianSelectionFormat, normalizeGuardianSelection, } from "./semgrep-guardian-findings.js";
|
|
5
|
+
import { parseHostedScannerJson } from "./hosted-scanner-http.js";
|
|
1
6
|
import { cloudRepositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
|
-
import { messageText, parseNativeJsonResult, position, projectNativeJsonResult, sourceRepositoryUrl, ungatedText, weaknessIds, } from "./native-json-findings.js";
|
|
3
|
-
import { array,
|
|
7
|
+
import { messageText, nativeResultPath, parseNativeJsonResult, position, projectNativeJsonResult, sourceRepositoryUrl, ungatedText, weaknessIds, } from "./native-json-findings.js";
|
|
8
|
+
import { array, normalizeRecords, optionalArray, readScannerJson, record, relativePath, requiredText, sarifRunRepositories, sarifRunResults, stableId, readSarifRuns, text, validateSarifRuleReference, } from "./scanner-import.js";
|
|
4
9
|
function sourceRepository(options) {
|
|
5
10
|
return sourceRepositoryUrl(options?.sourceRepositoryUrl, "Semgrep");
|
|
6
11
|
}
|
|
12
|
+
const severityLevels = new Map([
|
|
13
|
+
["CRITICAL", "critical"],
|
|
14
|
+
["HIGH", "high"],
|
|
15
|
+
["MEDIUM", "medium"],
|
|
16
|
+
["LOW", "low"],
|
|
17
|
+
["ERROR", "high"],
|
|
18
|
+
["WARNING", "medium"],
|
|
19
|
+
["INFO", "low"],
|
|
20
|
+
]);
|
|
7
21
|
function severity(value) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
MEDIUM: "medium",
|
|
12
|
-
LOW: "low",
|
|
13
|
-
ERROR: "high",
|
|
14
|
-
WARNING: "medium",
|
|
15
|
-
INFO: "low",
|
|
16
|
-
};
|
|
17
|
-
return typeof value === "string" ? (levels[value] ?? "unknown") : "unknown";
|
|
22
|
+
return typeof value === "string"
|
|
23
|
+
? (severityLevels.get(value) ?? "unknown")
|
|
24
|
+
: "unknown";
|
|
18
25
|
}
|
|
19
26
|
function identity(rule, path, line, column, endLine, endColumn) {
|
|
20
27
|
// CE omits fingerprints and source snippets. Its fallback is stable only while the range is stable.
|
|
@@ -49,16 +56,22 @@ function sarifArtifactUri(artifact, runContext) {
|
|
|
49
56
|
// Semgrep's native formatter copies filesystem paths without URI encoding.
|
|
50
57
|
return base === "%SRCROOT%" ? uri : decodeURIComponent(uri);
|
|
51
58
|
}
|
|
59
|
+
function primarySarifLocation(result) {
|
|
60
|
+
const locations = array(result["locations"] ?? [], "Semgrep locations");
|
|
61
|
+
if (locations.length !== 1)
|
|
62
|
+
throw new Error("Expected Semgrep's single primary result location.");
|
|
63
|
+
const location = record(locations[0], "Location");
|
|
64
|
+
const physical = record(location["physicalLocation"], "Physical location");
|
|
65
|
+
const artifact = record(physical["artifactLocation"], "Artifact location");
|
|
66
|
+
return { physical, artifact };
|
|
67
|
+
}
|
|
52
68
|
function sarifIdentity(value, runContext) {
|
|
53
69
|
const result = record(value, "Semgrep result");
|
|
54
70
|
const supplied = ungatedText(record(result["fingerprints"] ?? {}, "Semgrep fingerprints")["matchBasedId/v1"]);
|
|
55
71
|
if (supplied)
|
|
56
72
|
return stableId("semgrep", [supplied]);
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
throw new Error("Expected Semgrep's single primary result location.");
|
|
60
|
-
const physical = record(record(locations[0], "Location")["physicalLocation"], "Physical location");
|
|
61
|
-
const uri = sarifArtifactUri(record(physical["artifactLocation"], "Artifact location"), runContext);
|
|
73
|
+
const { physical, artifact } = primarySarifLocation(result);
|
|
74
|
+
const uri = sarifArtifactUri(artifact, runContext);
|
|
62
75
|
if (uri === null)
|
|
63
76
|
throw new Error("Cannot derive a Semgrep CE identity from an indexed or unresolved base-relative artifact URI.");
|
|
64
77
|
const region = record(physical["region"], "Semgrep region");
|
|
@@ -66,93 +79,103 @@ function sarifIdentity(value, runContext) {
|
|
|
66
79
|
const column = position(region["startColumn"] ?? 1, "Start column");
|
|
67
80
|
return identity(requiredText(result["ruleId"], "Semgrep ruleId"), uri, line, column, position(region["endLine"] ?? line, "End line"), position(region["endColumn"] ?? column, "End column"));
|
|
68
81
|
}
|
|
69
|
-
export function normalizeSemgrepFindings(input, options, target = "cloud") {
|
|
82
|
+
export function normalizeSemgrepFindings(input, options = {}, target = "cloud") {
|
|
70
83
|
const document = record(input, "Semgrep report");
|
|
84
|
+
if (document["format"] === guardianSelectionFormat) {
|
|
85
|
+
return normalizeGuardianSelection(document, target, options.sourceRepositoryUrl, options.sourceRepositories);
|
|
86
|
+
}
|
|
87
|
+
if (isSemgrepPlatformFormat(document["format"])) {
|
|
88
|
+
return normalizeSemgrepPlatformFindings(document, options?.sourceRepositoryUrl, target, options?.sourceRepositories);
|
|
89
|
+
}
|
|
71
90
|
if (document["version"] === "2.1.0" && document["runs"] !== undefined)
|
|
72
|
-
return normalizeSemgrepSarif(document, options, target);
|
|
91
|
+
return normalizeSemgrepSarif(document, { ...options, sourceRepositoryUrl: options?.sourceRepositoryUrl ?? "" }, target);
|
|
92
|
+
return normalizeSemgrepJson(document, options, target);
|
|
93
|
+
}
|
|
94
|
+
function nativeProjection(target, previous) {
|
|
95
|
+
let changed = false;
|
|
96
|
+
return {
|
|
97
|
+
location(raw) {
|
|
98
|
+
const oldPath = relativePath(raw);
|
|
99
|
+
if (previous)
|
|
100
|
+
return oldPath;
|
|
101
|
+
// Semgrep retains its raw spelling; OpenGrep groups by the normalized path.
|
|
102
|
+
const path = nativeResultPath(raw, oldPath) === null ? null : raw;
|
|
103
|
+
if (path !== oldPath)
|
|
104
|
+
changed = true;
|
|
105
|
+
return path;
|
|
106
|
+
},
|
|
107
|
+
finish(findings, omittedExplanations = false) {
|
|
108
|
+
if (target === "cloud" && (changed || omittedExplanations))
|
|
109
|
+
markPreviousCloudProjection(findings);
|
|
110
|
+
return findings;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** @internal Rebuild the native JSON or SARIF that an earlier reader approved. */
|
|
115
|
+
export function normalizePreviousSemgrepFindings(input, options) {
|
|
116
|
+
const document = record(input, "Semgrep report");
|
|
117
|
+
return document["version"] === "2.1.0" && document["runs"] !== undefined
|
|
118
|
+
? normalizeSarif(document, options, "cloud", true)
|
|
119
|
+
: normalizeSemgrepJson(document, options, "cloud", true);
|
|
120
|
+
}
|
|
121
|
+
function normalizeSemgrepJson(document, options, target, previous = false) {
|
|
73
122
|
const repositoryUrl = sourceRepository(options);
|
|
74
123
|
requiredText(document["version"], "Semgrep version");
|
|
75
|
-
if (array(document["errors"] ?? [], "Semgrep errors").length)
|
|
76
|
-
throw new Error("The Semgrep report contains scan errors; supply a successful report before importing findings.");
|
|
77
124
|
const { results, paths: _paths, time: _time, ...context } = document;
|
|
78
|
-
|
|
125
|
+
const omitExplanations = !previous && Object.hasOwn(context, "explanations");
|
|
126
|
+
if (omitExplanations)
|
|
127
|
+
delete context["explanations"];
|
|
128
|
+
const rows = array(results, "Semgrep results");
|
|
129
|
+
if (!rows.length && document["errors"] === undefined)
|
|
130
|
+
throw new Error("An empty Semgrep report must include its errors array.");
|
|
131
|
+
if (optionalArray(document["errors"], "Semgrep errors").length)
|
|
132
|
+
throw new Error("The Semgrep report contains scan errors; supply a successful report before importing findings.");
|
|
133
|
+
const projection = nativeProjection(target, previous);
|
|
134
|
+
const findings = normalizeRecords(rows, (value) => projectNativeJsonResult(parseNativeJsonResult(value, "Semgrep", projection.location), {
|
|
79
135
|
origin: "Semgrep",
|
|
80
136
|
repositoryUrl,
|
|
81
137
|
severity,
|
|
82
138
|
reportContext: context,
|
|
83
139
|
target,
|
|
84
140
|
}), jsonIdentity, target);
|
|
141
|
+
return projection.finish(findings, omitExplanations);
|
|
142
|
+
}
|
|
143
|
+
export function isSemgrepSarifDriver(name) {
|
|
144
|
+
return ["semgrep", "semgrep oss", "semgrep pro"].includes(name.toLowerCase());
|
|
85
145
|
}
|
|
86
146
|
export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
147
|
+
return normalizeSarif(input, options, target);
|
|
148
|
+
}
|
|
149
|
+
function normalizeSarif(input, options, target, previous = false) {
|
|
87
150
|
const repositoryUrl = sourceRepository(options);
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (declared &&
|
|
96
|
-
cloudRepositoryUrlKey(declared) !== cloudRepositoryUrlKey(repositoryUrl))
|
|
151
|
+
const repositoryKey = cloudRepositoryUrlKey(repositoryUrl);
|
|
152
|
+
const verifiedUrls = new Set([repositoryUrl]);
|
|
153
|
+
const entries = readSarifRuns(input, "Semgrep", (context) => {
|
|
154
|
+
for (const { url: declared } of sarifRunRepositories(context.run, "Semgrep")) {
|
|
155
|
+
if (verifiedUrls.has(declared))
|
|
156
|
+
continue;
|
|
157
|
+
if (cloudRepositoryUrlKey(declared) !== repositoryKey)
|
|
97
158
|
throw new Error("SARIF source repository does not match the declared source repository URL.");
|
|
159
|
+
verifiedUrls.add(declared);
|
|
98
160
|
}
|
|
99
|
-
|
|
100
|
-
const driver = record(tool["driver"], "SARIF driver");
|
|
101
|
-
if (!["semgrep", "semgrep oss", "semgrep pro"].includes(requiredText(driver["name"], "SARIF producer").toLowerCase()))
|
|
161
|
+
if (!isSemgrepSarifDriver(requiredText(context.driver["name"], "SARIF producer")))
|
|
102
162
|
throw new Error("Expected a Semgrep SARIF producer.");
|
|
103
|
-
|
|
104
|
-
throw new Error("Use a self-contained Semgrep SARIF report.");
|
|
105
|
-
for (const invocation of array(run["invocations"] ?? [], "Semgrep invocations")) {
|
|
106
|
-
const details = record(invocation, "Semgrep invocation");
|
|
107
|
-
if (details["executionSuccessful"] === false)
|
|
108
|
-
throw new Error("Semgrep SARIF contains an unsuccessful invocation.");
|
|
109
|
-
if (array(details["toolExecutionNotifications"] ?? [], "Semgrep scan notifications").length)
|
|
110
|
-
throw new Error("Semgrep SARIF contains scan error notifications.");
|
|
111
|
-
}
|
|
112
|
-
const rules = array(driver["rules"] ?? [], "Semgrep rules").map((r) => record(r, "Semgrep rule"));
|
|
113
|
-
const rulesById = indexSarifRules(rules);
|
|
114
|
-
const { runs: _runs, ...documentContext } = document;
|
|
115
|
-
const { results: _results, tool: _tool, ...runContext } = run;
|
|
116
|
-
const { rules: _rules, ...driverContext } = driver;
|
|
117
|
-
const { driver: _driver, ...toolContext } = tool;
|
|
118
|
-
return array(run["results"] ?? [], "Semgrep results").map((result) => ({
|
|
119
|
-
result,
|
|
120
|
-
rulesById,
|
|
121
|
-
hasRules: rules.length > 0,
|
|
122
|
-
documentContext,
|
|
123
|
-
runContext,
|
|
124
|
-
driverContext,
|
|
125
|
-
toolContext,
|
|
126
|
-
}));
|
|
163
|
+
return sarifRunResults(context, "Semgrep");
|
|
127
164
|
});
|
|
128
|
-
|
|
165
|
+
const projection = nativeProjection(target, previous);
|
|
166
|
+
const findings = normalizeRecords(entries, ({ result: value, context }) => {
|
|
129
167
|
const result = record(value, "Semgrep result");
|
|
130
168
|
const properties = record(result["properties"] ?? {}, "Semgrep result properties");
|
|
131
169
|
if (properties["exposure"] != null ||
|
|
132
170
|
properties["dependencyPaths"] != null)
|
|
133
171
|
throw new Error("This adapter supports Semgrep SAST; Supply Chain reports need separate qualification.");
|
|
134
172
|
const ruleId = requiredText(result["ruleId"], "Semgrep ruleId");
|
|
135
|
-
const selectedRule = rulesById.get(ruleId);
|
|
136
|
-
if (
|
|
173
|
+
const selectedRule = context.rulesById.get(ruleId) ?? undefined;
|
|
174
|
+
if (context.rulesById.size > 0 && !selectedRule)
|
|
137
175
|
throw new Error("Semgrep result must reference exactly one rule in its run.");
|
|
138
176
|
const rule = selectedRule?.rule;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
result["ruleIndex"] !== ruleIndex)
|
|
142
|
-
throw new Error("Semgrep ruleIndex and ruleId disagree.");
|
|
143
|
-
if (result["rule"] !== undefined) {
|
|
144
|
-
const ref = record(result["rule"], "Semgrep rule reference");
|
|
145
|
-
if (ref["toolComponent"] !== undefined ||
|
|
146
|
-
(ref["id"] !== undefined && ref["id"] !== ruleId) ||
|
|
147
|
-
(ref["index"] !== undefined && ref["index"] !== ruleIndex) ||
|
|
148
|
-
(ref["guid"] !== undefined && ref["guid"] !== rule?.["guid"]))
|
|
149
|
-
throw new Error("Inconsistent or external Semgrep rule reference.");
|
|
150
|
-
}
|
|
151
|
-
const locations = array(result["locations"] ?? [], "Semgrep locations");
|
|
152
|
-
if (locations.length !== 1)
|
|
153
|
-
throw new Error("Expected Semgrep's single primary result location.");
|
|
154
|
-
const physical = record(record(locations[0], "Location")["physicalLocation"], "Physical location");
|
|
155
|
-
const artifact = record(physical["artifactLocation"], "Artifact location");
|
|
177
|
+
validateSarifRuleReference(result, ruleId, selectedRule, "Semgrep");
|
|
178
|
+
const { physical, artifact } = primarySarifLocation(result);
|
|
156
179
|
const rawPath = sarifArtifactUri(artifact, context.runContext);
|
|
157
180
|
const region = record(physical["region"], "Semgrep region");
|
|
158
181
|
const line = position(region["startLine"], "Start line");
|
|
@@ -176,7 +199,7 @@ export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
|
176
199
|
const absoluteUri = artifact["uriBaseId"] !== "%SRCROOT%" &&
|
|
177
200
|
typeof artifact["uri"] === "string" &&
|
|
178
201
|
/^[a-z][a-z\d+.-]*:/iu.test(artifact["uri"]);
|
|
179
|
-
const path = rawPath === null || absoluteUri ? null :
|
|
202
|
+
const path = rawPath === null || absoluteUri ? null : projection.location(rawPath);
|
|
180
203
|
return validateExternalEvidence({
|
|
181
204
|
title: ruleId,
|
|
182
205
|
description: text(message["markdown"]) ??
|
|
@@ -201,16 +224,29 @@ export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
|
201
224
|
? "suppressed"
|
|
202
225
|
: null,
|
|
203
226
|
},
|
|
204
|
-
source_data:
|
|
205
|
-
...context,
|
|
206
|
-
runContext: sarifRunContextForResult(context.runContext, result, rule, context.driverContext, context.toolContext, context.documentContext),
|
|
207
|
-
...(rule ? { rule } : {}),
|
|
208
|
-
result,
|
|
209
|
-
}),
|
|
227
|
+
source_data: context.sourceData(result, rule),
|
|
210
228
|
}, target);
|
|
211
|
-
}, ({ result,
|
|
229
|
+
}, ({ result, context }) => sarifIdentity(result, context.runContext), target);
|
|
230
|
+
return projection.finish(findings);
|
|
231
|
+
}
|
|
232
|
+
/** @internal Read the original file before resolving repository provenance. */
|
|
233
|
+
export async function readSemgrepReport(path) {
|
|
234
|
+
return readScannerJson(path, (json) => {
|
|
235
|
+
// Pick a parser before allocating the findings array. Verify the root:
|
|
236
|
+
// the member can be nested in a native report or escaped in a Platform one.
|
|
237
|
+
const parser = /"format"\s*:\s*"semgrep-platform-findings\/v[12]"/u.test(json)
|
|
238
|
+
? parseHostedScannerJson
|
|
239
|
+
: JSON.parse;
|
|
240
|
+
const parsed = parser(json);
|
|
241
|
+
const requiredParser = isRecord(parsed) &&
|
|
242
|
+
(parsed["format"] === semgrepPlatformLegacyFormat ||
|
|
243
|
+
parsed["format"] === semgrepPlatformFormat)
|
|
244
|
+
? parseHostedScannerJson
|
|
245
|
+
: JSON.parse;
|
|
246
|
+
return parser === requiredParser ? parsed : requiredParser(json);
|
|
247
|
+
});
|
|
212
248
|
}
|
|
213
|
-
export async function readSemgrepFindings(path, options, target = "cloud") {
|
|
214
|
-
return normalizeSemgrepFindings(await
|
|
249
|
+
export async function readSemgrepFindings(path, options = {}, target = "cloud") {
|
|
250
|
+
return normalizeSemgrepFindings(await readSemgrepReport(path), options, target);
|
|
215
251
|
}
|
|
216
252
|
//# sourceMappingURL=semgrep-findings.js.map
|
|
@@ -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,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACxB,QAAQ,EACR,IAAI,GACL,MAAM,qBAAqB,CAAC;AAO7B,SAAS,gBAAgB,CAAC,OAA6B;IACrD,OAAO,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,EAAE,SAAS,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,MAAM,MAAM,GAA2B;QACrC,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,KAAK;KACZ,CAAC;IACF,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,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ImportTarget } from \"./external-import-contract.js\";\nimport {\n 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 indexSarifRules,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n sarifRunContextForResult,\n stableId,\n text,\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 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 locations = array(result[\"locations\"] ?? [], \"Semgrep locations\");\n if (locations.length !== 1)\n throw new Error(\"Expected Semgrep's single primary result location.\");\n const physical = record(\n record(locations[0], \"Location\")[\"physicalLocation\"],\n \"Physical location\",\n );\n const uri = sarifArtifactUri(\n record(physical[\"artifactLocation\"], \"Artifact location\"),\n runContext,\n );\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 const rules = array(driver[\"rules\"] ?? [], \"Semgrep rules\").map((r) =>\n record(r, \"Semgrep rule\"),\n );\n const rulesById = indexSarifRules(rules);\n const { runs: _runs, ...documentContext } = document;\n const { results: _results, tool: _tool, ...runContext } = run;\n const { rules: _rules, ...driverContext } = driver;\n const { driver: _driver, ...toolContext } = tool;\n return array(run[\"results\"] ?? [], \"Semgrep results\").map((result) => ({\n result,\n rulesById,\n hasRules: rules.length > 0,\n documentContext,\n runContext,\n driverContext,\n toolContext,\n }));\n });\n return normalizeRecords(\n entries,\n ({ result: value, rulesById, hasRules, ...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 = rulesById.get(ruleId);\n if (selectedRule === null || (hasRules && selectedRule === undefined))\n throw new Error(\n \"Semgrep result must reference exactly one rule in its run.\",\n );\n const rule = selectedRule?.rule;\n const ruleIndex = selectedRule?.index;\n if (\n result[\"ruleIndex\"] !== undefined &&\n result[\"ruleIndex\"] !== ruleIndex\n )\n throw new Error(\"Semgrep ruleIndex and ruleId disagree.\");\n if (result[\"rule\"] !== undefined) {\n const ref = record(result[\"rule\"], \"Semgrep rule reference\");\n if (\n ref[\"toolComponent\"] !== undefined ||\n (ref[\"id\"] !== undefined && ref[\"id\"] !== ruleId) ||\n (ref[\"index\"] !== undefined && ref[\"index\"] !== ruleIndex) ||\n (ref[\"guid\"] !== undefined && ref[\"guid\"] !== rule?.[\"guid\"])\n )\n throw new Error(\"Inconsistent or external Semgrep rule reference.\");\n }\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 physical = record(\n record(locations[0], \"Location\")[\"physicalLocation\"],\n \"Physical location\",\n );\n const artifact = record(\n physical[\"artifactLocation\"],\n \"Artifact location\",\n );\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: structuredClone({\n ...context,\n runContext: sarifRunContextForResult(\n context.runContext,\n result,\n rule,\n context.driverContext,\n context.toolContext,\n context.documentContext,\n ),\n ...(rule ? { rule } : {}),\n result,\n }),\n },\n target,\n );\n },\n ({ result, runContext }) => sarifIdentity(result, 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,gCAAgC,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAKvC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,QAAQ,EACR,uBAAuB,EACvB,mBAAmB,EACnB,WAAW,EACX,WAAW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AmB,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
|