@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/scanner-import.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { hash } from "node:crypto";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { posix } from "node:path";
|
|
3
4
|
import { promisify } from "node:util";
|
|
4
5
|
import { gunzip } from "node:zlib";
|
|
5
6
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
6
7
|
import { isRecord } from "./record.js";
|
|
8
|
+
import { previousAdmission } from "./external-import-contract.js";
|
|
9
|
+
import { rememberPreviousSelection } from "./reader-selection.js";
|
|
7
10
|
export function record(value, label) {
|
|
8
11
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
9
12
|
throw new Error(`${label} must be an object.`);
|
|
@@ -39,6 +42,18 @@ export function relativePath(value) {
|
|
|
39
42
|
? path
|
|
40
43
|
: null;
|
|
41
44
|
}
|
|
45
|
+
export function repositoryFilePath(value) {
|
|
46
|
+
const relative = relativePath(value);
|
|
47
|
+
if (!relative)
|
|
48
|
+
return null;
|
|
49
|
+
const path = posix.normalize(relative);
|
|
50
|
+
// Anchor the SCP branch at the first eligible @ to avoid rescanning long filenames.
|
|
51
|
+
return path === "." ||
|
|
52
|
+
path.endsWith("/") ||
|
|
53
|
+
/^(?:[a-z][a-z\d+.-]*:|~[^/]*(?:\/|$)|[^/][^/@]*@[^/]+:)/iu.test(path)
|
|
54
|
+
? null
|
|
55
|
+
: path;
|
|
56
|
+
}
|
|
42
57
|
export function stableId(prefix, fields) {
|
|
43
58
|
return `${prefix}:${hash("sha256", JSON.stringify(fields))}`;
|
|
44
59
|
}
|
|
@@ -97,11 +112,7 @@ const sarifArtifactLocationFields = new Set([
|
|
|
97
112
|
"mappedTo",
|
|
98
113
|
"displayBase",
|
|
99
114
|
]);
|
|
100
|
-
|
|
101
|
-
export function sarifRunContextForResult(runContext, ...selectedEvidence) {
|
|
102
|
-
const { artifacts, ...context } = runContext;
|
|
103
|
-
if (!Array.isArray(artifacts) || artifacts.length === 0)
|
|
104
|
-
return runContext;
|
|
115
|
+
function sarifArtifactReferences(evidence) {
|
|
105
116
|
const locations = [];
|
|
106
117
|
let hasArtifactLink = false;
|
|
107
118
|
function visit(value) {
|
|
@@ -126,37 +137,213 @@ export function sarifRunContextForResult(runContext, ...selectedEvidence) {
|
|
|
126
137
|
visit(child);
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
|
-
visit(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
visit(evidence);
|
|
141
|
+
return { locations, hasArtifactLink };
|
|
142
|
+
}
|
|
143
|
+
const unresolvedUri = /[%:\\]|(?:^|\/)\.\.?(?:\/|$)/u;
|
|
144
|
+
function artifactUriMatcher(artifacts) {
|
|
145
|
+
const uris = new Set();
|
|
146
|
+
let hasLocation = false;
|
|
147
|
+
let base;
|
|
148
|
+
for (const artifact of artifacts) {
|
|
149
|
+
if (!isRecord(artifact) || !isRecord(artifact["location"]))
|
|
137
150
|
continue;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
const { uri, uriBaseId } = artifact["location"];
|
|
152
|
+
// Mixed bases or a URI that needs resolution can match any direct reference.
|
|
153
|
+
if ((hasLocation && uriBaseId !== base) ||
|
|
154
|
+
(typeof uri === "string" && unresolvedUri.test(uri)))
|
|
155
|
+
return () => true;
|
|
156
|
+
hasLocation = true;
|
|
157
|
+
base = uriBaseId;
|
|
158
|
+
if (typeof uri === "string")
|
|
159
|
+
uris.add(uri);
|
|
160
|
+
}
|
|
161
|
+
return (uri, uriBaseId) => hasLocation &&
|
|
162
|
+
(uriBaseId !== base || unresolvedUri.test(uri) || uris.has(uri));
|
|
163
|
+
}
|
|
164
|
+
/** Keep original artifact indexes; omit only inventory unrelated to this finding. */
|
|
165
|
+
export function sarifRunContextSelector(runContext) {
|
|
166
|
+
const { artifacts, ...context } = runContext;
|
|
167
|
+
if (!Array.isArray(artifacts) || artifacts.length === 0)
|
|
168
|
+
return () => runContext;
|
|
169
|
+
let matchesUri;
|
|
170
|
+
return (...selectedEvidence) => {
|
|
171
|
+
const { locations, hasArtifactLink } = sarifArtifactReferences([
|
|
172
|
+
context,
|
|
173
|
+
...selectedEvidence,
|
|
174
|
+
]);
|
|
175
|
+
if (hasArtifactLink)
|
|
176
|
+
return runContext;
|
|
177
|
+
for (const location of locations) {
|
|
178
|
+
const { index, uri, uriBaseId } = location;
|
|
179
|
+
if (typeof index === "number" && index >= 0)
|
|
148
180
|
return runContext;
|
|
181
|
+
if (typeof uri === "string") {
|
|
182
|
+
matchesUri ??= artifactUriMatcher(artifacts);
|
|
183
|
+
if (matchesUri(uri, uriBaseId))
|
|
184
|
+
return runContext;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return context;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Duplicate IDs cannot identify a single rule in this run. */
|
|
191
|
+
export function indexSarifRules(entries) {
|
|
192
|
+
const byId = new Map();
|
|
193
|
+
for (const [index, rule] of entries) {
|
|
194
|
+
const id = rule["id"];
|
|
195
|
+
byId.set(id, byId.has(id) ? null : { rule, index });
|
|
196
|
+
}
|
|
197
|
+
return byId;
|
|
198
|
+
}
|
|
199
|
+
/** Pair each result with its shared run context and original evidence. */
|
|
200
|
+
export function sarifRunResults(document, run, tool, driver, producer) {
|
|
201
|
+
const rules = array(driver["rules"] ?? [], `${producer} rules`).map((rule) => record(rule, `${producer} rule`));
|
|
202
|
+
const rulesById = indexSarifRules(rules.entries());
|
|
203
|
+
const { runs: _runs, ...documentContext } = document;
|
|
204
|
+
const { results: _results, tool: _tool, ...runContext } = run;
|
|
205
|
+
const { rules: _rules, ...driverContext } = driver;
|
|
206
|
+
const { driver: _driver, ...toolContext } = tool;
|
|
207
|
+
const selectRunContext = sarifRunContextSelector(runContext);
|
|
208
|
+
// JS callers may supply lazy metadata. Preserve each adapter's original traversal order.
|
|
209
|
+
const metadataInReadOrder = producer === "Semgrep"
|
|
210
|
+
? [driverContext, toolContext, documentContext]
|
|
211
|
+
: [documentContext, driverContext, toolContext];
|
|
212
|
+
const context = {
|
|
213
|
+
rulesById,
|
|
214
|
+
runContext,
|
|
215
|
+
sourceData(result, rule) {
|
|
216
|
+
return structuredClone({
|
|
217
|
+
documentContext,
|
|
218
|
+
runContext: selectRunContext(result, rule, ...metadataInReadOrder),
|
|
219
|
+
driverContext,
|
|
220
|
+
toolContext,
|
|
221
|
+
...(rule ? { rule } : {}),
|
|
222
|
+
result,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
return array(run["results"] ?? [], `${producer} results`).map((result) => ({
|
|
227
|
+
result,
|
|
228
|
+
context,
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
/** The top-level index and nested descriptor must agree with the selected driver rule. */
|
|
232
|
+
export function validateSarifRuleReference(result, ruleId, selected, producer) {
|
|
233
|
+
// Snyk's original diagnostics use unqualified SARIF field names.
|
|
234
|
+
const label = producer === "Snyk" ? "Result" : producer;
|
|
235
|
+
if (result["ruleIndex"] !== undefined &&
|
|
236
|
+
result["ruleIndex"] !== selected?.index)
|
|
237
|
+
throw new Error(`${label} ruleIndex and ruleId disagree.`);
|
|
238
|
+
if (result["rule"] === undefined)
|
|
239
|
+
return;
|
|
240
|
+
const reference = record(result["rule"], producer === "Snyk" ? "Rule reference" : `${producer} rule reference`);
|
|
241
|
+
if (reference["toolComponent"] !== undefined ||
|
|
242
|
+
(reference["id"] !== undefined && reference["id"] !== ruleId) ||
|
|
243
|
+
(reference["index"] !== undefined &&
|
|
244
|
+
reference["index"] !== selected?.index) ||
|
|
245
|
+
(reference["guid"] !== undefined &&
|
|
246
|
+
reference["guid"] !== selected?.rule["guid"]))
|
|
247
|
+
throw new Error(producer === "Snyk"
|
|
248
|
+
? "Result uses an inconsistent or external rule reference."
|
|
249
|
+
: `Inconsistent or external ${producer} rule reference.`);
|
|
250
|
+
}
|
|
251
|
+
/** Track older size decisions while a single reader constructs its result. */
|
|
252
|
+
export function trackReaderSelection(result) {
|
|
253
|
+
const changes = [];
|
|
254
|
+
const uncertainIds = new Set();
|
|
255
|
+
function append(position, id, project) {
|
|
256
|
+
const index = result.findings.length;
|
|
257
|
+
let outcome;
|
|
258
|
+
try {
|
|
259
|
+
const evidence = project();
|
|
260
|
+
outcome = evidence;
|
|
261
|
+
result.findings.push({ source_finding_id: id, evidence });
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
outcome = error;
|
|
265
|
+
result.excluded.push({
|
|
266
|
+
position,
|
|
267
|
+
source_finding_id: id,
|
|
268
|
+
reason: errorMessage(error),
|
|
269
|
+
});
|
|
149
270
|
}
|
|
271
|
+
const previous = outcome && typeof outcome === "object"
|
|
272
|
+
? previousAdmission(outcome)
|
|
273
|
+
: undefined;
|
|
274
|
+
if (previous === "uncertain")
|
|
275
|
+
uncertainIds.add(id);
|
|
276
|
+
else if (previous !== undefined)
|
|
277
|
+
changes.push({ index, position, id, previous });
|
|
150
278
|
}
|
|
151
|
-
|
|
279
|
+
function finish(filter) {
|
|
280
|
+
if (!changes.length && !uncertainIds.size) {
|
|
281
|
+
filter?.(result);
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
const findings = [];
|
|
285
|
+
const excluded = [];
|
|
286
|
+
const restoredPositions = new Set();
|
|
287
|
+
let cursor = 0;
|
|
288
|
+
for (const { index, position, id, previous } of changes) {
|
|
289
|
+
while (cursor < index)
|
|
290
|
+
findings.push(result.findings[cursor++]);
|
|
291
|
+
if (previous) {
|
|
292
|
+
findings.push({ source_finding_id: id, evidence: previous });
|
|
293
|
+
restoredPositions.add(position);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
cursor++;
|
|
297
|
+
excluded.push({
|
|
298
|
+
position,
|
|
299
|
+
source_finding_id: id,
|
|
300
|
+
reason: "Evidence exceeds the Cloud limit of 256 KiB.",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
while (cursor < result.findings.length)
|
|
305
|
+
findings.push(result.findings[cursor++]);
|
|
306
|
+
for (const row of result.excluded) {
|
|
307
|
+
if (!restoredPositions.has(row.position))
|
|
308
|
+
excluded.push(row);
|
|
309
|
+
}
|
|
310
|
+
excluded.sort((a, b) => a.position - b.position);
|
|
311
|
+
const previous = { ...result, findings, excluded };
|
|
312
|
+
// A removed sibling could have depended on an unproven row for its scope.
|
|
313
|
+
filter?.(previous, uncertainIds.size ? uncertainIds : undefined);
|
|
314
|
+
filter?.(result);
|
|
315
|
+
const sourceFindingIds = [
|
|
316
|
+
...new Set([
|
|
317
|
+
...previous.findings.map((row) => row.source_finding_id),
|
|
318
|
+
...uncertainIds,
|
|
319
|
+
]),
|
|
320
|
+
];
|
|
321
|
+
if (uncertainIds.size) {
|
|
322
|
+
rememberPreviousSelection(result, {
|
|
323
|
+
sourceFindingIds,
|
|
324
|
+
uncertainFindingIds: [...uncertainIds],
|
|
325
|
+
knownFindings: structuredClone(previous.findings.filter((row) => !uncertainIds.has(row.source_finding_id))),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
rememberPreviousSelection(result, {
|
|
330
|
+
sourceFindingIds,
|
|
331
|
+
snapshot: structuredClone(previous),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
return { append, finish, uncertainIds };
|
|
152
337
|
}
|
|
153
338
|
/** Exclude every colliding record: choosing the first could overwrite another occurrence. */
|
|
154
|
-
export function normalizeRecords(records,
|
|
339
|
+
export function normalizeRecords(records, projectEvidence, identify, target = "cloud", options = {}) {
|
|
155
340
|
const result = {
|
|
156
341
|
read: records.length,
|
|
157
342
|
findings: [],
|
|
158
343
|
excluded: [],
|
|
344
|
+
...(options.report === undefined ? {} : { report: options.report }),
|
|
159
345
|
};
|
|
346
|
+
const selection = trackReaderSelection(result);
|
|
160
347
|
const identified = [];
|
|
161
348
|
const counts = new Map();
|
|
162
349
|
for (const [index, value] of records.entries()) {
|
|
@@ -188,21 +375,9 @@ export function normalizeRecords(records, normalize, identify, target = "cloud")
|
|
|
188
375
|
});
|
|
189
376
|
continue;
|
|
190
377
|
}
|
|
191
|
-
|
|
192
|
-
const finding = normalize(value, id);
|
|
193
|
-
if (finding.source_finding_id !== id)
|
|
194
|
-
throw new Error("Finding identity changed during normalization.");
|
|
195
|
-
result.findings.push(finding);
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
result.excluded.push({
|
|
199
|
-
position,
|
|
200
|
-
source_finding_id: id,
|
|
201
|
-
reason: errorMessage(error),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
378
|
+
selection.append(position, id, () => projectEvidence(value, id));
|
|
204
379
|
}
|
|
205
380
|
result.excluded.sort((a, b) => a.position - b.position);
|
|
206
|
-
return
|
|
381
|
+
return selection.finish(options.filter);
|
|
207
382
|
}
|
|
208
383
|
//# sourceMappingURL=scanner-import.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner-import.js","sourceRoot":"","sources":["../src/scanner-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,UAAU,MAAM,CAAC,KAAc,EAAE,KAAa;IAClD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,qBAAqB,CAAC,CAAC;IACjD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAc,EAAE,KAAa;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,CAAC,CAAC;IACzE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,KAAa;IACxD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,GA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O,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACnB,QAAQ;gBACR,iBAAiB,EAAE,EAAE;gBACrB,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { hash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { gunzip } from \"node:zlib\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\n\nexport function record(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== \"object\" || Array.isArray(value))\n throw new Error(`${label} must be an object.`);\n return value as Record<string, unknown>;\n}\n\nexport function array(value: unknown, label: string): unknown[] {\n if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);\n return value;\n}\n\nexport function text(value: unknown): string | null {\n return typeof value === \"string\" && value.trim() ? value : null;\n}\n\nexport function requiredText(value: unknown, label: string): string {\n const result = text(value);\n if (!result) throw new Error(`${label} must be nonempty text.`);\n return result;\n}\n\nexport function strings(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((v): v is string => text(v) !== null)\n : [];\n}\n\n/** Paths that cannot be attributed to a repository stay in original evidence. */\nexport function relativePath(value: unknown): string | null {\n const path = text(value)?.replaceAll(\"\\\\\", \"/\");\n return path &&\n !path.startsWith(\"/\") &&\n !path.includes(\"\\0\") &&\n !/^[A-Za-z]:/.test(path) &&\n !path.split(\"/\").includes(\"..\")\n ? path\n : null;\n}\n\nexport function stableId(prefix: string, fields: unknown[]): string {\n return `${prefix}:${hash(\"sha256\", JSON.stringify(fields))}`;\n}\n\nconst strictUtf8 = new TextDecoder(\"utf-8\", { fatal: true });\nconst gunzipAsync = promisify(gunzip);\n\nasync function readScannerBytes(path: string): Promise<Buffer> {\n const bytes = await readFile(path);\n return bytes[0] === 0x1f && bytes[1] === 0x8b ? gunzipAsync(bytes) : bytes;\n}\n\nexport async function readScannerText(path: string): Promise<string> {\n return strictUtf8.decode(await readScannerBytes(path));\n}\n\nexport function parseJsonOrJsonl(contents: string): unknown {\n try {\n return JSON.parse(contents);\n } catch {\n return contents\n .split(/\\r?\\n/u)\n .filter((line) => line.trim())\n .map((line) => JSON.parse(line));\n }\n}\n\nexport async function readScannerJson(path: string): Promise<unknown> {\n const bytes = await readScannerBytes(path);\n let decoded: string;\n try {\n decoded = strictUtf8.decode(bytes);\n } catch (error) {\n throw new CodexSecurityError(\n `Scanner report is not valid UTF-8. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n try {\n return JSON.parse(decoded.replace(/^\\uFEFF/u, \"\"));\n } catch (error) {\n throw new CodexSecurityError(\n `Scanner JSON could not be parsed. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n}\n\n/** Empty reference containers and property-bag metadata do not externalize data. */\nexport function hasSarifExternalPropertyReferences(value: unknown): boolean {\n if (value == null) return false;\n return Object.entries(\n record(value, \"SARIF external property references\"),\n ).some(\n ([key, references]) =>\n key !== \"properties\" &&\n (!Array.isArray(references) || references.length > 0),\n );\n}\n\nconst sarifArtifactLocationFields = new Set([\n \"artifactLocation\",\n \"analysisTarget\",\n \"executableLocation\",\n \"workingDirectory\",\n \"stdin\",\n \"stdout\",\n \"stderr\",\n \"stdoutStderr\",\n \"mappedTo\",\n \"displayBase\",\n]);\n\n/** Keep original artifact indexes; omit only inventory unrelated to this finding. */\nexport function sarifRunContextForResult(\n runContext: Record<string, unknown>,\n ...selectedEvidence: unknown[]\n): Record<string, unknown> {\n const { artifacts, ...context } = runContext;\n if (!Array.isArray(artifacts) || artifacts.length === 0) return runContext;\n const locations: Record<string, unknown>[] = [];\n let hasArtifactLink = false;\n function visit(value: unknown): void {\n if (typeof value === \"string\") {\n // SARIF message links can refer to an artifact without an artifactLocation.\n if (/sarif:/iu.test(value)) hasArtifactLink = true;\n } else if (Array.isArray(value)) value.forEach(visit);\n else if (isRecord(value))\n for (const [key, child] of Object.entries(value)) {\n if (key === \"properties\") continue;\n if (sarifArtifactLocationFields.has(key) && isRecord(child))\n locations.push(child);\n if (\n [\"locations\", \"responseFiles\", \"analysisToolLogFiles\"].includes(\n key,\n ) &&\n Array.isArray(child)\n )\n locations.push(...child.filter(isRecord));\n if (key === \"originalUriBaseIds\" && isRecord(child))\n locations.push(...Object.values(child).filter(isRecord));\n visit(child);\n }\n }\n visit([context, ...selectedEvidence]);\n if (hasArtifactLink) return runContext;\n const unresolvedUri = /[%:\\\\]|(?:^|\\/)\\.\\.?(?:\\/|$)/u;\n for (const location of locations) {\n if (typeof location[\"index\"] === \"number\" && location[\"index\"] >= 0)\n return runContext;\n if (typeof location[\"uri\"] !== \"string\") continue;\n for (const artifact of artifacts) {\n if (!isRecord(artifact) || !isRecord(artifact[\"location\"])) continue;\n const candidate = artifact[\"location\"];\n // Keep URI spellings that need resolution; evidence is never rewritten.\n if (\n location[\"uriBaseId\"] !== candidate[\"uriBaseId\"] ||\n unresolvedUri.test(location[\"uri\"]) ||\n (typeof candidate[\"uri\"] === \"string\" &&\n unresolvedUri.test(candidate[\"uri\"])) ||\n location[\"uri\"] === candidate[\"uri\"]\n )\n return runContext;\n }\n }\n return context;\n}\n\n/** Exclude every colliding record: choosing the first could overwrite another occurrence. */\nexport function normalizeRecords<T>(\n records: T[],\n normalize: (record: T, id: string) => ExternalFinding,\n identify: (record: T) => string,\n target: \"local\" | \"cloud\" = \"cloud\",\n): ExternalFindings {\n const result: ExternalFindings = {\n read: records.length,\n findings: [],\n excluded: [],\n };\n const identified: { position: number; value: T; id: string }[] = [];\n const counts = new Map<string, number>();\n for (const [index, value] of records.entries()) {\n try {\n const id = identify(value);\n if (\n !id.trim() ||\n id.includes(\"\\0\") ||\n (target === \"cloud\" && Buffer.byteLength(id) > 512)\n )\n throw new Error(\n target === \"cloud\"\n ? \"Source finding ID must contain 1–512 UTF-8 bytes and no NUL characters.\"\n : \"Source finding ID must be nonempty and contain no NUL characters.\",\n );\n identified.push({ position: index + 1, value, id });\n counts.set(id, (counts.get(id) ?? 0) + 1);\n } catch (error) {\n result.excluded.push({\n position: index + 1,\n source_finding_id: null,\n reason: errorMessage(error),\n });\n }\n }\n for (const { position, value, id } of identified) {\n if (counts.get(id)! > 1) {\n result.excluded.push({\n position,\n source_finding_id: id,\n reason:\n \"Ambiguous duplicate source identity; select one complete finding or separate source projects.\",\n });\n continue;\n }\n try {\n const finding = normalize(value, id);\n if (finding.source_finding_id !== id)\n throw new Error(\"Finding identity changed during normalization.\");\n result.findings.push(finding);\n } catch (error) {\n result.excluded.push({\n position,\n source_finding_id: id,\n reason: errorMessage(error),\n });\n }\n }\n result.excluded.sort((a, b) => a.position - b.position);\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scanner-import.js","sourceRoot":"","sources":["../src/scanner-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,UAAU,MAAM,CAAC,KAAc,EA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E,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IACxD,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { hash } from \"node:crypto\";\nimport { readFile, type FileHandle } from \"node:fs/promises\";\nimport { posix } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { gunzip } from \"node:zlib\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport { previousAdmission } from \"./external-import-contract.js\";\nimport { rememberPreviousSelection } from \"./reader-selection.js\";\n\nexport function record(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== \"object\" || Array.isArray(value))\n throw new Error(`${label} must be an object.`);\n return value as Record<string, unknown>;\n}\n\nexport function array(value: unknown, label: string): unknown[] {\n if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);\n return value;\n}\n\nexport function text(value: unknown): string | null {\n return typeof value === \"string\" && value.trim() ? value : null;\n}\n\nexport function requiredText(value: unknown, label: string): string {\n const result = text(value);\n if (!result) throw new Error(`${label} must be nonempty text.`);\n return result;\n}\n\nexport function strings(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((v): v is string => text(v) !== null)\n : [];\n}\n\n/** Paths that cannot be attributed to a repository stay in original evidence. */\nexport function relativePath(value: unknown): string | null {\n const path = text(value)?.replaceAll(\"\\\\\", \"/\");\n return path &&\n !path.startsWith(\"/\") &&\n !path.includes(\"\\0\") &&\n !/^[A-Za-z]:/.test(path) &&\n !path.split(\"/\").includes(\"..\")\n ? path\n : null;\n}\n\nexport function repositoryFilePath(value: unknown): string | null {\n const relative = relativePath(value);\n if (!relative) return null;\n const path = posix.normalize(relative);\n // Anchor the SCP branch at the first eligible @ to avoid rescanning long filenames.\n return path === \".\" ||\n path.endsWith(\"/\") ||\n /^(?:[a-z][a-z\\d+.-]*:|~[^/]*(?:\\/|$)|[^/][^/@]*@[^/]+:)/iu.test(path)\n ? null\n : path;\n}\n\nexport function stableId(prefix: string, fields: unknown[]): string {\n return `${prefix}:${hash(\"sha256\", JSON.stringify(fields))}`;\n}\n\nconst strictUtf8 = new TextDecoder(\"utf-8\", { fatal: true });\nconst gunzipAsync = promisify(gunzip);\n\nasync function readScannerBytes(path: string | FileHandle): Promise<Buffer> {\n const bytes = await readFile(path);\n return bytes[0] === 0x1f && bytes[1] === 0x8b ? gunzipAsync(bytes) : bytes;\n}\n\nexport async function readScannerText(path: string): Promise<string> {\n return strictUtf8.decode(await readScannerBytes(path));\n}\n\nexport function parseJsonOrJsonl(contents: string): unknown {\n try {\n return JSON.parse(contents);\n } catch {\n return contents\n .split(/\\r?\\n/u)\n .filter((line) => line.trim())\n .map((line) => JSON.parse(line));\n }\n}\n\nexport async function readScannerJson(\n path: string | FileHandle,\n): Promise<unknown> {\n const bytes = await readScannerBytes(path);\n let decoded: string;\n try {\n decoded = strictUtf8.decode(bytes);\n } catch (error) {\n throw new CodexSecurityError(\n `Scanner report is not valid UTF-8. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n try {\n return JSON.parse(decoded.replace(/^\\uFEFF/u, \"\"));\n } catch (error) {\n throw new CodexSecurityError(\n `Scanner JSON could not be parsed. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n}\n\n/** Empty reference containers and property-bag metadata do not externalize data. */\nexport function hasSarifExternalPropertyReferences(value: unknown): boolean {\n if (value == null) return false;\n return Object.entries(\n record(value, \"SARIF external property references\"),\n ).some(\n ([key, references]) =>\n key !== \"properties\" &&\n (!Array.isArray(references) || references.length > 0),\n );\n}\n\nconst sarifArtifactLocationFields = new Set([\n \"artifactLocation\",\n \"analysisTarget\",\n \"executableLocation\",\n \"workingDirectory\",\n \"stdin\",\n \"stdout\",\n \"stderr\",\n \"stdoutStderr\",\n \"mappedTo\",\n \"displayBase\",\n]);\n\nfunction sarifArtifactReferences(evidence: unknown) {\n const locations: Record<string, unknown>[] = [];\n let hasArtifactLink = false;\n function visit(value: unknown): void {\n if (typeof value === \"string\") {\n // SARIF message links can refer to an artifact without an artifactLocation.\n if (/sarif:/iu.test(value)) hasArtifactLink = true;\n } else if (Array.isArray(value)) value.forEach(visit);\n else if (isRecord(value))\n for (const [key, child] of Object.entries(value)) {\n if (key === \"properties\") continue;\n if (sarifArtifactLocationFields.has(key) && isRecord(child))\n locations.push(child);\n if (\n [\"locations\", \"responseFiles\", \"analysisToolLogFiles\"].includes(\n key,\n ) &&\n Array.isArray(child)\n )\n locations.push(...child.filter(isRecord));\n if (key === \"originalUriBaseIds\" && isRecord(child))\n locations.push(...Object.values(child).filter(isRecord));\n visit(child);\n }\n }\n visit(evidence);\n return { locations, hasArtifactLink };\n}\n\nconst unresolvedUri = /[%:\\\\]|(?:^|\\/)\\.\\.?(?:\\/|$)/u;\n\nfunction artifactUriMatcher(artifacts: unknown[]) {\n const uris = new Set<string>();\n let hasLocation = false;\n let base: unknown;\n for (const artifact of artifacts) {\n if (!isRecord(artifact) || !isRecord(artifact[\"location\"])) continue;\n const { uri, uriBaseId } = artifact[\"location\"];\n // Mixed bases or a URI that needs resolution can match any direct reference.\n if (\n (hasLocation && uriBaseId !== base) ||\n (typeof uri === \"string\" && unresolvedUri.test(uri))\n )\n return () => true;\n hasLocation = true;\n base = uriBaseId;\n if (typeof uri === \"string\") uris.add(uri);\n }\n return (uri: string, uriBaseId: unknown) =>\n hasLocation &&\n (uriBaseId !== base || unresolvedUri.test(uri) || uris.has(uri));\n}\n\n/** Keep original artifact indexes; omit only inventory unrelated to this finding. */\nexport function sarifRunContextSelector(runContext: Record<string, unknown>) {\n const { artifacts, ...context } = runContext;\n if (!Array.isArray(artifacts) || artifacts.length === 0)\n return () => runContext;\n let matchesUri: ReturnType<typeof artifactUriMatcher> | undefined;\n return (...selectedEvidence: unknown[]) => {\n const { locations, hasArtifactLink } = sarifArtifactReferences([\n context,\n ...selectedEvidence,\n ]);\n if (hasArtifactLink) return runContext;\n for (const location of locations) {\n const { index, uri, uriBaseId } = location;\n if (typeof index === \"number\" && index >= 0) return runContext;\n if (typeof uri === \"string\") {\n matchesUri ??= artifactUriMatcher(artifacts);\n if (matchesUri(uri, uriBaseId)) return runContext;\n }\n }\n return context;\n };\n}\n\ntype IndexedSarifRule = { rule: Record<string, unknown>; index: number };\n\n/** Duplicate IDs cannot identify a single rule in this run. */\nexport function indexSarifRules(\n entries: Iterable<[number, Record<string, unknown>]>,\n) {\n const byId = new Map<unknown, IndexedSarifRule | null>();\n for (const [index, rule] of entries) {\n const id = rule[\"id\"];\n byId.set(id, byId.has(id) ? null : { rule, index });\n }\n return byId;\n}\n\n/** Pair each result with its shared run context and original evidence. */\nexport function sarifRunResults(\n document: Record<string, unknown>,\n run: Record<string, unknown>,\n tool: Record<string, unknown>,\n driver: Record<string, unknown>,\n producer: \"Endor\" | \"Semgrep\",\n) {\n const rules = array(driver[\"rules\"] ?? [], `${producer} rules`).map((rule) =>\n record(rule, `${producer} rule`),\n );\n const rulesById = indexSarifRules(rules.entries());\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 const selectRunContext = sarifRunContextSelector(runContext);\n // JS callers may supply lazy metadata. Preserve each adapter's original traversal order.\n const metadataInReadOrder =\n producer === \"Semgrep\"\n ? [driverContext, toolContext, documentContext]\n : [documentContext, driverContext, toolContext];\n const context = {\n rulesById,\n runContext,\n sourceData(\n result: Record<string, unknown>,\n rule?: Record<string, unknown>,\n ) {\n return structuredClone({\n documentContext,\n runContext: selectRunContext(result, rule, ...metadataInReadOrder),\n driverContext,\n toolContext,\n ...(rule ? { rule } : {}),\n result,\n });\n },\n };\n return array(run[\"results\"] ?? [], `${producer} results`).map((result) => ({\n result,\n context,\n }));\n}\n\n/** The top-level index and nested descriptor must agree with the selected driver rule. */\nexport function validateSarifRuleReference(\n result: Record<string, unknown>,\n ruleId: string,\n selected: IndexedSarifRule | undefined,\n producer: \"Endor\" | \"Semgrep\" | \"Snyk\",\n) {\n // Snyk's original diagnostics use unqualified SARIF field names.\n const label = producer === \"Snyk\" ? \"Result\" : producer;\n if (\n result[\"ruleIndex\"] !== undefined &&\n result[\"ruleIndex\"] !== selected?.index\n )\n throw new Error(`${label} ruleIndex and ruleId disagree.`);\n if (result[\"rule\"] === undefined) return;\n const reference = record(\n result[\"rule\"],\n producer === \"Snyk\" ? \"Rule reference\" : `${producer} rule reference`,\n );\n if (\n reference[\"toolComponent\"] !== undefined ||\n (reference[\"id\"] !== undefined && reference[\"id\"] !== ruleId) ||\n (reference[\"index\"] !== undefined &&\n reference[\"index\"] !== selected?.index) ||\n (reference[\"guid\"] !== undefined &&\n reference[\"guid\"] !== selected?.rule[\"guid\"])\n )\n throw new Error(\n producer === \"Snyk\"\n ? \"Result uses an inconsistent or external rule reference.\"\n : `Inconsistent or external ${producer} rule reference.`,\n );\n}\n\ninterface SizeChange {\n index: number;\n position: number;\n id: string;\n previous: ExternalFinding[\"evidence\"] | null;\n}\n\ntype SelectionFilter = (\n selection: ExternalFindings,\n removedIds?: Set<string>,\n) => void;\n\n/** Track older size decisions while a single reader constructs its result. */\nexport function trackReaderSelection(result: ExternalFindings) {\n const changes: SizeChange[] = [];\n const uncertainIds = new Set<string>();\n\n function append(\n position: number,\n id: string,\n project: () => ExternalFinding[\"evidence\"],\n ) {\n const index = result.findings.length;\n let outcome: unknown;\n try {\n const evidence = project();\n outcome = evidence;\n result.findings.push({ source_finding_id: id, evidence });\n } catch (error) {\n outcome = error;\n result.excluded.push({\n position,\n source_finding_id: id,\n reason: errorMessage(error),\n });\n }\n const previous =\n outcome && typeof outcome === \"object\"\n ? previousAdmission(outcome)\n : undefined;\n if (previous === \"uncertain\") uncertainIds.add(id);\n else if (previous !== undefined)\n changes.push({ index, position, id, previous });\n }\n\n function finish(filter?: SelectionFilter): ExternalFindings {\n if (!changes.length && !uncertainIds.size) {\n filter?.(result);\n return result;\n }\n const findings: ExternalFinding[] = [];\n const excluded: ExternalFindings[\"excluded\"] = [];\n const restoredPositions = new Set<number>();\n let cursor = 0;\n for (const { index, position, id, previous } of changes) {\n while (cursor < index) findings.push(result.findings[cursor++]!);\n if (previous) {\n findings.push({ source_finding_id: id, evidence: previous });\n restoredPositions.add(position);\n } else {\n cursor++;\n excluded.push({\n position,\n source_finding_id: id,\n reason: \"Evidence exceeds the Cloud limit of 256 KiB.\",\n });\n }\n }\n while (cursor < result.findings.length)\n findings.push(result.findings[cursor++]!);\n for (const row of result.excluded) {\n if (!restoredPositions.has(row.position)) excluded.push(row);\n }\n excluded.sort((a, b) => a.position - b.position);\n const previous = { ...result, findings, excluded };\n // A removed sibling could have depended on an unproven row for its scope.\n filter?.(previous, uncertainIds.size ? uncertainIds : undefined);\n filter?.(result);\n const sourceFindingIds = [\n ...new Set([\n ...previous.findings.map((row) => row.source_finding_id),\n ...uncertainIds,\n ]),\n ];\n if (uncertainIds.size) {\n rememberPreviousSelection(result, {\n sourceFindingIds,\n uncertainFindingIds: [...uncertainIds],\n knownFindings: structuredClone(\n previous.findings.filter(\n (row) => !uncertainIds.has(row.source_finding_id),\n ),\n ),\n });\n } else {\n rememberPreviousSelection(result, {\n sourceFindingIds,\n snapshot: structuredClone(previous),\n });\n }\n return result;\n }\n\n return { append, finish, uncertainIds };\n}\n\n/** Exclude every colliding record: choosing the first could overwrite another occurrence. */\nexport function normalizeRecords<T>(\n records: T[],\n projectEvidence: (record: T, id: string) => ExternalFinding[\"evidence\"],\n identify: (record: T) => string,\n target: \"local\" | \"cloud\" = \"cloud\",\n options: {\n report?: ExternalFindings[\"report\"];\n filter?: SelectionFilter;\n } = {},\n): ExternalFindings {\n const result: ExternalFindings = {\n read: records.length,\n findings: [],\n excluded: [],\n ...(options.report === undefined ? {} : { report: options.report }),\n };\n const selection = trackReaderSelection(result);\n const identified: { position: number; value: T; id: string }[] = [];\n const counts = new Map<string, number>();\n for (const [index, value] of records.entries()) {\n try {\n const id = identify(value);\n if (\n !id.trim() ||\n id.includes(\"\\0\") ||\n (target === \"cloud\" && Buffer.byteLength(id) > 512)\n )\n throw new Error(\n target === \"cloud\"\n ? \"Source finding ID must contain 1–512 UTF-8 bytes and no NUL characters.\"\n : \"Source finding ID must be nonempty and contain no NUL characters.\",\n );\n identified.push({ position: index + 1, value, id });\n counts.set(id, (counts.get(id) ?? 0) + 1);\n } catch (error) {\n result.excluded.push({\n position: index + 1,\n source_finding_id: null,\n reason: errorMessage(error),\n });\n }\n }\n for (const { position, value, id } of identified) {\n if (counts.get(id)! > 1) {\n result.excluded.push({\n position,\n source_finding_id: id,\n reason:\n \"Ambiguous duplicate source identity; select one complete finding or separate source projects.\",\n });\n continue;\n }\n selection.append(position, id, () => projectEvidence(value, id));\n }\n result.excluded.sort((a, b) => a.position - b.position);\n return selection.finish(options.filter);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Provider } from "./external-import-models.js";
|
|
2
|
+
import { type ExternalImportTarget } from "./external-import-contract.js";
|
|
3
|
+
import type { ExternalFinding, ExternalSourceRepository } from "./external-findings.js";
|
|
4
|
+
export declare function declaredScannerRepositoryUrl(value: unknown, provider: string, target?: ExternalImportTarget): string;
|
|
5
|
+
/** Check the repository declared for each retained native scope. */
|
|
6
|
+
export declare function repositoryScopeValidator(scanner: {
|
|
7
|
+
provider: Provider;
|
|
8
|
+
label: string;
|
|
9
|
+
scope: string;
|
|
10
|
+
}, retainedRepository: (provider: Provider, finding: ExternalFinding, target: ExternalImportTarget) => {
|
|
11
|
+
url: string;
|
|
12
|
+
scope?: string;
|
|
13
|
+
} | undefined): (provider: Provider, findings: readonly ExternalFinding[], target: ExternalImportTarget, sameRepositories?: (urls: Iterable<string>) => boolean) => Map<string, ExternalSourceRepository>;
|
|
14
|
+
//# sourceMappingURL=scanner-repository-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner-repository-url.d.ts","sourceRoot":"","sources":["../src/scanner-repository-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAiBhC,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,oBAA8B,GACrC,MAAM,CAmBR;AAED,oEAAoE;AACpE,wBAAgB,wBAAwB,CACtC,OAAO,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAC7D,kBAAkB,EAAE,CAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,oBAAoB,KACzB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,cAGpC,QAAQ,YACR,SAAS,eAAe,EAAE,UAC5B,oBAAoB,qBACV,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,OAAO,KAOpD,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAsCzC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
|
|
2
|
+
import { requiredText } from "./scanner-import.js";
|
|
3
|
+
function repositorySegment(encoded) {
|
|
4
|
+
try {
|
|
5
|
+
const segment = decodeURIComponent(encoded);
|
|
6
|
+
return (Boolean(segment) &&
|
|
7
|
+
segment.trim() === segment &&
|
|
8
|
+
!["", ".", ".."].includes(segment.replace(/\.git$/iu, "")) &&
|
|
9
|
+
!/[/\\?#\p{Cc}]|%[\da-f]{2}/iu.test(segment));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function declaredScannerRepositoryUrl(value, provider, target = "cloud") {
|
|
16
|
+
const source = requiredText(value, `${provider} --source-repository-url`);
|
|
17
|
+
const url = URL.parse(source);
|
|
18
|
+
const parts = /^https?:\/\/([^/?#\\]+)\/([^?#\\]+)$/iu.exec(source);
|
|
19
|
+
const segments = parts?.[2]?.replace(/\/$/u, "").split("/") ?? [];
|
|
20
|
+
if (!url ||
|
|
21
|
+
!parts ||
|
|
22
|
+
parts[1].includes("@") ||
|
|
23
|
+
/[\s\p{Cc}]/u.test(source) ||
|
|
24
|
+
url.username ||
|
|
25
|
+
url.password ||
|
|
26
|
+
segments.length < (target === "local" ? 1 : 2) ||
|
|
27
|
+
!segments.every(repositorySegment))
|
|
28
|
+
throw new Error(`${provider} --source-repository-url requires an HTTP(S) repository path without credentials, query, fragment, or ambiguous path segments.`);
|
|
29
|
+
return source;
|
|
30
|
+
}
|
|
31
|
+
/** Check the repository declared for each retained native scope. */
|
|
32
|
+
export function repositoryScopeValidator(scanner, retainedRepository) {
|
|
33
|
+
return (provider, findings, target, sameRepositories = (urls) => new Set(Array.from(urls, target === "cloud" ? cloudRepositoryUrlKey : repositoryUrlKey)).size <= 1) => {
|
|
34
|
+
const repositories = new Map();
|
|
35
|
+
const wholeReport = provider === "blackduck" && scanner.provider === provider;
|
|
36
|
+
const scopes = new Set();
|
|
37
|
+
const sources = new Set();
|
|
38
|
+
for (const finding of findings) {
|
|
39
|
+
const { source_finding_id: id, evidence } = finding;
|
|
40
|
+
const retained = retainedRepository(provider, finding, target);
|
|
41
|
+
const declared = evidence.details?.repository?.url;
|
|
42
|
+
// A Black Duck BOM binds its entire report. Other scopes bind their native rows.
|
|
43
|
+
if (wholeReport || retained?.scope) {
|
|
44
|
+
if (declared)
|
|
45
|
+
sources.add(declared);
|
|
46
|
+
if (retained)
|
|
47
|
+
sources.add(retained.url);
|
|
48
|
+
}
|
|
49
|
+
if (!retained)
|
|
50
|
+
continue;
|
|
51
|
+
if (retained.scope)
|
|
52
|
+
scopes.add(retained.scope);
|
|
53
|
+
if (declared &&
|
|
54
|
+
declared !== retained.url &&
|
|
55
|
+
!sameRepositories([declared, retained.url]))
|
|
56
|
+
throw new Error("Retained scanner repository does not match the normalized evidence repository.");
|
|
57
|
+
repositories.set(id, { url: retained.url });
|
|
58
|
+
}
|
|
59
|
+
if (scopes.size > 1 ||
|
|
60
|
+
((scopes.size > 0 || (wholeReport && target === "local")) &&
|
|
61
|
+
sources.size > 1 &&
|
|
62
|
+
!sameRepositories(sources)))
|
|
63
|
+
throw new Error(`${scanner.label} occurrences must belong to the same ${scanner.scope} and source repository.`);
|
|
64
|
+
return repositories;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=scanner-repository-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner-repository-url.js","sourceRoot":"","sources":["../src/scanner-repository-url.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AAKvC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,SAAS,iBAAiB,CAAC,OAAe;IACxC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,CACL,OAAO,CAAC,OAAO,CAAC;YAChB,OAAO,CAAC,IAAI,EAAE,KAAK,OAAO;YAC1B,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAC1D,CAAC,6BAA6B,CAAC,IAAI,CAAC,O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E,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,IACE,MAAM,CAAC,IAAI,GAAG,CAAC;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC;gBACvD,OAAO,CAAC,IAAI,GAAG,CAAC;gBAChB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAE7B,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,CAAC,KAAK,wCAAwC,OAAO,CAAC,KAAK,yBAAyB,CAC/F,CAAC;QACJ,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Provider } from \"./external-import-models.js\";\nimport {\n type ExternalImportTarget,\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport type {\n ExternalFinding,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { requiredText } from \"./scanner-import.js\";\n\nfunction repositorySegment(encoded: string): boolean {\n try {\n const segment = decodeURIComponent(encoded);\n return (\n Boolean(segment) &&\n segment.trim() === segment &&\n ![\"\", \".\", \"..\"].includes(segment.replace(/\\.git$/iu, \"\")) &&\n !/[/\\\\?#\\p{Cc}]|%[\\da-f]{2}/iu.test(segment)\n );\n } catch {\n return false;\n }\n}\n\nexport function declaredScannerRepositoryUrl(\n value: unknown,\n provider: string,\n target: ExternalImportTarget = \"cloud\",\n): string {\n const source = requiredText(value, `${provider} --source-repository-url`);\n const url = URL.parse(source);\n const parts = /^https?:\\/\\/([^/?#\\\\]+)\\/([^?#\\\\]+)$/iu.exec(source);\n const segments = parts?.[2]?.replace(/\\/$/u, \"\").split(\"/\") ?? [];\n if (\n !url ||\n !parts ||\n parts[1]!.includes(\"@\") ||\n /[\\s\\p{Cc}]/u.test(source) ||\n url.username ||\n url.password ||\n segments.length < (target === \"local\" ? 1 : 2) ||\n !segments.every(repositorySegment)\n )\n throw new Error(\n `${provider} --source-repository-url requires an HTTP(S) repository path without credentials, query, fragment, or ambiguous path segments.`,\n );\n return source;\n}\n\n/** Check the repository declared for each retained native scope. */\nexport function repositoryScopeValidator(\n scanner: { provider: Provider; label: string; scope: string },\n retainedRepository: (\n provider: Provider,\n finding: ExternalFinding,\n target: ExternalImportTarget,\n ) => { url: string; scope?: string } | undefined,\n) {\n return (\n provider: Provider,\n findings: readonly ExternalFinding[],\n target: ExternalImportTarget,\n sameRepositories: (urls: Iterable<string>) => boolean = (urls) =>\n new Set(\n Array.from(\n urls,\n target === \"cloud\" ? cloudRepositoryUrlKey : repositoryUrlKey,\n ),\n ).size <= 1,\n ): Map<string, ExternalSourceRepository> => {\n const repositories = new Map<string, ExternalSourceRepository>();\n const wholeReport =\n provider === \"blackduck\" && scanner.provider === provider;\n const scopes = new Set<string>();\n const sources = new Set<string>();\n for (const finding of findings) {\n const { source_finding_id: id, evidence } = finding;\n const retained = retainedRepository(provider, finding, target);\n const declared = evidence.details?.repository?.url;\n // A Black Duck BOM binds its entire report. Other scopes bind their native rows.\n if (wholeReport || retained?.scope) {\n if (declared) sources.add(declared);\n if (retained) sources.add(retained.url);\n }\n if (!retained) continue;\n if (retained.scope) scopes.add(retained.scope);\n if (\n declared &&\n declared !== retained.url &&\n !sameRepositories([declared, retained.url])\n )\n throw new Error(\n \"Retained scanner repository does not match the normalized evidence repository.\",\n );\n repositories.set(id, { url: retained.url });\n }\n if (\n scopes.size > 1 ||\n ((scopes.size > 0 || (wholeReport && target === \"local\")) &&\n sources.size > 1 &&\n !sameRepositories(sources))\n )\n throw new Error(\n `${scanner.label} occurrences must belong to the same ${scanner.scope} and source repository.`,\n );\n return repositories;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semgrep-findings.d.ts","sourceRoot":"","sources":["../src/semgrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAK1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"semgrep-findings.d.ts","sourceRoot":"","sources":["../src/semgrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAK1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAwB/D,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAmHD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAwBlB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAgJlB;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,oBAA8B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CAE3B"}
|