@openai/codex-security 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -57
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +187 -363
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +120 -35
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +414 -163
- package/dist/api.js.map +1 -1
- package/dist/auth.js +7 -2
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +635 -266
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +6 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +12 -5
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +11 -3
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +48 -16
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +44 -89
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +11 -15
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +12 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +411 -184
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +15 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1238 -226
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +10 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +71 -51
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +13 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +124 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +7 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +512 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +94 -36
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +5 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +110 -57
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +37 -48
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +48 -3
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +214 -39
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +50 -88
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +97 -106
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +320 -481
- package/docs/dedupe-records.md +27 -4
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +9 -10
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -35
- package/dist/deduplication/records-protocol.js.map +0 -1
package/dist/semgrep-findings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloudRepositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
2
|
import { messageText, parseNativeJsonResult, position, projectNativeJsonResult, sourceRepositoryUrl, ungatedText, weaknessIds, } from "./native-json-findings.js";
|
|
3
|
-
import { array, hasSarifExternalPropertyReferences, normalizeRecords, readScannerJson, record, relativePath, requiredText,
|
|
3
|
+
import { array, hasSarifExternalPropertyReferences, normalizeRecords, readScannerJson, record, relativePath, requiredText, sarifRunResults, stableId, text, validateSarifRuleReference, } from "./scanner-import.js";
|
|
4
4
|
function sourceRepository(options) {
|
|
5
5
|
return sourceRepositoryUrl(options?.sourceRepositoryUrl, "Semgrep");
|
|
6
6
|
}
|
|
@@ -49,16 +49,22 @@ function sarifArtifactUri(artifact, runContext) {
|
|
|
49
49
|
// Semgrep's native formatter copies filesystem paths without URI encoding.
|
|
50
50
|
return base === "%SRCROOT%" ? uri : decodeURIComponent(uri);
|
|
51
51
|
}
|
|
52
|
+
function primarySarifLocation(result) {
|
|
53
|
+
const locations = array(result["locations"] ?? [], "Semgrep locations");
|
|
54
|
+
if (locations.length !== 1)
|
|
55
|
+
throw new Error("Expected Semgrep's single primary result location.");
|
|
56
|
+
const location = record(locations[0], "Location");
|
|
57
|
+
const physical = record(location["physicalLocation"], "Physical location");
|
|
58
|
+
const artifact = record(physical["artifactLocation"], "Artifact location");
|
|
59
|
+
return { physical, artifact };
|
|
60
|
+
}
|
|
52
61
|
function sarifIdentity(value, runContext) {
|
|
53
62
|
const result = record(value, "Semgrep result");
|
|
54
63
|
const supplied = ungatedText(record(result["fingerprints"] ?? {}, "Semgrep fingerprints")["matchBasedId/v1"]);
|
|
55
64
|
if (supplied)
|
|
56
65
|
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);
|
|
66
|
+
const { physical, artifact } = primarySarifLocation(result);
|
|
67
|
+
const uri = sarifArtifactUri(artifact, runContext);
|
|
62
68
|
if (uri === null)
|
|
63
69
|
throw new Error("Cannot derive a Semgrep CE identity from an indexed or unresolved base-relative artifact URI.");
|
|
64
70
|
const region = record(physical["region"], "Semgrep region");
|
|
@@ -75,15 +81,12 @@ export function normalizeSemgrepFindings(input, options, target = "cloud") {
|
|
|
75
81
|
if (array(document["errors"] ?? [], "Semgrep errors").length)
|
|
76
82
|
throw new Error("The Semgrep report contains scan errors; supply a successful report before importing findings.");
|
|
77
83
|
const { results, paths: _paths, time: _time, ...context } = document;
|
|
78
|
-
return normalizeRecords(array(results, "Semgrep results"), (value
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
reportContext: context,
|
|
85
|
-
target,
|
|
86
|
-
}),
|
|
84
|
+
return normalizeRecords(array(results, "Semgrep results"), (value) => projectNativeJsonResult(parseNativeJsonResult(value, "Semgrep"), {
|
|
85
|
+
origin: "Semgrep",
|
|
86
|
+
repositoryUrl,
|
|
87
|
+
severity,
|
|
88
|
+
reportContext: context,
|
|
89
|
+
target,
|
|
87
90
|
}), jsonIdentity, target);
|
|
88
91
|
}
|
|
89
92
|
export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
@@ -112,54 +115,21 @@ export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
|
112
115
|
if (array(details["toolExecutionNotifications"] ?? [], "Semgrep scan notifications").length)
|
|
113
116
|
throw new Error("Semgrep SARIF contains scan error notifications.");
|
|
114
117
|
}
|
|
115
|
-
|
|
116
|
-
const rulesById = new Map();
|
|
117
|
-
for (const [index, rule] of rules.entries()) {
|
|
118
|
-
const id = rule["id"];
|
|
119
|
-
rulesById.set(id, rulesById.has(id) ? null : { rule, index });
|
|
120
|
-
}
|
|
121
|
-
const { runs: _runs, ...documentContext } = document;
|
|
122
|
-
const { results: _results, tool: _tool, ...runContext } = run;
|
|
123
|
-
const { rules: _rules, ...driverContext } = driver;
|
|
124
|
-
const { driver: _driver, ...toolContext } = tool;
|
|
125
|
-
return array(run["results"] ?? [], "Semgrep results").map((result) => ({
|
|
126
|
-
result,
|
|
127
|
-
rulesById,
|
|
128
|
-
hasRules: rules.length > 0,
|
|
129
|
-
documentContext,
|
|
130
|
-
runContext,
|
|
131
|
-
driverContext,
|
|
132
|
-
toolContext,
|
|
133
|
-
}));
|
|
118
|
+
return sarifRunResults(document, run, tool, driver, "Semgrep");
|
|
134
119
|
});
|
|
135
|
-
return normalizeRecords(entries, ({ result: value,
|
|
120
|
+
return normalizeRecords(entries, ({ result: value, context }) => {
|
|
136
121
|
const result = record(value, "Semgrep result");
|
|
137
122
|
const properties = record(result["properties"] ?? {}, "Semgrep result properties");
|
|
138
123
|
if (properties["exposure"] != null ||
|
|
139
124
|
properties["dependencyPaths"] != null)
|
|
140
125
|
throw new Error("This adapter supports Semgrep SAST; Supply Chain reports need separate qualification.");
|
|
141
126
|
const ruleId = requiredText(result["ruleId"], "Semgrep ruleId");
|
|
142
|
-
const selectedRule = rulesById.get(ruleId);
|
|
143
|
-
if (
|
|
127
|
+
const selectedRule = context.rulesById.get(ruleId) ?? undefined;
|
|
128
|
+
if (context.rulesById.size > 0 && !selectedRule)
|
|
144
129
|
throw new Error("Semgrep result must reference exactly one rule in its run.");
|
|
145
130
|
const rule = selectedRule?.rule;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
result["ruleIndex"] !== ruleIndex)
|
|
149
|
-
throw new Error("Semgrep ruleIndex and ruleId disagree.");
|
|
150
|
-
if (result["rule"] !== undefined) {
|
|
151
|
-
const ref = record(result["rule"], "Semgrep rule reference");
|
|
152
|
-
if (ref["toolComponent"] !== undefined ||
|
|
153
|
-
(ref["id"] !== undefined && ref["id"] !== ruleId) ||
|
|
154
|
-
(ref["index"] !== undefined && ref["index"] !== ruleIndex) ||
|
|
155
|
-
(ref["guid"] !== undefined && ref["guid"] !== rule?.["guid"]))
|
|
156
|
-
throw new Error("Inconsistent or external Semgrep rule reference.");
|
|
157
|
-
}
|
|
158
|
-
const locations = array(result["locations"] ?? [], "Semgrep locations");
|
|
159
|
-
if (locations.length !== 1)
|
|
160
|
-
throw new Error("Expected Semgrep's single primary result location.");
|
|
161
|
-
const physical = record(record(locations[0], "Location")["physicalLocation"], "Physical location");
|
|
162
|
-
const artifact = record(physical["artifactLocation"], "Artifact location");
|
|
131
|
+
validateSarifRuleReference(result, ruleId, selectedRule, "Semgrep");
|
|
132
|
+
const { physical, artifact } = primarySarifLocation(result);
|
|
163
133
|
const rawPath = sarifArtifactUri(artifact, context.runContext);
|
|
164
134
|
const region = record(physical["region"], "Semgrep region");
|
|
165
135
|
const line = position(region["startLine"], "Start line");
|
|
@@ -184,41 +154,33 @@ export function normalizeSemgrepSarif(input, options, target = "cloud") {
|
|
|
184
154
|
typeof artifact["uri"] === "string" &&
|
|
185
155
|
/^[a-z][a-z\d+.-]*:/iu.test(artifact["uri"]);
|
|
186
156
|
const path = rawPath === null || absoluteUri ? null : relativePath(rawPath);
|
|
187
|
-
return {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
end_line: path ? endLine : null,
|
|
203
|
-
snippet: ungatedText(record(region["snippet"] ?? {}, "Snippet")["text"]),
|
|
204
|
-
},
|
|
205
|
-
source_status: Array.isArray(result["suppressions"]) &&
|
|
206
|
-
result["suppressions"].some((value) => {
|
|
207
|
-
const status = record(value, "Suppression")["status"];
|
|
208
|
-
return status === undefined || status === "accepted";
|
|
209
|
-
})
|
|
210
|
-
? "suppressed"
|
|
211
|
-
: null,
|
|
157
|
+
return validateExternalEvidence({
|
|
158
|
+
title: ruleId,
|
|
159
|
+
description: text(message["markdown"]) ??
|
|
160
|
+
messageText(message["text"], "Semgrep"),
|
|
161
|
+
severity: mappedSeverity,
|
|
162
|
+
locations: path ? [{ path, line }] : [],
|
|
163
|
+
details: {
|
|
164
|
+
kind: "sast",
|
|
165
|
+
repository: { url: repositoryUrl },
|
|
166
|
+
scanner_origin: "Semgrep",
|
|
167
|
+
rule: { id: ruleId },
|
|
168
|
+
weakness_ids: weaknessIds(record(rule?.["properties"] ?? {}, "Rule properties")["tags"]),
|
|
169
|
+
code: {
|
|
170
|
+
end_line: path ? endLine : null,
|
|
171
|
+
snippet: ungatedText(record(region["snippet"] ?? {}, "Snippet")["text"]),
|
|
212
172
|
},
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
173
|
+
source_status: Array.isArray(result["suppressions"]) &&
|
|
174
|
+
result["suppressions"].some((value) => {
|
|
175
|
+
const status = record(value, "Suppression")["status"];
|
|
176
|
+
return status === undefined || status === "accepted";
|
|
177
|
+
})
|
|
178
|
+
? "suppressed"
|
|
179
|
+
: null,
|
|
180
|
+
},
|
|
181
|
+
source_data: context.sourceData(result, rule),
|
|
182
|
+
}, target);
|
|
183
|
+
}, ({ result, context }) => sarifIdentity(result, context.runContext), target);
|
|
222
184
|
}
|
|
223
185
|
export async function readSemgrepFindings(path, options, target = "cloud") {
|
|
224
186
|
return normalizeSemgrepFindings(await readScannerJson(path), options, target);
|
|
@@ -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,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,KAAK,CAAC,IAAI,SA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CAAC,CAAC,EAAE,CAAC;oBACzB,MAAM;iBACP,CAAC;aACH,EACD,MAAM,CACP;SACF,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,EAC7D,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,OAA6B,EAC7B,MAAM,GAAyB,OAAO;IAEtC,OAAO,wBAAwB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import type { ExternalImportTarget } 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 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, sourceFindingId) => ({\n source_finding_id: sourceFindingId,\n evidence: projectNativeJsonResult(\n parseNativeJsonResult(value, \"Semgrep\"),\n {\n origin: \"Semgrep\",\n repositoryUrl,\n severity,\n reportContext: context,\n target,\n },\n ),\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 = new Map<\n unknown,\n { rule: Record<string, unknown>; index: number } | null\n >();\n for (const [index, rule] of rules.entries()) {\n const id = rule[\"id\"];\n rulesById.set(id, rulesById.has(id) ? null : { rule, index });\n }\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 }, sourceFindingId) => {\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 {\n source_finding_id: sourceFindingId,\n evidence: 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 },\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":"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,EACZ,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,IAAI,EACJ,0BAA0B,GAC3B,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,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,QAAQ,CACf,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,OAAe,EACf,SAAiB;IAEjB,oGAAoG;IACpG,OAAO,QAAQ,CAAC,kBAAkB,EAAE;QAClC,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,OAAO;QACP,SAAS;KACV,CAAC,CAAC;AACL,C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P,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,EAClE,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,OAA6B,EAC7B,MAAM,GAAyB,OAAO;IAEtC,OAAO,wBAAwB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import type { ExternalImportTarget } 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 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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExternalFindings } from "./external-findings.js";
|
|
2
|
+
/** Select SAST findings from operator-supplied Web API responses for local SDK import. */
|
|
3
|
+
export declare function normalizeSelectedSemgrepPlatformFindings(options: {
|
|
4
|
+
deployment: string;
|
|
5
|
+
ref: string;
|
|
6
|
+
/** Independently supplied by the operator for the selected local checkout. */
|
|
7
|
+
sourceRepositoryUrl: string;
|
|
8
|
+
projectResponse: string;
|
|
9
|
+
findingsResponses: Iterable<string>;
|
|
10
|
+
findingIds: readonly string[];
|
|
11
|
+
}): ExternalFindings;
|
|
12
|
+
//# sourceMappingURL=semgrep-platform-findings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-platform-findings.d.ts","sourceRoot":"","sources":["../src/semgrep-platform-findings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA8F/D,0FAA0F;AAC1F,wBAAgB,wCAAwC,CAAC,OAAO,EAAE;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B,GAAG,gBAAgB,CA4LnB"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { canonicalNumber, validateExternalEvidence, } from "./external-import-contract.js";
|
|
2
|
+
import { isRecord } from "./record.js";
|
|
3
|
+
import { position, weaknessIds } from "./native-json-findings.js";
|
|
4
|
+
import { array, normalizeRecords, record, relativePath, repositoryFilePath, requiredText, stableId, text, } from "./scanner-import.js";
|
|
5
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
6
|
+
// These v1 Findings API response fields belong only to AI detections or Supply Chain.
|
|
7
|
+
const nonSastFields = [
|
|
8
|
+
"ai_impact",
|
|
9
|
+
"epss_score",
|
|
10
|
+
"fix_recommendations",
|
|
11
|
+
"found_dependency",
|
|
12
|
+
"is_malicious",
|
|
13
|
+
"reachability",
|
|
14
|
+
"reachable_condition",
|
|
15
|
+
"usage",
|
|
16
|
+
"vulnerability_identifier",
|
|
17
|
+
];
|
|
18
|
+
function identifiesNonSastProduct(value) {
|
|
19
|
+
if (!isRecord(value))
|
|
20
|
+
return false;
|
|
21
|
+
return (nonSastFields.some((field) => value[field] != null) ||
|
|
22
|
+
[value["issue_type"], value["product"]].some((product) => typeof product === "string" &&
|
|
23
|
+
/^(?:sca|ai_sast|secrets)$/iu.test(product)));
|
|
24
|
+
}
|
|
25
|
+
// Node 22 supports JSON source text and raw values. The SDK targets the ES2022 type library.
|
|
26
|
+
const wireJson = JSON;
|
|
27
|
+
// A retained JSON number is represented as an object in JavaScript.
|
|
28
|
+
function responseRecord(value, label) {
|
|
29
|
+
return record(wireJson.isRawJSON(value) ? undefined : value, label);
|
|
30
|
+
}
|
|
31
|
+
function sourceLine(value) {
|
|
32
|
+
if (value == null)
|
|
33
|
+
return null;
|
|
34
|
+
if (!wireJson.isRawJSON(value))
|
|
35
|
+
return position(value, "Semgrep source line");
|
|
36
|
+
const exact = canonicalNumber(value.rawJSON);
|
|
37
|
+
return position(/^\d+$/u.test(exact) ? Number(exact) : undefined, "Semgrep source line");
|
|
38
|
+
}
|
|
39
|
+
/** Keep original number tokens, including adjacent int64 IDs above Number.MAX_SAFE_INTEGER. */
|
|
40
|
+
function parseSemgrepResponse(json) {
|
|
41
|
+
return responseRecord(JSON.parse(json.replace(/^\uFEFF/u, ""), (_key, value, context) => typeof value === "number" ? wireJson.rawJSON(context.source) : value), "Semgrep API response");
|
|
42
|
+
}
|
|
43
|
+
function platformId(value) {
|
|
44
|
+
let token;
|
|
45
|
+
if (wireJson.isRawJSON(value))
|
|
46
|
+
token = value.rawJSON;
|
|
47
|
+
else if (typeof value === "string" && /^[1-9][0-9]*$/u.test(value))
|
|
48
|
+
token = value;
|
|
49
|
+
else
|
|
50
|
+
return undefined;
|
|
51
|
+
const id = canonicalNumber(token);
|
|
52
|
+
if (/^[1-9][0-9]*$/u.test(id))
|
|
53
|
+
return id;
|
|
54
|
+
// A large scientific value is an integer only when every significant digit lies left of its decimal point.
|
|
55
|
+
const scientific = /^[1-9](?:\.(\d+))?e\+(\d+)$/u.exec(id);
|
|
56
|
+
return scientific && BigInt(scientific[2]) >= (scientific[1]?.length ?? 0)
|
|
57
|
+
? id
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
function requiredPlatformId(value) {
|
|
61
|
+
const id = platformId(value);
|
|
62
|
+
if (!id)
|
|
63
|
+
throw new Error("Expected an exact, positive Semgrep Platform ID.");
|
|
64
|
+
return id;
|
|
65
|
+
}
|
|
66
|
+
/** Select SAST findings from operator-supplied Web API responses for local SDK import. */
|
|
67
|
+
export function normalizeSelectedSemgrepPlatformFindings(options) {
|
|
68
|
+
const native = responseRecord(parseSemgrepResponse(options.projectResponse)["project"], "Semgrep project");
|
|
69
|
+
const scope = {
|
|
70
|
+
deployment: requiredText(options.deployment, "Semgrep deployment"),
|
|
71
|
+
project: {
|
|
72
|
+
id: requiredPlatformId(native["id"]),
|
|
73
|
+
name: requiredText(native["name"], "Semgrep project name"),
|
|
74
|
+
url: declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Semgrep", "local"),
|
|
75
|
+
},
|
|
76
|
+
ref: requiredText(options.ref, "Semgrep ref"),
|
|
77
|
+
product: "sast",
|
|
78
|
+
};
|
|
79
|
+
// git-check-ref-format distinguishes literal branch/tag names from revision expressions.
|
|
80
|
+
const refParts = scope.ref.split("/");
|
|
81
|
+
if (refParts[0] !== "refs" ||
|
|
82
|
+
refParts.length < 2 ||
|
|
83
|
+
refParts.some((part) => !part || part.startsWith(".") || part.endsWith(".lock")) ||
|
|
84
|
+
scope.ref.endsWith(".") ||
|
|
85
|
+
scope.ref.includes("..") ||
|
|
86
|
+
scope.ref.includes("@{") ||
|
|
87
|
+
/[\u0000-\u0020\u007f~^:?*\[\\]/u.test(scope.ref))
|
|
88
|
+
throw new Error("Use a fully qualified Semgrep ref such as refs/heads/topic.");
|
|
89
|
+
if (native["url"] !== scope.project.url)
|
|
90
|
+
throw new Error("Selected Semgrep project does not match the operator's source repository URL.");
|
|
91
|
+
const wanted = new Set(options.findingIds.map((id) => requiredPlatformId(requiredText(id, "Selected Semgrep finding ID"))));
|
|
92
|
+
if (!wanted.size)
|
|
93
|
+
throw new Error("Select at least one Semgrep finding ID.");
|
|
94
|
+
const selected = new Map();
|
|
95
|
+
const pages = typeof options.findingsResponses === "string"
|
|
96
|
+
? [options.findingsResponses]
|
|
97
|
+
: options.findingsResponses;
|
|
98
|
+
const projectPath = decodeURIComponent(new URL(scope.project.url).pathname).replace(/^\/|\/$/gu, "");
|
|
99
|
+
for (const response of pages) {
|
|
100
|
+
const findings = array(parseSemgrepResponse(response)["findings"], "Semgrep findings");
|
|
101
|
+
const previousCount = selected.size;
|
|
102
|
+
for (const finding of findings) {
|
|
103
|
+
if (!isRecord(finding))
|
|
104
|
+
continue;
|
|
105
|
+
const id = platformId(finding["id"]);
|
|
106
|
+
if (!id || !wanted.has(id))
|
|
107
|
+
continue;
|
|
108
|
+
if (selected.has(id))
|
|
109
|
+
throw new Error(`Duplicate selected Semgrep finding ${id}.`);
|
|
110
|
+
const repo = responseRecord(finding["repository"], "Semgrep finding repository");
|
|
111
|
+
const repositoryId = repo["id"] == null ? undefined : requiredPlatformId(repo["id"]);
|
|
112
|
+
const url = repo["url"];
|
|
113
|
+
const name = repo["name"];
|
|
114
|
+
const matchesQualifiedPath = name === projectPath && projectPath.includes("/");
|
|
115
|
+
if (finding["ref"] !== scope.ref ||
|
|
116
|
+
(repositoryId !== undefined && repositoryId !== scope.project.id) ||
|
|
117
|
+
(url != null
|
|
118
|
+
? url !== scope.project.url
|
|
119
|
+
: repositoryId === undefined || !matchesQualifiedPath))
|
|
120
|
+
throw new Error("Selected Semgrep finding does not belong to the selected project and ref.");
|
|
121
|
+
if ([finding["issue_type"], finding["product"]].some((product) => product != null &&
|
|
122
|
+
(typeof product !== "string" ||
|
|
123
|
+
!["sast", "code"].includes(product.toLowerCase()))))
|
|
124
|
+
throw new Error("Select Semgrep Code (SAST) findings.");
|
|
125
|
+
selected.set(id, finding);
|
|
126
|
+
}
|
|
127
|
+
// The v1 findings endpoint returns a single product per response page.
|
|
128
|
+
if (selected.size !== previousCount &&
|
|
129
|
+
findings.some(identifiesNonSastProduct))
|
|
130
|
+
throw new Error("Select Semgrep Code (SAST) findings.");
|
|
131
|
+
}
|
|
132
|
+
const rows = Array.from(wanted, (id) => {
|
|
133
|
+
const found = selected.get(id);
|
|
134
|
+
if (!found)
|
|
135
|
+
throw new Error(`Selected Semgrep finding ${id} is missing.`);
|
|
136
|
+
return found;
|
|
137
|
+
});
|
|
138
|
+
// Older Platform imports hash safe integers as numbers, and larger IDs as strings.
|
|
139
|
+
const exact = (id) => Number.isSafeInteger(Number(id)) ? Number(id) : id;
|
|
140
|
+
return normalizeRecords(rows, (finding) => {
|
|
141
|
+
const rule = responseRecord(finding["rule"] ?? {}, "Semgrep rule");
|
|
142
|
+
const name = text(rule["name"]) ?? text(finding["rule_name"]);
|
|
143
|
+
const severity = text(finding["severity"])?.toLowerCase() ?? "";
|
|
144
|
+
const description = text(rule["message"]) ?? text(finding["rule_message"]);
|
|
145
|
+
const location = responseRecord(finding["location"] ?? {}, "Semgrep location");
|
|
146
|
+
const rawPath = text(location["file_path"]);
|
|
147
|
+
const relative = relativePath(rawPath);
|
|
148
|
+
const path = relative && !relative.endsWith("/.") && repositoryFilePath(relative)
|
|
149
|
+
? rawPath
|
|
150
|
+
: null;
|
|
151
|
+
const startLine = path ? sourceLine(location["line"]) : null;
|
|
152
|
+
return validateExternalEvidence({
|
|
153
|
+
title: requiredText(name ?? description, "Semgrep finding title"),
|
|
154
|
+
description,
|
|
155
|
+
severity: ["low", "medium", "high", "critical"].includes(severity)
|
|
156
|
+
? severity
|
|
157
|
+
: "unknown",
|
|
158
|
+
locations: path ? [{ path, line: startLine }] : [],
|
|
159
|
+
branch: scope.ref,
|
|
160
|
+
details: {
|
|
161
|
+
kind: "sast",
|
|
162
|
+
repository: { url: scope.project.url },
|
|
163
|
+
scanner_origin: "Semgrep",
|
|
164
|
+
rule: name ? { id: name } : null,
|
|
165
|
+
source_status: text(finding["status"]),
|
|
166
|
+
weakness_ids: weaknessIds(rule["cwe_names"]),
|
|
167
|
+
code: {
|
|
168
|
+
end_line: startLine !== null ? sourceLine(location["end_line"]) : null,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
source_data: {
|
|
172
|
+
format: "semgrep-platform-selection/v1",
|
|
173
|
+
...scope,
|
|
174
|
+
project: {
|
|
175
|
+
...scope.project,
|
|
176
|
+
id: text(native["id"]) ?? scope.project.id,
|
|
177
|
+
},
|
|
178
|
+
semgrepPlatformFindingJson: JSON.stringify(finding, (_key, value) => {
|
|
179
|
+
if (wireJson.isRawJSON(value))
|
|
180
|
+
return wireJson.rawJSON(canonicalNumber(value.rawJSON));
|
|
181
|
+
// Native object key order can vary across otherwise identical reads.
|
|
182
|
+
if (isRecord(value))
|
|
183
|
+
return Object.fromEntries(Object.keys(value)
|
|
184
|
+
.sort()
|
|
185
|
+
.map((key) => [key, value[key]]));
|
|
186
|
+
return value;
|
|
187
|
+
}),
|
|
188
|
+
},
|
|
189
|
+
}, "local");
|
|
190
|
+
}, (finding) => stableId("semgrep-platform", [
|
|
191
|
+
scope.deployment,
|
|
192
|
+
exact(scope.project.id),
|
|
193
|
+
scope.product,
|
|
194
|
+
scope.ref,
|
|
195
|
+
exact(requiredPlatformId(finding["id"])),
|
|
196
|
+
]), "local");
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=semgrep-platform-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semgrep-platform-findings.js","sourceRoot":"","sources":["../src/semgrep-platform-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,QAAQ,EACR,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,sFAAsF;AACtF,MAAM,aAAa,GAAG;IACpB,WAAW;IACX,YAAY;IACZ,qBAAqB;IACrB,kBAAkB;IAClB,cAAc;IACd,cAAc;IACd,qBAAqB;IACrB,OAAO;IACP,0BAA0B;CAC3B,CAAC;AAEF,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,CACL,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;QACnD,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAC1C,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,OAAO,KAAK,QAAQ;YAC3B,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,CAC9C,CACF,CAAC;AACJ,CAAC;AAED,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,KAAc,EAAE,EAAE;oBACvB,IAAI,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC;wBAC3B,OAAO,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC1D,qEAAqE;oBACrE,IAAI,QAAQ,CAAC,KAAK,CAAC;wBACjB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;6BACf,IAAI,EAAE;6BACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CACnC,CAAC;oBACJ,OAAO,KAAK,CAAC;gBACf,CAAC,CACF;aACF;SACF,EACD,OAAO,CACR,CAAC;IACJ,CAAC,EACD,CAAC,OAAO,EAAE,EAAE,CACV,QAAQ,CAAC,kBAAkB,EAAE;QAC3B,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,GAAG;QACT,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;KACzC,CAAC,EACJ,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["import {\n canonicalNumber,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport { position, weaknessIds } from \"./native-json-findings.js\";\nimport {\n array,\n normalizeRecords,\n record,\n relativePath,\n repositoryFilePath,\n requiredText,\n stableId,\n text,\n} from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\n\n// These v1 Findings API response fields belong only to AI detections or Supply Chain.\nconst nonSastFields = [\n \"ai_impact\",\n \"epss_score\",\n \"fix_recommendations\",\n \"found_dependency\",\n \"is_malicious\",\n \"reachability\",\n \"reachable_condition\",\n \"usage\",\n \"vulnerability_identifier\",\n];\n\nfunction identifiesNonSastProduct(value: unknown): boolean {\n if (!isRecord(value)) return false;\n return (\n nonSastFields.some((field) => value[field] != null) ||\n [value[\"issue_type\"], value[\"product\"]].some(\n (product) =>\n typeof product === \"string\" &&\n /^(?:sca|ai_sast|secrets)$/iu.test(product),\n )\n );\n}\n\n// Node 22 supports JSON source text and raw values. The SDK targets the ES2022 type library.\nconst wireJson = JSON as JSON & {\n rawJSON(source: string): { rawJSON: string };\n isRawJSON(value: unknown): value is { rawJSON: string };\n};\n\n// A retained JSON number is represented as an object in JavaScript.\nfunction responseRecord(value: unknown, label: string) {\n return record(wireJson.isRawJSON(value) ? undefined : value, label);\n}\n\nfunction sourceLine(value: unknown): number | null {\n if (value == null) return null;\n if (!wireJson.isRawJSON(value)) return position(value, \"Semgrep source line\");\n const exact = canonicalNumber(value.rawJSON);\n return position(\n /^\\d+$/u.test(exact) ? Number(exact) : undefined,\n \"Semgrep source line\",\n );\n}\n\n/** Keep original number tokens, including adjacent int64 IDs above Number.MAX_SAFE_INTEGER. */\nfunction parseSemgrepResponse(json: string): Record<string, unknown> {\n return responseRecord(\n JSON.parse(\n json.replace(/^\\uFEFF/u, \"\"),\n (_key: string, value: unknown, context?: { source?: string }) =>\n typeof value === \"number\" ? wireJson.rawJSON(context!.source!) : value,\n ),\n \"Semgrep API response\",\n );\n}\n\nfunction platformId(value: unknown): string | undefined {\n let token: string;\n if (wireJson.isRawJSON(value)) token = value.rawJSON;\n else if (typeof value === \"string\" && /^[1-9][0-9]*$/u.test(value))\n token = value;\n else return undefined;\n const id = canonicalNumber(token);\n if (/^[1-9][0-9]*$/u.test(id)) return id;\n // A large scientific value is an integer only when every significant digit lies left of its decimal point.\n const scientific = /^[1-9](?:\\.(\\d+))?e\\+(\\d+)$/u.exec(id);\n return scientific && BigInt(scientific[2]!) >= (scientific[1]?.length ?? 0)\n ? id\n : undefined;\n}\n\nfunction requiredPlatformId(value: unknown): string {\n const id = platformId(value);\n if (!id) throw new Error(\"Expected an exact, positive Semgrep Platform ID.\");\n return id;\n}\n\n/** Select SAST findings from operator-supplied Web API responses for local SDK import. */\nexport function normalizeSelectedSemgrepPlatformFindings(options: {\n deployment: string;\n ref: string;\n /** Independently supplied by the operator for the selected local checkout. */\n sourceRepositoryUrl: string;\n projectResponse: string;\n findingsResponses: Iterable<string>;\n findingIds: readonly string[];\n}): ExternalFindings {\n const native = responseRecord(\n parseSemgrepResponse(options.projectResponse)[\"project\"],\n \"Semgrep project\",\n );\n const scope = {\n deployment: requiredText(options.deployment, \"Semgrep deployment\"),\n project: {\n id: requiredPlatformId(native[\"id\"]),\n name: requiredText(native[\"name\"], \"Semgrep project name\"),\n url: declaredScannerRepositoryUrl(\n options.sourceRepositoryUrl,\n \"Semgrep\",\n \"local\",\n ),\n },\n ref: requiredText(options.ref, \"Semgrep ref\"),\n product: \"sast\",\n };\n // git-check-ref-format distinguishes literal branch/tag names from revision expressions.\n const refParts = scope.ref.split(\"/\");\n if (\n refParts[0] !== \"refs\" ||\n refParts.length < 2 ||\n refParts.some(\n (part) => !part || part.startsWith(\".\") || part.endsWith(\".lock\"),\n ) ||\n scope.ref.endsWith(\".\") ||\n scope.ref.includes(\"..\") ||\n scope.ref.includes(\"@{\") ||\n /[\\u0000-\\u0020\\u007f~^:?*\\[\\\\]/u.test(scope.ref)\n )\n throw new Error(\n \"Use a fully qualified Semgrep ref such as refs/heads/topic.\",\n );\n if (native[\"url\"] !== scope.project.url)\n throw new Error(\n \"Selected Semgrep project does not match the operator's source repository URL.\",\n );\n const wanted = new Set(\n options.findingIds.map((id) =>\n requiredPlatformId(requiredText(id, \"Selected Semgrep finding ID\")),\n ),\n );\n if (!wanted.size) throw new Error(\"Select at least one Semgrep finding ID.\");\n const selected = new Map<string, Record<string, unknown>>();\n const pages =\n typeof options.findingsResponses === \"string\"\n ? [options.findingsResponses]\n : options.findingsResponses;\n const projectPath = decodeURIComponent(\n new URL(scope.project.url).pathname,\n ).replace(/^\\/|\\/$/gu, \"\");\n for (const response of pages) {\n const findings = array(\n parseSemgrepResponse(response)[\"findings\"],\n \"Semgrep findings\",\n );\n const previousCount = selected.size;\n for (const finding of findings) {\n if (!isRecord(finding)) continue;\n const id = platformId(finding[\"id\"]);\n if (!id || !wanted.has(id)) continue;\n if (selected.has(id))\n throw new Error(`Duplicate selected Semgrep finding ${id}.`);\n const repo = responseRecord(\n finding[\"repository\"],\n \"Semgrep finding repository\",\n );\n const repositoryId =\n repo[\"id\"] == null ? undefined : requiredPlatformId(repo[\"id\"]);\n const url = repo[\"url\"];\n const name = repo[\"name\"];\n const matchesQualifiedPath =\n name === projectPath && projectPath.includes(\"/\");\n if (\n finding[\"ref\"] !== scope.ref ||\n (repositoryId !== undefined && repositoryId !== scope.project.id) ||\n (url != null\n ? url !== scope.project.url\n : repositoryId === undefined || !matchesQualifiedPath)\n )\n throw new Error(\n \"Selected Semgrep finding does not belong to the selected project and ref.\",\n );\n if (\n [finding[\"issue_type\"], finding[\"product\"]].some(\n (product) =>\n product != null &&\n (typeof product !== \"string\" ||\n ![\"sast\", \"code\"].includes(product.toLowerCase())),\n )\n )\n throw new Error(\"Select Semgrep Code (SAST) findings.\");\n selected.set(id, finding);\n }\n // The v1 findings endpoint returns a single product per response page.\n if (\n selected.size !== previousCount &&\n findings.some(identifiesNonSastProduct)\n )\n throw new Error(\"Select Semgrep Code (SAST) findings.\");\n }\n const rows = Array.from(wanted, (id) => {\n const found = selected.get(id);\n if (!found) throw new Error(`Selected Semgrep finding ${id} is missing.`);\n return found;\n });\n // Older Platform imports hash safe integers as numbers, and larger IDs as strings.\n const exact = (id: string) =>\n Number.isSafeInteger(Number(id)) ? Number(id) : id;\n return normalizeRecords(\n rows,\n (finding) => {\n const rule = responseRecord(finding[\"rule\"] ?? {}, \"Semgrep rule\");\n const name = text(rule[\"name\"]) ?? text(finding[\"rule_name\"]);\n const severity = text(finding[\"severity\"])?.toLowerCase() ?? \"\";\n const description =\n text(rule[\"message\"]) ?? text(finding[\"rule_message\"]);\n const location = responseRecord(\n finding[\"location\"] ?? {},\n \"Semgrep location\",\n );\n const rawPath = text(location[\"file_path\"]);\n const relative = relativePath(rawPath);\n const path =\n relative && !relative.endsWith(\"/.\") && repositoryFilePath(relative)\n ? rawPath\n : null;\n const startLine = path ? sourceLine(location[\"line\"]) : null;\n return validateExternalEvidence(\n {\n title: requiredText(name ?? description, \"Semgrep finding title\"),\n description,\n severity: [\"low\", \"medium\", \"high\", \"critical\"].includes(severity)\n ? severity\n : \"unknown\",\n locations: path ? [{ path, line: startLine }] : [],\n branch: scope.ref,\n details: {\n kind: \"sast\",\n repository: { url: scope.project.url },\n scanner_origin: \"Semgrep\",\n rule: name ? { id: name } : null,\n source_status: text(finding[\"status\"]),\n weakness_ids: weaknessIds(rule[\"cwe_names\"]),\n code: {\n end_line:\n startLine !== null ? sourceLine(location[\"end_line\"]) : null,\n },\n },\n source_data: {\n format: \"semgrep-platform-selection/v1\",\n ...scope,\n project: {\n ...scope.project,\n id: text(native[\"id\"]) ?? scope.project.id,\n },\n semgrepPlatformFindingJson: JSON.stringify(\n finding,\n (_key, value: unknown) => {\n if (wireJson.isRawJSON(value))\n return wireJson.rawJSON(canonicalNumber(value.rawJSON));\n // Native object key order can vary across otherwise identical reads.\n if (isRecord(value))\n return Object.fromEntries(\n Object.keys(value)\n .sort()\n .map((key) => [key, value[key]]),\n );\n return value;\n },\n ),\n },\n },\n \"local\",\n );\n },\n (finding) =>\n stableId(\"semgrep-platform\", [\n scope.deployment,\n exact(scope.project.id),\n scope.product,\n scope.ref,\n exact(requiredPlatformId(finding[\"id\"])),\n ]),\n \"local\",\n );\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const severityRubricSchema: z.ZodObject<{
|
|
3
|
+
markdown: z.ZodString;
|
|
4
|
+
revision: z.ZodNumber;
|
|
5
|
+
sha256: z.ZodString;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export type SeverityRubricSnapshot = z.infer<typeof severityRubricSchema>;
|
|
8
|
+
export declare function readSeverityRubricFile(path: string, repository: string): Promise<SeverityRubricSnapshot>;
|
|
9
|
+
export declare const bundledSeverityRubric: Readonly<{
|
|
10
|
+
markdown: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
sha256: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** Resolve once per operation; callers retain this snapshot for retries and workers. */
|
|
15
|
+
export declare function getDefaultSeverityRubric({ signal, environment, }?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
environment?: NodeJS.ProcessEnv;
|
|
18
|
+
}): Promise<SeverityRubricSnapshot>;
|
|
19
|
+
export declare function severityRubricInstructions(rubric: SeverityRubricSnapshot): string;
|
|
20
|
+
//# sourceMappingURL=severity-rubric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"severity-rubric.d.ts","sourceRoot":"","sources":["../src/severity-rubric.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA6BxB,eAAO,MAAM,oBAAoB;;;;kBAK9B,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAS1E,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAKjC;AAED,eAAO,MAAM,qBAAqB;;;;EAEjC,CAAC;AAEF,wFAAwF;AACxF,wBAAsB,wBAAwB,CAAC,EAC7C,MAAM,EACN,WAAyB,GAC1B,GAAE;IACD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CAC5B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA+BvC;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,sBAAsB,GAC7B,MAAM,CAKR"}
|