@openai/codex-security 0.8.2 → 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 +43 -61
- 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/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_db.py +186 -360
- 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_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 +213 -20
- 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 +64 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +14 -8
- 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 +411 -160
- package/dist/api.js.map +1 -1
- package/dist/auth.js +6 -1
- 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 +608 -258
- 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 +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/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 +7 -37
- 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 +5 -11
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +9 -0
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +325 -179
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +12 -0
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1202 -214
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +8 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +65 -54
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +2 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +111 -0
- 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 +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-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 +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +13 -18
- package/dist/inspector-findings.js.map +1 -1
- 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.map +1 -1
- package/dist/patch-tui.js +90 -35
- 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 +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +95 -52
- 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 +16 -37
- 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 +46 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +208 -42
- 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 +20 -48
- 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 +21 -20
- 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 +310 -477
- package/docs/dedupe-records.md +10 -0
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +8 -9
- 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 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -1,21 +1,29 @@
|
|
|
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 { snapshotImportOptions, } from "./external-findings.js";
|
|
8
|
-
import { cloudRepositoryUrlKey,
|
|
9
|
-
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";
|
|
10
11
|
import { inspectorReportRepository } from "./inspector-findings.js";
|
|
12
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
13
|
+
import { sonarRepositoryUrls } from "./sonar-findings.js";
|
|
11
14
|
import { isRecord } from "./record.js";
|
|
12
15
|
import { dependabotRepository } from "./github-dependabot-findings.js";
|
|
13
16
|
import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
|
|
14
|
-
import { abortable,
|
|
17
|
+
import { abortable, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, } from "./targets.js";
|
|
15
18
|
function requireIdentity(value, field) {
|
|
16
19
|
if (typeof value !== "string" || !value.trim() || value.includes("\0"))
|
|
17
20
|
throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
|
|
18
21
|
}
|
|
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
|
+
}
|
|
19
27
|
const gitTransportPorts = {
|
|
20
28
|
"http:": "80",
|
|
21
29
|
"https:": "443",
|
|
@@ -26,8 +34,19 @@ const gitTransportPorts = {
|
|
|
26
34
|
"ftp:": "21",
|
|
27
35
|
"ftps:": "990",
|
|
28
36
|
};
|
|
29
|
-
|
|
30
|
-
|
|
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) {
|
|
31
50
|
if (/^[A-Za-z]:[\\/]/u.test(value))
|
|
32
51
|
return undefined;
|
|
33
52
|
const transport = bound
|
|
@@ -51,18 +70,23 @@ function remoteRepository(value, provider, bound) {
|
|
|
51
70
|
if (!remote || !Object.hasOwn(gitTransportPorts, remote.url.protocol))
|
|
52
71
|
return undefined;
|
|
53
72
|
const { url, path, scpStyle } = remote;
|
|
54
|
-
const ssh = url.protocol
|
|
73
|
+
const ssh = isGitSsh(url.protocol);
|
|
55
74
|
const protocol = url.protocol === "http:" ? "http:" : "https:";
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
url.
|
|
59
|
-
const
|
|
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;
|
|
60
84
|
const port = githubSshOverHttps || url.port === gitTransportPorts[url.protocol]
|
|
61
85
|
? ""
|
|
62
86
|
: url.port;
|
|
63
87
|
// A GitHub source identifies a case-insensitive repository on custom Enterprise
|
|
64
88
|
// hosts too; other providers can refer to VCS hosts with case-sensitive paths.
|
|
65
|
-
const key =
|
|
89
|
+
const key = platform === "github" ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
66
90
|
const origin = `${protocol}//${hostname}${port ? `:${port}` : ""}/`;
|
|
67
91
|
if (!bound)
|
|
68
92
|
return { key: key(origin + path) };
|
|
@@ -101,145 +125,139 @@ function remoteRepository(value, provider, bound) {
|
|
|
101
125
|
.slice(0, suffix?.index)
|
|
102
126
|
.replace(/^\//u, "")
|
|
103
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)
|
|
131
|
+
: undefined;
|
|
104
132
|
const repository = suffix
|
|
105
133
|
? key(origin + name + "?") +
|
|
106
134
|
"\0" +
|
|
107
135
|
suffix[0].replace(/\/$/u, "").replace(/\.git$/u, "")
|
|
108
|
-
: key(origin + name);
|
|
136
|
+
: key(azure ?? origin + name);
|
|
109
137
|
return {
|
|
110
138
|
key: repository,
|
|
111
139
|
account: ssh && login ? literal(login) : undefined,
|
|
112
140
|
// GitHub serves the same repository path through its SCP and SSH URLs.
|
|
113
|
-
homeRelative: ssh &&
|
|
141
|
+
homeRelative: ssh && platform !== "github" && !isGitHubCloudHost(hostname.toLowerCase())
|
|
114
142
|
? homeRelative
|
|
115
143
|
: undefined,
|
|
116
144
|
};
|
|
117
145
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
((await present("commondir")) ||
|
|
128
|
-
((await present("objects")) && (await present("refs")))))
|
|
129
|
-
roots.push(directory);
|
|
130
|
-
const parent = dirname(directory);
|
|
131
|
-
if (parent === directory)
|
|
132
|
-
return roots;
|
|
133
|
-
directory = parent;
|
|
134
|
-
}
|
|
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));
|
|
135
155
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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}`;
|
|
157
178
|
}
|
|
158
|
-
else if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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}`;
|
|
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;
|
|
179
201
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
configurationDirectory !== undefined &&
|
|
183
|
-
configurationDirectory !== context.directory) {
|
|
184
|
-
// Git rereads commondir after changing to the discovered repository root.
|
|
185
|
-
roots.push(...(await associatedMetadataRoots(directory, {
|
|
186
|
-
...context,
|
|
187
|
-
directory: await abortable(() => canonicalConfigPath(configurationDirectory), signal),
|
|
188
|
-
}, signal)));
|
|
202
|
+
catch {
|
|
203
|
+
return undefined;
|
|
189
204
|
}
|
|
190
|
-
return roots;
|
|
191
205
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
environment,
|
|
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
|
+
});
|
|
212
|
+
}
|
|
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;
|
|
197
230
|
};
|
|
198
|
-
const paths = new Set([resolve(repository), context.directory]);
|
|
199
|
-
for (const path of paths) {
|
|
200
|
-
for (const root of await bareMetadataRoots(path, signal)) {
|
|
201
|
-
roots.add(root);
|
|
202
|
-
for (const associated of await associatedMetadataRoots(root, context, signal, root))
|
|
203
|
-
roots.add(associated);
|
|
204
|
-
}
|
|
205
|
-
let directory = path;
|
|
206
|
-
for (;;) {
|
|
207
|
-
signal?.throwIfAborted();
|
|
208
|
-
const marker = join(directory, ".git");
|
|
209
|
-
const metadata = await abortable(() => stat(marker).catch(nullIfMissingPath), signal);
|
|
210
|
-
if (metadata !== null) {
|
|
211
|
-
roots.add(directory);
|
|
212
|
-
const gitDirectory = metadata.isDirectory()
|
|
213
|
-
? await abortable(() => realpath(marker), signal)
|
|
214
|
-
: await metadataPointer(marker, "gitdir: ", context, signal);
|
|
215
|
-
if (gitDirectory !== undefined)
|
|
216
|
-
for (const associated of await associatedMetadataRoots(gitDirectory, context, signal, directory))
|
|
217
|
-
roots.add(associated);
|
|
218
|
-
}
|
|
219
|
-
const parent = dirname(directory);
|
|
220
|
-
if (parent === directory)
|
|
221
|
-
break;
|
|
222
|
-
directory = parent;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
for (const root of [...roots])
|
|
226
|
-
roots.add(await abortable(() => canonicalConfigPath(root), signal));
|
|
227
|
-
return [...roots];
|
|
228
231
|
}
|
|
229
|
-
|
|
230
|
-
|
|
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;
|
|
231
245
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return;
|
|
246
|
+
/** @internal Effective fetch URLs from the selected, protected checkout. */
|
|
247
|
+
export async function configuredFetchRemotes(repository, provider, protectedRoots, environment, signal) {
|
|
235
248
|
if (!(await hasGitMetadata(repository, signal)))
|
|
236
|
-
return;
|
|
249
|
+
return [];
|
|
237
250
|
const gitProtectedRoots = [
|
|
238
251
|
...(typeof protectedRoots === "string"
|
|
239
252
|
? [protectedRoots]
|
|
240
253
|
: (protectedRoots ?? [])),
|
|
241
|
-
await abortable(() => canonicalConfigPath(process.cwd()), signal),
|
|
242
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 [];
|
|
243
261
|
const readGit = (args) => abortable(() => gitOutput(repository, args, signal, { LC_ALL: "C" }, undefined, "utf8", gitProtectedRoots, environment), signal);
|
|
244
262
|
let remoteNames;
|
|
245
263
|
try {
|
|
@@ -256,42 +274,71 @@ async function requireMatchingRepository(repository, provider, sources, protecte
|
|
|
256
274
|
(error.stderr.trimEnd() ===
|
|
257
275
|
"fatal: not a git repository (or any of the parent directories): .git" ||
|
|
258
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())))
|
|
259
|
-
return;
|
|
277
|
+
return [];
|
|
260
278
|
throw error;
|
|
261
279
|
}
|
|
262
280
|
const remotes = [];
|
|
263
281
|
for (const name of remoteNames.split(/\r?\n/u).filter(Boolean)) {
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
}
|
|
266
294
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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;
|
|
274
318
|
for (const source of sources) {
|
|
275
|
-
const
|
|
276
|
-
const
|
|
277
|
-
(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const targets =
|
|
281
|
-
|
|
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)))
|
|
282
334
|
continue;
|
|
283
|
-
|
|
284
|
-
if (!target ||
|
|
285
|
-
!targets.some(({ key, account, homeRelative }) => key === target.key &&
|
|
286
|
-
(homeRelative === undefined ||
|
|
287
|
-
target.homeRelative === undefined ||
|
|
288
|
-
homeRelative === target.homeRelative) &&
|
|
289
|
-
((homeRelative === false && target.homeRelative === false) ||
|
|
290
|
-
account === undefined ||
|
|
291
|
-
target.account === undefined ||
|
|
292
|
-
account === target.account)))
|
|
335
|
+
if (targets.length || configured.length)
|
|
293
336
|
throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
|
|
294
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);
|
|
295
342
|
}
|
|
296
343
|
async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
297
344
|
dependencies.signal?.throwIfAborted();
|
|
@@ -306,8 +353,7 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
|
306
353
|
const protectedRoot = [
|
|
307
354
|
...new Set([
|
|
308
355
|
repository,
|
|
309
|
-
...(await abortable(() =>
|
|
310
|
-
...(await abortable(() => localGitProtectionRoots(process.cwd(), environment, dependencies.signal), dependencies.signal)),
|
|
356
|
+
...(await abortable(() => importGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
|
|
311
357
|
]),
|
|
312
358
|
];
|
|
313
359
|
requireOutputOutsideRepositories(protectedRoot, await abortable(() => canonicalizeModelSafePath(environment.CODEX_SECURITY_STATE_DIR), dependencies.signal), "runtime");
|
|
@@ -329,10 +375,9 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
|
|
|
329
375
|
return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
|
|
330
376
|
}
|
|
331
377
|
/** @internal Prepare evidence using settings captured by either local import entrypoint. */
|
|
332
|
-
export async function prepareLocalImport(input, options, dependencies) {
|
|
378
|
+
export async function prepareLocalImport(input, options, dependencies, readerSources = snapshotSourceRepositories(dependencies.sourceRepositories), parsedSources = [], fetchRemotes) {
|
|
333
379
|
requireIdentity(options.sourceKey, "Source key");
|
|
334
|
-
const current =
|
|
335
|
-
validateExternalReport(current.report);
|
|
380
|
+
const current = snapshotNormalizedFindings(input, checkStoredNumber);
|
|
336
381
|
let dependabotSource;
|
|
337
382
|
const identities = new Set();
|
|
338
383
|
for (const finding of current.findings) {
|
|
@@ -357,37 +402,140 @@ export async function prepareLocalImport(input, options, dependencies) {
|
|
|
357
402
|
}
|
|
358
403
|
const { repository, options: workbenchOptions } = await localContext(options.repository, dependencies);
|
|
359
404
|
const sources = new Map();
|
|
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));
|
|
360
443
|
for (const finding of current.findings) {
|
|
361
|
-
const
|
|
444
|
+
const { evidence, source_finding_id: id } = finding;
|
|
445
|
+
const url = evidence.details?.repository?.url;
|
|
362
446
|
if (url)
|
|
363
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));
|
|
364
495
|
}
|
|
365
|
-
const inspector = inspectorReportRepository(options.provider, current.findings, "local", options.inspectorProjectMap);
|
|
366
496
|
if (inspector) {
|
|
367
497
|
const platform = inspector.platform ?? options.provider;
|
|
368
|
-
const native = remoteRepository(inspector.url,
|
|
498
|
+
const native = remoteRepository(inspector.url, options.provider, true, platform);
|
|
369
499
|
for (const url of sources.keys()) {
|
|
370
|
-
if (!native ||
|
|
500
|
+
if (!native ||
|
|
501
|
+
remoteRepository(url, options.provider, true, platform)?.key !==
|
|
502
|
+
native.key)
|
|
371
503
|
throw new CodexSecurityError(`Imported repository ${JSON.stringify(url)} does not match the retained Inspector repository ${JSON.stringify(inspector.url)}.`);
|
|
372
504
|
}
|
|
373
505
|
}
|
|
374
|
-
for (const source of [
|
|
375
|
-
...(inspector ? [inspector] : []),
|
|
376
|
-
...(dependencies.sourceRepositories ?? []),
|
|
377
|
-
]) {
|
|
506
|
+
for (const source of [...(inspector ? [inspector] : []), ...references]) {
|
|
378
507
|
// A reader's platform must not loosen an operator-supplied Inspector map.
|
|
379
508
|
if (sources.get(source.url)?.platform !== "github")
|
|
380
509
|
sources.set(source.url, options.inspectorProjectMap ? { url: source.url } : source);
|
|
381
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.");
|
|
382
529
|
if (dependabotSource)
|
|
383
530
|
sources.set(dependabotSource, {
|
|
384
531
|
url: dependabotSource,
|
|
385
532
|
platform: "github",
|
|
386
533
|
});
|
|
387
|
-
|
|
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);
|
|
388
536
|
dependencies.signal?.throwIfAborted();
|
|
389
537
|
const preview = {
|
|
390
|
-
...
|
|
538
|
+
...cloneImportPreview(current),
|
|
391
539
|
repository,
|
|
392
540
|
source: { provider: options.provider, source_key: options.sourceKey },
|
|
393
541
|
};
|
|
@@ -395,15 +543,13 @@ export async function prepareLocalImport(input, options, dependencies) {
|
|
|
395
543
|
repository,
|
|
396
544
|
provider: options.provider,
|
|
397
545
|
sourceKey: options.sourceKey,
|
|
398
|
-
findings: current.findings,
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (typeof value === "number" && !Number.isFinite(value))
|
|
403
|
-
throw new TypeError("Stored finding JSON cannot contain non-finite numbers.");
|
|
404
|
-
return value;
|
|
546
|
+
findings: current.findings.map(({ source_finding_id, evidence }) => ({
|
|
547
|
+
source_finding_id,
|
|
548
|
+
evidence,
|
|
549
|
+
})),
|
|
405
550
|
});
|
|
406
551
|
return {
|
|
552
|
+
matchesRepositoryRemote,
|
|
407
553
|
preview,
|
|
408
554
|
async import() {
|
|
409
555
|
dependencies.signal?.throwIfAborted();
|
|
@@ -423,7 +569,7 @@ export async function prepareLocalImport(input, options, dependencies) {
|
|
|
423
569
|
read: current.read,
|
|
424
570
|
...(current.report === undefined
|
|
425
571
|
? {}
|
|
426
|
-
: { report:
|
|
572
|
+
: snapshotNormalizedFindings({ report: current.report })),
|
|
427
573
|
ready: current.findings.length,
|
|
428
574
|
excluded: structuredClone(current.excluded),
|
|
429
575
|
findings: result["findings"],
|