@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
|
@@ -1,186 +1,263 @@
|
|
|
1
|
-
import { lstat, readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
-
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
3
|
-
import { isNumberObject } from "node:util/types";
|
|
4
|
-
import { environmentEntry } from "./auth.js";
|
|
5
1
|
import { CodexSecurityError } from "./errors.js";
|
|
6
2
|
import { forwardExternalImportSetting, requireExternalImports, } from "./external-imports-feature.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { cloneImportPreview, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
|
|
4
|
+
import { cloudRepositoryUrlKey, requireSafeJsonInteger, repositoryUrlKey, } from "./external-import-contract.js";
|
|
5
|
+
import { localFindingRepositories } from "./external-findings-read.js";
|
|
6
|
+
import { hasGitMetadata, localGitProtectionRoots, importGitProtectionRoots, } from "./local-git-metadata.js";
|
|
7
|
+
import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
|
|
8
|
+
import { azureReposHttpsUrl, isGitHubCloudHost, isGitHubSshOverHttps, isGitSsh, parseGitRemote, } from "./git-remote.js";
|
|
9
|
+
import { continuumReportRepositories } from "./continuum-findings.js";
|
|
10
|
+
import { veracodeReportRepositories } from "./veracode-findings.js";
|
|
11
|
+
import { inspectorReportRepository } from "./inspector-findings.js";
|
|
12
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
13
|
+
import { sonarRepositoryUrls } from "./sonar-findings.js";
|
|
9
14
|
import { isRecord } from "./record.js";
|
|
10
15
|
import { dependabotRepository } from "./github-dependabot-findings.js";
|
|
11
16
|
import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
|
|
12
|
-
import { abortable,
|
|
17
|
+
import { abortable, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, } from "./targets.js";
|
|
13
18
|
function requireIdentity(value, field) {
|
|
14
19
|
if (typeof value !== "string" || !value.trim() || value.includes("\0"))
|
|
15
20
|
throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
function checkStoredNumber(value) {
|
|
23
|
+
if (!Number.isFinite(value))
|
|
24
|
+
throw new TypeError("Stored finding JSON cannot contain non-finite numbers.");
|
|
25
|
+
requireSafeJsonInteger(value, "Stored finding JSON");
|
|
26
|
+
}
|
|
27
|
+
const gitTransportPorts = {
|
|
28
|
+
"http:": "80",
|
|
29
|
+
"https:": "443",
|
|
30
|
+
"ssh:": "22",
|
|
31
|
+
"git+ssh:": "22",
|
|
32
|
+
"ssh+git:": "22",
|
|
33
|
+
"git:": "9418",
|
|
34
|
+
"ftp:": "21",
|
|
35
|
+
"ftps:": "990",
|
|
36
|
+
};
|
|
37
|
+
function sonarHostedGit(hostname) {
|
|
38
|
+
return (isGitHubCloudHost(hostname) ||
|
|
39
|
+
hostname === "gitlab.com" ||
|
|
40
|
+
hostname === "bitbucket.org");
|
|
41
|
+
}
|
|
42
|
+
function sonarHostedHostname(hostname) {
|
|
43
|
+
const name = hostname.toLowerCase().replace(/\.$/u, "");
|
|
44
|
+
return sonarHostedGit(name) ||
|
|
45
|
+
["ssh.github.com", "ssh.dev.azure.com", "dev.azure.com"].includes(name)
|
|
46
|
+
? name
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
function remoteRepository(value, provider, bound, platform = provider, possibleSshHost) {
|
|
19
50
|
if (/^[A-Za-z]:[\\/]/u.test(value))
|
|
20
51
|
return undefined;
|
|
52
|
+
const transport = bound
|
|
53
|
+
? /^(?:ssh|git\+ssh|ssh\+git|git):\/\/([^/]*)(.*)$/isu.exec(value)
|
|
54
|
+
: null;
|
|
55
|
+
const authority = transport?.[1];
|
|
56
|
+
const http = bound && /^https?:\/\//iu.test(value.trimStart());
|
|
57
|
+
// Git decodes the authority before locating its path. An encoded delimiter
|
|
58
|
+
// cannot prove a match to another spelling through WHATWG URL's hostname.
|
|
59
|
+
if (authority &&
|
|
60
|
+
(/%2f|[?#]/iu.test(authority) ||
|
|
61
|
+
authority.slice(authority.lastIndexOf("@") + 1).includes("%")))
|
|
62
|
+
return { key: value };
|
|
21
63
|
let remote;
|
|
22
64
|
try {
|
|
23
65
|
remote = parseGitRemote(value);
|
|
24
66
|
}
|
|
25
67
|
catch {
|
|
26
|
-
return undefined;
|
|
68
|
+
return transport || http ? { key: "\0" + value } : undefined;
|
|
27
69
|
}
|
|
28
|
-
if (!remote ||
|
|
29
|
-
![
|
|
30
|
-
"http:",
|
|
31
|
-
"https:",
|
|
32
|
-
"ssh:",
|
|
33
|
-
"git:",
|
|
34
|
-
"ftp:",
|
|
35
|
-
"ftps:",
|
|
36
|
-
"git+ssh:",
|
|
37
|
-
"ssh+git:",
|
|
38
|
-
].includes(remote.url.protocol))
|
|
70
|
+
if (!remote || !Object.hasOwn(gitTransportPorts, remote.url.protocol))
|
|
39
71
|
return undefined;
|
|
40
|
-
const url = remote
|
|
41
|
-
const ssh =
|
|
72
|
+
const { url, path, scpStyle } = remote;
|
|
73
|
+
const ssh = isGitSsh(url.protocol);
|
|
42
74
|
const protocol = url.protocol === "http:" ? "http:" : "https:";
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
url.
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
const hosted = sonarHostedHostname(url.hostname);
|
|
76
|
+
if (provider === "sonar" && hosted)
|
|
77
|
+
url.hostname = hosted;
|
|
78
|
+
const githubSshOverHttps = isGitHubSshOverHttps(url);
|
|
79
|
+
let hostname = githubSshOverHttps ? "github.com" : url.hostname;
|
|
80
|
+
// An unresolved SSH name can be a local Host alias. Only substitute the
|
|
81
|
+
// supplied hostname when checking the path of an unverified manual mapping.
|
|
82
|
+
if (possibleSshHost && ssh && (!hosted || hosted === "dev.azure.com"))
|
|
83
|
+
hostname = sonarHostedHostname(possibleSshHost) ?? possibleSshHost;
|
|
84
|
+
const port = githubSshOverHttps || url.port === gitTransportPorts[url.protocol]
|
|
52
85
|
? ""
|
|
53
86
|
: url.port;
|
|
54
87
|
// A GitHub source identifies a case-insensitive repository on custom Enterprise
|
|
55
88
|
// hosts too; other providers can refer to VCS hosts with case-sensitive paths.
|
|
56
|
-
const key =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const head = await abortable(() => lstat(join(directory, "HEAD")).catch(nullIfMissingPath), signal);
|
|
67
|
-
if ((head?.isFile() || head?.isSymbolicLink()) &&
|
|
68
|
-
((await present("commondir")) ||
|
|
69
|
-
((await present("objects")) && (await present("refs")))))
|
|
70
|
-
roots.push(directory);
|
|
71
|
-
const parent = dirname(directory);
|
|
72
|
-
if (parent === directory)
|
|
73
|
-
return roots;
|
|
74
|
-
directory = parent;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async function metadataPointer(path, prefix, context, signal) {
|
|
78
|
-
const metadata = await abortable(() => stat(path).catch(nullIfMissingPath), signal);
|
|
79
|
-
if (!metadata?.isFile())
|
|
80
|
-
return undefined;
|
|
81
|
-
const text = await abortable(() => readFile(path, "utf8"), signal);
|
|
82
|
-
if (!text.startsWith(prefix) || (prefix === "" && text.length === 0))
|
|
83
|
-
return undefined;
|
|
84
|
-
const payload = text.slice(prefix.length).replace(/[\r\n]+$/u, "");
|
|
85
|
-
if (prefix !== "" && payload.length === 0)
|
|
86
|
-
return undefined;
|
|
87
|
-
// Git checks emptiness before consuming the path as a NUL-terminated string.
|
|
88
|
-
const value = payload.split("\0", 1)[0];
|
|
89
|
-
// Preserve filesystem traversal through links before '..'.
|
|
90
|
-
let target = isAbsolute(value) ? value : `${dirname(path)}${sep}${value}`;
|
|
91
|
-
if (process.platform === "win32") {
|
|
92
|
-
const drive = /^[A-Za-z]:(?![\\/])/u.exec(value)?.[0].toUpperCase();
|
|
93
|
-
if (drive !== undefined) {
|
|
94
|
-
const directory = context.directory.slice(0, 2).toUpperCase() === drive
|
|
95
|
-
? context.directory
|
|
96
|
-
: environmentEntry(context.environment, `=${drive}`) || `${drive}\\`;
|
|
97
|
-
target = resolve(directory, value.slice(2));
|
|
89
|
+
const key = platform === "github" ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
90
|
+
const origin = `${protocol}//${hostname}${port ? `:${port}` : ""}/`;
|
|
91
|
+
if (!bound)
|
|
92
|
+
return { key: key(origin + path) };
|
|
93
|
+
if (!ssh && url.protocol !== "git:") {
|
|
94
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
95
|
+
// libcurl and WHATWG differ on backslashes and encoded dot segments.
|
|
96
|
+
const raw = /^https?:\/\/[^/\\?#\s]+(\/[^\\?#]*)?(?:[?#].*)?$/iu.exec(value);
|
|
97
|
+
if (!raw || /\/(?:%2e|\.%2e|%2e\.|%2e%2e)(?:\/|$)/iu.test(raw[1] ?? ""))
|
|
98
|
+
return { key: "\0" + value };
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
const suffix = /[?#].*$/su.exec(value)?.[0] ?? "";
|
|
101
|
+
// HTTP sends the query and omits fragment text from repository requests.
|
|
102
|
+
if (suffix && !["http:", "https:"].includes(url.protocol))
|
|
103
|
+
return { key: key(origin + path) + "\0" };
|
|
104
|
+
return {
|
|
105
|
+
key: key(origin + path) + suffix.replace(/#.*$/su, "#").replace(/\/$/u, ""),
|
|
106
|
+
};
|
|
101
107
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
// Git passes the original path (including dot segments, '?' and '#') to upload-pack.
|
|
109
|
+
const literal = (raw) => {
|
|
110
|
+
const bytes = Buffer.from(raw).toString("latin1");
|
|
111
|
+
return scpStyle
|
|
112
|
+
? bytes
|
|
113
|
+
: bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
114
|
+
};
|
|
115
|
+
if (!scpStyle && !transport)
|
|
116
|
+
return { key: value };
|
|
117
|
+
const gitPath = literal(transport?.[2] ?? path);
|
|
118
|
+
const login = scpStyle
|
|
119
|
+
? /^([^@/:\s?#]+)@/u.exec(value)?.[1]
|
|
120
|
+
: /^(.*)@/u.exec(authority ?? "")?.[1];
|
|
121
|
+
const homeRelative = /^\/?~(?:\/|$)/u.test(gitPath) || (scpStyle && !/^[~/]/u.test(gitPath));
|
|
122
|
+
const suffix = /[?#].*$/su.exec(gitPath);
|
|
123
|
+
// Express upload-pack bytes as a URL path for comparison with the HTTP source.
|
|
124
|
+
const name = gitPath
|
|
125
|
+
.slice(0, suffix?.index)
|
|
126
|
+
.replace(/^\//u, "")
|
|
127
|
+
.replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
|
|
128
|
+
// Azure's generated SCP clone URL spells spaces as %20, even though Git sends SCP paths literally.
|
|
129
|
+
const azure = provider === "sonar" && !(scpStyle && path.startsWith("/"))
|
|
130
|
+
? azureReposHttpsUrl(url, scpStyle ? name.replace(/%2520/gu, "%20") : name)
|
|
112
131
|
: undefined;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Git rereads commondir after changing to the discovered repository root.
|
|
126
|
-
roots.push(...(await associatedMetadataRoots(directory, {
|
|
127
|
-
...context,
|
|
128
|
-
directory: await abortable(() => canonicalConfigPath(configurationDirectory), signal),
|
|
129
|
-
}, signal)));
|
|
130
|
-
}
|
|
131
|
-
return roots;
|
|
132
|
-
}
|
|
133
|
-
async function localGitProtectionRoots(repository, environment, signal) {
|
|
134
|
-
const roots = new Set(await abortable(() => gitProtectionRoots(repository, signal), signal));
|
|
135
|
-
const context = {
|
|
136
|
-
directory: await abortable(() => canonicalConfigPath(repository), signal),
|
|
137
|
-
environment,
|
|
132
|
+
const repository = suffix
|
|
133
|
+
? key(origin + name + "?") +
|
|
134
|
+
"\0" +
|
|
135
|
+
suffix[0].replace(/\/$/u, "").replace(/\.git$/u, "")
|
|
136
|
+
: key(azure ?? origin + name);
|
|
137
|
+
return {
|
|
138
|
+
key: repository,
|
|
139
|
+
account: ssh && login ? literal(login) : undefined,
|
|
140
|
+
// GitHub serves the same repository path through its SCP and SSH URLs.
|
|
141
|
+
homeRelative: ssh && platform !== "github" && !isGitHubCloudHost(hostname.toLowerCase())
|
|
142
|
+
? homeRelative
|
|
143
|
+
: undefined,
|
|
138
144
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
}
|
|
146
|
+
function matchingRemote(left, right) {
|
|
147
|
+
return (left.key === right.key &&
|
|
148
|
+
(left.homeRelative === undefined ||
|
|
149
|
+
right.homeRelative === undefined ||
|
|
150
|
+
left.homeRelative === right.homeRelative) &&
|
|
151
|
+
((left.homeRelative === false && right.homeRelative === false) ||
|
|
152
|
+
left.account === undefined ||
|
|
153
|
+
right.account === undefined ||
|
|
154
|
+
left.account === right.account));
|
|
155
|
+
}
|
|
156
|
+
/** A credential-free Sonar repository binding from a supported Git fetch transport. */
|
|
157
|
+
export function sonarRepositoryForRemote(origin) {
|
|
158
|
+
try {
|
|
159
|
+
if (/[\s\\\p{Cc}?#]/u.test(origin))
|
|
160
|
+
return;
|
|
161
|
+
const remote = parseGitRemote(origin);
|
|
162
|
+
if (!remote)
|
|
163
|
+
return;
|
|
164
|
+
const { url } = remote;
|
|
165
|
+
// Git dispatches remote helpers by the literal scheme, while URL lowercases it.
|
|
166
|
+
if (!remote.scpStyle && !origin.startsWith(url.protocol + "//"))
|
|
167
|
+
return;
|
|
168
|
+
// Git passes literal SSH paths to upload-pack. URL.pathname collapses dot segments.
|
|
169
|
+
const path = remote.scpStyle
|
|
170
|
+
? remote.path
|
|
171
|
+
: /^[^:/]+:\/\/[^/]+\/(.+)$/u.exec(origin)?.[1];
|
|
172
|
+
if (!path)
|
|
173
|
+
return;
|
|
174
|
+
const hostname = url.hostname.toLowerCase();
|
|
175
|
+
let candidate;
|
|
176
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
177
|
+
candidate = `${url.origin}/${path}`;
|
|
145
178
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
? await abortable(() => realpath(marker), signal)
|
|
155
|
-
: await metadataPointer(marker, "gitdir: ", context, signal);
|
|
156
|
-
if (gitDirectory !== undefined)
|
|
157
|
-
for (const associated of await associatedMetadataRoots(gitDirectory, context, signal, directory))
|
|
158
|
-
roots.add(associated);
|
|
159
|
-
}
|
|
160
|
-
const parent = dirname(directory);
|
|
161
|
-
if (parent === directory)
|
|
162
|
-
break;
|
|
163
|
-
directory = parent;
|
|
179
|
+
else if (url.username === "git" && isGitHubSshOverHttps(url)) {
|
|
180
|
+
candidate = `https://github.com/${path}`;
|
|
181
|
+
}
|
|
182
|
+
else if (isGitSsh(url.protocol) &&
|
|
183
|
+
url.username === "git" &&
|
|
184
|
+
(!url.port || url.port === "22") &&
|
|
185
|
+
sonarHostedGit(hostname)) {
|
|
186
|
+
candidate = `https://${hostname}/${path}`;
|
|
164
187
|
}
|
|
188
|
+
else {
|
|
189
|
+
candidate = azureReposHttpsUrl(url, path);
|
|
190
|
+
}
|
|
191
|
+
if (!candidate)
|
|
192
|
+
return;
|
|
193
|
+
const source = declaredScannerRepositoryUrl(candidate.replace(/\.git$/iu, ""), "Sonar", "local");
|
|
194
|
+
const candidateRemote = remoteRepository(origin, "sonar", true);
|
|
195
|
+
const target = remoteRepository(source, "sonar", true);
|
|
196
|
+
if (isGitSsh(url.protocol) && candidateRemote?.account !== "git")
|
|
197
|
+
return;
|
|
198
|
+
return candidateRemote && target && matchingRemote(candidateRemote, target)
|
|
199
|
+
? source
|
|
200
|
+
: undefined;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return undefined;
|
|
165
204
|
}
|
|
166
|
-
for (const root of [...roots])
|
|
167
|
-
roots.add(await abortable(() => canonicalConfigPath(root), signal));
|
|
168
|
-
return [...roots];
|
|
169
205
|
}
|
|
170
|
-
|
|
171
|
-
|
|
206
|
+
/** Use the same executable and configuration boundaries for every Git query proving a binding. */
|
|
207
|
+
export function boundSonarWorktree(repository, protectedRoots, environment, signal) {
|
|
208
|
+
return enclosingGitWorktreeRoot(repository, signal, {
|
|
209
|
+
requireIfPresent: true,
|
|
210
|
+
readGit: (directory, args) => gitOutput(directory, args, signal, undefined, undefined, "utf8", protectedRoots, environment),
|
|
211
|
+
});
|
|
172
212
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
213
|
+
function localRepositoryPlatform(provider, sources, bound) {
|
|
214
|
+
const githubKey = (url) => remoteRepository(url, provider, bound, "github")?.key;
|
|
215
|
+
const githubRepositories = new Set(sources.flatMap((source) => {
|
|
216
|
+
if (source.platform !== "github")
|
|
217
|
+
return [];
|
|
218
|
+
const key = githubKey(source.url);
|
|
219
|
+
return key === undefined ? [] : [key];
|
|
220
|
+
}));
|
|
221
|
+
return (source) => {
|
|
222
|
+
if (source.platform === "github")
|
|
223
|
+
return "github";
|
|
224
|
+
if (githubRepositories.size === 0)
|
|
225
|
+
return provider;
|
|
226
|
+
const key = githubKey(source.url);
|
|
227
|
+
return key !== undefined && githubRepositories.has(key)
|
|
228
|
+
? "github"
|
|
229
|
+
: provider;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function sameScannerRepositories(remotes) {
|
|
233
|
+
let known;
|
|
234
|
+
for (const remote of remotes) {
|
|
235
|
+
if (known && !matchingRemote(known, remote))
|
|
236
|
+
return false;
|
|
237
|
+
// HTTPS does not specify the login or path interpretation carried by SSH.
|
|
238
|
+
known = {
|
|
239
|
+
key: remote.key,
|
|
240
|
+
account: remote.account ?? known?.account,
|
|
241
|
+
homeRelative: remote.homeRelative ?? known?.homeRelative,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
/** @internal Effective fetch URLs from the selected, protected checkout. */
|
|
247
|
+
export async function configuredFetchRemotes(repository, provider, protectedRoots, environment, signal) {
|
|
176
248
|
if (!(await hasGitMetadata(repository, signal)))
|
|
177
|
-
return;
|
|
249
|
+
return [];
|
|
178
250
|
const gitProtectedRoots = [
|
|
179
251
|
...(typeof protectedRoots === "string"
|
|
180
252
|
? [protectedRoots]
|
|
181
253
|
: (protectedRoots ?? [])),
|
|
182
|
-
await abortable(() => canonicalConfigPath(process.cwd()), signal),
|
|
183
254
|
];
|
|
255
|
+
// The Sonar caller includes the discovered Git roots for both checkouts.
|
|
256
|
+
if (provider !== "sonar")
|
|
257
|
+
gitProtectedRoots.push(await abortable(() => canonicalConfigPath(process.cwd()), signal));
|
|
258
|
+
if (provider === "sonar" &&
|
|
259
|
+
!(await boundSonarWorktree(repository, gitProtectedRoots, environment, signal)))
|
|
260
|
+
return [];
|
|
184
261
|
const readGit = (args) => abortable(() => gitOutput(repository, args, signal, { LC_ALL: "C" }, undefined, "utf8", gitProtectedRoots, environment), signal);
|
|
185
262
|
let remoteNames;
|
|
186
263
|
try {
|
|
@@ -197,36 +274,71 @@ async function requireMatchingRepository(repository, provider, sources, protecte
|
|
|
197
274
|
(error.stderr.trimEnd() ===
|
|
198
275
|
"fatal: not a git repository (or any of the parent directories): .git" ||
|
|
199
276
|
/^fatal: not a git repository \(or any parent up to mount point [^\r\n]+\)\r?\nStopping at filesystem boundary \(GIT_DISCOVERY_ACROSS_FILESYSTEM not set\)\.$/u.test(error.stderr.trimEnd())))
|
|
200
|
-
return;
|
|
277
|
+
return [];
|
|
201
278
|
throw error;
|
|
202
279
|
}
|
|
203
280
|
const remotes = [];
|
|
204
281
|
for (const name of remoteNames.split(/\r?\n/u).filter(Boolean)) {
|
|
205
|
-
|
|
206
|
-
|
|
282
|
+
if (provider === "sonar") {
|
|
283
|
+
// Git fetches from only the first URL, after insteadOf rewrites.
|
|
284
|
+
const url = await readGit(["remote", "get-url", "--", name]);
|
|
285
|
+
if (/[\r\n]/u.test(url))
|
|
286
|
+
throw new CodexSecurityError("A configured Git remote URL contains a line break. Configure each fetch URL as a separate Git value.");
|
|
287
|
+
remotes.push({ name, url });
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
const urls = await readGit(["remote", "get-url", "--all", "--", name]);
|
|
291
|
+
for (const url of urls.split(/\r?\n/u))
|
|
292
|
+
remotes.push({ name, url });
|
|
293
|
+
}
|
|
207
294
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return
|
|
213
|
-
|
|
295
|
+
return remotes;
|
|
296
|
+
}
|
|
297
|
+
async function requireMatchingRepository(repository, provider, sources, strictSources, strictPlatformFor, protectedRoots, environment, signal, possibleSshHost, fetchRemotes) {
|
|
298
|
+
if (sources.length === 0)
|
|
299
|
+
return false;
|
|
300
|
+
const remotes = fetchRemotes ??
|
|
301
|
+
(await configuredFetchRemotes(repository, provider, protectedRoots, environment, signal));
|
|
302
|
+
const boundProvider = provider === "sonar" ||
|
|
303
|
+
provider === "continuum" ||
|
|
304
|
+
provider === "inspector" ||
|
|
305
|
+
provider === "blackduck" ||
|
|
306
|
+
provider === "veracode";
|
|
307
|
+
const loosePlatformFor = localRepositoryPlatform(provider, sources, false);
|
|
308
|
+
const comparable = [];
|
|
309
|
+
const unverified = [];
|
|
310
|
+
for (const { url: remote } of remotes) {
|
|
311
|
+
const verified = provider === "sonar" ? sonarRepositoryForRemote(remote) : remote;
|
|
312
|
+
if (verified)
|
|
313
|
+
comparable.push(verified);
|
|
314
|
+
else if (!/[\s\\\p{Cc}?#]/u.test(remote))
|
|
315
|
+
unverified.push(remote);
|
|
316
|
+
}
|
|
317
|
+
let allSourcesMatched = true;
|
|
214
318
|
for (const source of sources) {
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
319
|
+
const bound = boundProvider || strictSources.has(source.url);
|
|
320
|
+
const platform = bound
|
|
321
|
+
? (strictSources.get(source.url) ?? strictPlatformFor(source))
|
|
322
|
+
: loosePlatformFor(source);
|
|
323
|
+
const identity = (url) => remoteRepository(url, provider, bound, platform);
|
|
324
|
+
const targets = comparable.flatMap((remote) => identity(remote) ?? []);
|
|
325
|
+
const target = identity(source.url);
|
|
326
|
+
if (target && targets.some((remote) => matchingRemote(remote, target)))
|
|
327
|
+
continue;
|
|
328
|
+
allSourcesMatched = false;
|
|
329
|
+
// A custom SSH upstream can agree with a manual mapping even when a
|
|
330
|
+
// recognized HTTPS remote points at a fork. It cannot prove a Cloud binding.
|
|
331
|
+
const configured = unverified.flatMap((remote) => remoteRepository(remote, provider, bound, platform, possibleSshHost) ??
|
|
332
|
+
[]);
|
|
333
|
+
if (target && configured.some((remote) => matchingRemote(remote, target)))
|
|
225
334
|
continue;
|
|
226
|
-
|
|
227
|
-
if (key === undefined || !remoteKeys.has(key))
|
|
335
|
+
if (targets.length || configured.length)
|
|
228
336
|
throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
|
|
229
337
|
}
|
|
338
|
+
return allSourcesMatched;
|
|
339
|
+
}
|
|
340
|
+
export function sonarCheckoutMatchesSource(repository, url, protectedRoots, environment, signal) {
|
|
341
|
+
return requireMatchingRepository(repository, "sonar", [{ url }], new Map(), () => "sonar", [...protectedRoots], environment, signal);
|
|
230
342
|
}
|
|
231
343
|
async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
232
344
|
dependencies.signal?.throwIfAborted();
|
|
@@ -241,8 +353,7 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
|
241
353
|
const protectedRoot = [
|
|
242
354
|
...new Set([
|
|
243
355
|
repository,
|
|
244
|
-
...(await abortable(() =>
|
|
245
|
-
...(await abortable(() => localGitProtectionRoots(process.cwd(), environment, dependencies.signal), dependencies.signal)),
|
|
356
|
+
...(await abortable(() => importGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
|
|
246
357
|
]),
|
|
247
358
|
];
|
|
248
359
|
requireOutputOutsideRepositories(protectedRoot, await abortable(() => canonicalizeModelSafePath(environment.CODEX_SECURITY_STATE_DIR), dependencies.signal), "runtime");
|
|
@@ -261,9 +372,12 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
|
261
372
|
export async function prepareNormalizedLocalImport(input, options, dependencies = {}) {
|
|
262
373
|
dependencies.signal?.throwIfAborted();
|
|
263
374
|
requireExternalImports(dependencies.environment);
|
|
375
|
+
return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
|
|
376
|
+
}
|
|
377
|
+
/** @internal Prepare evidence using settings captured by either local import entrypoint. */
|
|
378
|
+
export async function prepareLocalImport(input, options, dependencies, readerSources = snapshotSourceRepositories(dependencies.sourceRepositories), parsedSources = [], fetchRemotes) {
|
|
264
379
|
requireIdentity(options.sourceKey, "Source key");
|
|
265
|
-
const current =
|
|
266
|
-
validateExternalReport(current.report);
|
|
380
|
+
const current = snapshotNormalizedFindings(input, checkStoredNumber);
|
|
267
381
|
let dependabotSource;
|
|
268
382
|
const identities = new Set();
|
|
269
383
|
for (const finding of current.findings) {
|
|
@@ -288,25 +402,140 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
|
|
|
288
402
|
}
|
|
289
403
|
const { repository, options: workbenchOptions } = await localContext(options.repository, dependencies);
|
|
290
404
|
const sources = new Map();
|
|
291
|
-
|
|
405
|
+
const references = [...readerSources, ...parsedSources];
|
|
406
|
+
const inspector = inspectorReportRepository(options.provider, current.findings, "local", options.inspectorProjectMap);
|
|
407
|
+
const projected = options.provider === "blackduck"
|
|
408
|
+
? []
|
|
409
|
+
: current.findings.filter((finding) => projectedBlackDuckRepositoryUrl(finding, "local"));
|
|
410
|
+
const mixed = projected.length > 0 && readerSources.length > 0;
|
|
411
|
+
const nativeSources = new Map((mixed ? current.findings : projected)
|
|
412
|
+
.filter(({ evidence }) => options.provider !== "endor" ||
|
|
413
|
+
isRecord(evidence.source_data?.["runContext"]))
|
|
414
|
+
.map((finding) => [
|
|
415
|
+
finding,
|
|
416
|
+
localFindingRepositories(options.provider, finding),
|
|
417
|
+
]));
|
|
418
|
+
const platformFor = localRepositoryPlatform(options.provider, options.inspectorProjectMap
|
|
419
|
+
? []
|
|
420
|
+
: [
|
|
421
|
+
...references,
|
|
422
|
+
...Array.from(nativeSources.values()).flat(),
|
|
423
|
+
...(inspector ? [inspector] : []),
|
|
424
|
+
], true);
|
|
425
|
+
const identify = (url) => remoteRepository(url, options.provider, true, platformFor({ url })) ?? {
|
|
426
|
+
key: url,
|
|
427
|
+
};
|
|
428
|
+
// A hint from an independent reader applies across projected rows. A native
|
|
429
|
+
// GitHub asset in one row only identifies the platform of that row's claims.
|
|
430
|
+
const operatorPlatform = localRepositoryPlatform(options.provider, readerSources, true);
|
|
431
|
+
const sameRepositories = (urls) => sameScannerRepositories(Array.from(urls, identify));
|
|
432
|
+
const bound = blackDuckReportRepositories(options.provider, current.findings, "local", sameRepositories);
|
|
433
|
+
for (const repositories of [
|
|
434
|
+
veracodeReportRepositories,
|
|
435
|
+
continuumReportRepositories,
|
|
436
|
+
]) {
|
|
437
|
+
for (const source of repositories(options.provider, current.findings, "local", sameRepositories).values()) {
|
|
438
|
+
sources.set(source.url, source);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const strictSources = new Map();
|
|
442
|
+
const known = new Set(parsedSources.map(({ url }) => url));
|
|
443
|
+
for (const finding of current.findings) {
|
|
444
|
+
const { evidence, source_finding_id: id } = finding;
|
|
292
445
|
const url = evidence.details?.repository?.url;
|
|
293
446
|
if (url)
|
|
294
447
|
sources.set(url, { url });
|
|
448
|
+
const retained = bound.get(id);
|
|
449
|
+
const native = nativeSources.get(finding) ?? [];
|
|
450
|
+
if (retained) {
|
|
451
|
+
const claims = [
|
|
452
|
+
retained.url,
|
|
453
|
+
...(url ? [url] : []),
|
|
454
|
+
...native.map((ref) => ref.url),
|
|
455
|
+
];
|
|
456
|
+
const rowPlatform = (claim) => options.provider !== "wiz"
|
|
457
|
+
? platformFor({ url: claim })
|
|
458
|
+
: native.some((source) => source.platform === "github")
|
|
459
|
+
? "github"
|
|
460
|
+
: operatorPlatform({ url: claim });
|
|
461
|
+
if (!sameScannerRepositories(claims.map((claim) => remoteRepository(claim, options.provider, true, rowPlatform(claim)) ?? {
|
|
462
|
+
key: claim,
|
|
463
|
+
})))
|
|
464
|
+
throw new CodexSecurityError("The retained scanner repository does not match the original provider finding.");
|
|
465
|
+
for (const source of [retained, ...native])
|
|
466
|
+
sources.set(source.url, source);
|
|
467
|
+
for (const claim of claims) {
|
|
468
|
+
const platform = rowPlatform(claim);
|
|
469
|
+
if (!strictSources.has(claim) || platform !== "github")
|
|
470
|
+
strictSources.set(claim, platform);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
for (const source of native)
|
|
474
|
+
known.add(source.url);
|
|
475
|
+
}
|
|
476
|
+
if (mixed) {
|
|
477
|
+
// A caller reference with no matching row spelling can still be a Git alias.
|
|
478
|
+
const rows = [...sources.keys(), ...known].map(identify);
|
|
479
|
+
const byKey = Map.groupBy(rows, (remote) => remote.key);
|
|
480
|
+
const represented = new Set(rows.map((remote) => JSON.stringify(remote)));
|
|
481
|
+
const aliases = readerSources
|
|
482
|
+
.map(({ url }) => identify(url))
|
|
483
|
+
.filter((remote) => !represented.has(JSON.stringify(remote)));
|
|
484
|
+
for (const [key, group] of Map.groupBy(aliases, (remote) => remote.key)) {
|
|
485
|
+
const candidates = byKey.get(key);
|
|
486
|
+
if (!candidates || !sameScannerRepositories([...candidates, ...group]))
|
|
487
|
+
throw new CodexSecurityError("Reader repository does not match a source in the normalized findings.");
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (strictSources.size && options.provider !== "blackduck") {
|
|
491
|
+
const keys = new Set(Array.from(strictSources.keys(), (url) => identify(url).key));
|
|
492
|
+
for (const source of references)
|
|
493
|
+
if (!strictSources.has(source.url) && keys.has(identify(source.url).key))
|
|
494
|
+
strictSources.set(source.url, platformFor(source));
|
|
295
495
|
}
|
|
296
|
-
|
|
297
|
-
|
|
496
|
+
if (inspector) {
|
|
497
|
+
const platform = inspector.platform ?? options.provider;
|
|
498
|
+
const native = remoteRepository(inspector.url, options.provider, true, platform);
|
|
499
|
+
for (const url of sources.keys()) {
|
|
500
|
+
if (!native ||
|
|
501
|
+
remoteRepository(url, options.provider, true, platform)?.key !==
|
|
502
|
+
native.key)
|
|
503
|
+
throw new CodexSecurityError(`Imported repository ${JSON.stringify(url)} does not match the retained Inspector repository ${JSON.stringify(inspector.url)}.`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
for (const source of [...(inspector ? [inspector] : []), ...references]) {
|
|
507
|
+
// A reader's platform must not loosen an operator-supplied Inspector map.
|
|
298
508
|
if (sources.get(source.url)?.platform !== "github")
|
|
299
|
-
sources.set(source.url, source);
|
|
509
|
+
sources.set(source.url, options.inspectorProjectMap ? { url: source.url } : source);
|
|
300
510
|
}
|
|
511
|
+
const sonarSources = sonarRepositoryUrls(options.provider, current.findings, current.report, "local");
|
|
512
|
+
const manualSource = options.provider === "sonar" && options.sourceRepositoryUrl
|
|
513
|
+
? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Sonar", "local")
|
|
514
|
+
: undefined;
|
|
515
|
+
if (manualSource)
|
|
516
|
+
sonarSources.add(manualSource);
|
|
517
|
+
for (const url of sonarSources)
|
|
518
|
+
if (!sources.has(url))
|
|
519
|
+
sources.set(url, { url });
|
|
520
|
+
if (sonarSources.size && !sameRepositories(sources.keys()))
|
|
521
|
+
throw new CodexSecurityError(manualSource
|
|
522
|
+
? "The Sonar evidence does not match the declared source repository."
|
|
523
|
+
: "The retained Sonar repository does not match the other source repository claims.");
|
|
524
|
+
if (options.provider === "blackduck" &&
|
|
525
|
+
current.findings.length &&
|
|
526
|
+
sources.size > 1 &&
|
|
527
|
+
!sameScannerRepositories(Array.from(sources.keys(), identify)))
|
|
528
|
+
throw new CodexSecurityError("Black Duck occurrences must belong to the same project version and source repository.");
|
|
301
529
|
if (dependabotSource)
|
|
302
530
|
sources.set(dependabotSource, {
|
|
303
531
|
url: dependabotSource,
|
|
304
532
|
platform: "github",
|
|
305
533
|
});
|
|
306
|
-
|
|
534
|
+
const selected = manualSource ? new URL(manualSource) : undefined;
|
|
535
|
+
const matchesRepositoryRemote = await requireMatchingRepository(repository, options.provider, [...sources.values()], strictSources, platformFor, workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal, selected?.protocol === "https:" ? selected.hostname : undefined, fetchRemotes);
|
|
307
536
|
dependencies.signal?.throwIfAborted();
|
|
308
537
|
const preview = {
|
|
309
|
-
...
|
|
538
|
+
...cloneImportPreview(current),
|
|
310
539
|
repository,
|
|
311
540
|
source: { provider: options.provider, source_key: options.sourceKey },
|
|
312
541
|
};
|
|
@@ -314,15 +543,13 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
|
|
|
314
543
|
repository,
|
|
315
544
|
provider: options.provider,
|
|
316
545
|
sourceKey: options.sourceKey,
|
|
317
|
-
findings: current.findings,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (typeof value === "number" && !Number.isFinite(value))
|
|
322
|
-
throw new TypeError("Stored finding JSON cannot contain non-finite numbers.");
|
|
323
|
-
return value;
|
|
546
|
+
findings: current.findings.map(({ source_finding_id, evidence }) => ({
|
|
547
|
+
source_finding_id,
|
|
548
|
+
evidence,
|
|
549
|
+
})),
|
|
324
550
|
});
|
|
325
551
|
return {
|
|
552
|
+
matchesRepositoryRemote,
|
|
326
553
|
preview,
|
|
327
554
|
async import() {
|
|
328
555
|
dependencies.signal?.throwIfAborted();
|
|
@@ -342,7 +569,7 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
|
|
|
342
569
|
read: current.read,
|
|
343
570
|
...(current.report === undefined
|
|
344
571
|
? {}
|
|
345
|
-
: { report:
|
|
572
|
+
: snapshotNormalizedFindings({ report: current.report })),
|
|
346
573
|
ready: current.findings.length,
|
|
347
574
|
excluded: structuredClone(current.excluded),
|
|
348
575
|
findings: result["findings"],
|