@openai/codex-security 0.8.3 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -151
- package/_bundled_plugin/.mcp.json +5 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +71 -7
- package/_bundled_plugin/scripts/workbench_cli.py +30 -12
- package/_bundled_plugin/scripts/workbench_constants.py +10 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +369 -137
- package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
- package/_bundled_plugin/scripts/workbench_progress.py +10 -1
- package/_bundled_plugin/scripts/workbench_publication.py +14 -10
- package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
- package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
- package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +13 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +127 -56
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
- package/_bundled_plugin/shared/workbench-migrations.json +34 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/dist/api.d.ts +39 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +774 -292
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -6
- package/dist/auth.js.map +1 -1
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +35 -20
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +2 -4
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +11 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1734 -1238
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +27 -2
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +100 -66
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +80 -12
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +483 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +2 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +25 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +3 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +1 -1
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +28 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +103 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +7 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +7 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +337 -89
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +8 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1318 -258
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +20 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +148 -66
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +42 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +5 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +23 -9
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +15 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +55 -30
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/hosted-scanner-v1.d.ts +6 -0
- package/dist/hosted-scanner-v1.d.ts.map +1 -0
- package/dist/hosted-scanner-v1.js +60 -0
- package/dist/hosted-scanner-v1.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +47 -65
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +68 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +1 -1
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +1 -2
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +138 -65
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +1 -0
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +17 -13
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +97 -2
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +58 -34
- package/dist/private-finding-import.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +8 -1
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/reader-selection.d.ts +2 -0
- package/dist/reader-selection.d.ts.map +1 -1
- package/dist/reader-selection.js +8 -0
- package/dist/reader-selection.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -7
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +313 -110
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +18 -15
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +60 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +6 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +75 -42
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +22 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +9 -19
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +106 -77
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +20 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +200 -8
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +107 -43
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +207 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +983 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/semgrep-platform-v1.d.ts +6 -0
- package/dist/semgrep-platform-v1.d.ts.map +1 -0
- package/dist/semgrep-platform-v1.js +83 -0
- package/dist/semgrep-platform-v1.js.map +1 -0
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +7 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +93 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +76 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +1051 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-rest-v1.d.ts +28 -0
- package/dist/snyk-rest-v1.d.ts.map +1 -0
- package/dist/snyk-rest-v1.js +132 -0
- package/dist/snyk-rest-v1.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +2 -4
- package/dist/sonar-import.js.map +1 -1
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +2 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +56 -20
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +9 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +435 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +2 -0
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +49 -11
- package/dist/veracode-findings.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +4 -0
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +57 -3
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +497 -550
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +66 -39
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +50 -42
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +18 -15
- package/schemas/external-findings.schema.json +3 -1
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
|
@@ -1,32 +1,45 @@
|
|
|
1
1
|
import { hash, randomUUID } from "node:crypto";
|
|
2
2
|
import { chmodSync } from "node:fs";
|
|
3
3
|
import { lstat, mkdir, open, readFile, readdir, rename, rm, } from "node:fs/promises";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
4
|
import { join } from "node:path";
|
|
5
|
+
import { nullIfMissingFile } from "./targets.js";
|
|
6
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
-
import { isBoxedPrimitive, isNativeError, isProxy } from "node:util/types";
|
|
8
|
-
import { privateImportClient, selectPrivateReport, readPrivateCheckpoint, unsuccessfulJob, } from "./private-finding-import.js";
|
|
7
|
+
import { isBoxedPrimitive, isNativeError, isProxy, isStringObject, } from "node:util/types";
|
|
8
|
+
import { privateImportClient, privateJobVersions, selectPrivateReport, readPrivateCheckpoint, parsePrivateCheckpoint, unsuccessfulJob, } from "./private-finding-import.js";
|
|
9
9
|
import { readCloudCredentials } from "./cloud-publish.js";
|
|
10
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
11
|
+
import { tenableReportFormat } from "./tenable-findings.js";
|
|
12
|
+
import { guardianFindingId, guardianFindingRepository, guardianSelectionFormat, } from "./semgrep-guardian-findings.js";
|
|
10
13
|
import { cloudBaseUrl, cloudFindingsUrl, DEFAULT_CLOUD_BASE_URL, } from "./cloud-endpoint.js";
|
|
11
14
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, } from "./external-findings-read.js";
|
|
15
|
+
import { codexSecurityStateDirectory, createWindowsOutputDirectory, validatePreparedOutputDir, sqliteDatabaseOpener, } from "./runtime.js";
|
|
16
|
+
import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, requireCloudReader, semgrepSarifRepositories, snykFileRepositories, } from "./external-findings-read.js";
|
|
15
17
|
import { canSnapshotWithoutGetters, canonicalJson, isRecord, } from "./record.js";
|
|
16
18
|
import { notify } from "./value.js";
|
|
17
19
|
import { wizCsvRepositoryUrl } from "./wiz-csv.js";
|
|
18
|
-
import { wizFindingRepository } from "./wiz-findings.js";
|
|
19
|
-
import {
|
|
20
|
+
import { isWizPackageFinding, wizFindingRepository } from "./wiz-findings.js";
|
|
21
|
+
import { getOpenGrepSourcePositions } from "./opengrep-findings.js";
|
|
22
|
+
import { previousReaderSelection, hasPreviousCloudProjection, } from "./reader-selection.js";
|
|
20
23
|
import { dependabotRepository } from "./github-dependabot-findings.js";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
24
|
+
import { retainedGitHubRepository } from "./github-findings.js";
|
|
25
|
+
import { normalizePreviousSemgrepFindings, normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
|
|
26
|
+
import { normalizeSnykFile, readSnykReport, snykRepositoryUrls, } from "./snyk-findings.js";
|
|
27
|
+
import { isSnykRestFinding, isSnykRestFormat, snykRestCheckpointFindingId, snykRestImportRepository, snykRestRepositoryMatches, } from "./snyk-rest-findings.js";
|
|
28
|
+
import { hasRetainedSemgrepScope, isSemgrepPlatformEvidence, isSemgrepPlatformFormat, semgrepPlatformFormat, parseSemgrepResponse, semgrepLegacyRepositoryWitnesses, semgrepNativeProjectUrl, semgrepPlatformFindingBinding, semgrepPlatformRepositoryReference, semgrepPlatformReportScope, } from "./semgrep-platform-findings.js";
|
|
29
|
+
import { semgrepV1Id } from "./semgrep-platform-v1.js";
|
|
30
|
+
import { hostedRepositoryUrlKey, normalizeHostedGitRepositoryUrl, } from "./hosted-git-repository.js";
|
|
31
|
+
import { trivyRemoteKey, trivyRepositoryUrl } from "./trivy-findings.js";
|
|
32
|
+
import { hostedRepositoryUrl } from "./hosted-scanner-http.js";
|
|
33
|
+
import { endorRepositoryUrls, requiresStructuredEndorReport, } from "./endor-findings.js";
|
|
23
34
|
import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
|
|
35
|
+
import { checkmarxSelection } from "./checkmarx-repository.js";
|
|
24
36
|
import { continuumReportRepositories } from "./continuum-findings.js";
|
|
25
37
|
import { veracodeReportRepositories } from "./veracode-findings.js";
|
|
26
38
|
import { inspectorReportRepository } from "./inspector-findings.js";
|
|
27
39
|
import { sonarRepositoryUrls } from "./sonar-findings.js";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
40
|
+
import { checkRetainedTrivyProvider, checkTrivyReportProvider, isTrivyReportHeader, retainedTrivyReport, trivyBatchSourceUrls, validateTrivyRepositoryUrl, } from "./trivy-import.js";
|
|
41
|
+
import { NoPublishableFindingsError, reportForJson, snapshotSourceRepositories, snapshotImportOptions, cloneImportPreview, nativeErrorStackGetter, snapshotNormalizedFindings, } from "./external-findings.js";
|
|
42
|
+
import { canonicalNumber, cloudRepositoryUrlKey, CloudEvidenceDepthError, validateImportRequest, validateExternalEvidence, validatePreviousCloudEvidence, validateExternalReport, validateImportReceipt, validateRepositories, validateSourceReports, validateSourceReport, } from "./external-import-contract.js";
|
|
30
43
|
const MAX_REQUEST_BYTES = 5 * 1024 * 1024;
|
|
31
44
|
/** Preserve accepted work in CLI JSON output when publication cannot finish. */
|
|
32
45
|
export class ExternalPublicationError extends CodexSecurityError {
|
|
@@ -58,8 +71,93 @@ function wireJson(value) {
|
|
|
58
71
|
function jsonDigest(value, serialize = wireJson) {
|
|
59
72
|
return hash("sha256", serialize(value));
|
|
60
73
|
}
|
|
74
|
+
function matchesRepositoryEvidence(expected, stored) {
|
|
75
|
+
const storedWire = wireJson(stored);
|
|
76
|
+
if (wireJson(expected) === storedWire)
|
|
77
|
+
return true;
|
|
78
|
+
// A repository can store a literal first-component colon with an explicit
|
|
79
|
+
// relative prefix. Match only that spelling in typed locations and their manifests.
|
|
80
|
+
const qualified = new Map();
|
|
81
|
+
const locations = expected.locations?.map((location, index) => {
|
|
82
|
+
const { path } = location;
|
|
83
|
+
const actual = stored.locations?.[index]?.path;
|
|
84
|
+
if (actual !== `./${path}` || !/^[^/:\\@]+:[^/\\]/u.test(path))
|
|
85
|
+
return location;
|
|
86
|
+
qualified.set(path, actual);
|
|
87
|
+
return { ...location, path: actual };
|
|
88
|
+
});
|
|
89
|
+
if (!qualified.size)
|
|
90
|
+
return false;
|
|
91
|
+
const packages = expected.packages?.map((item) => {
|
|
92
|
+
const path = item.manifest_path && qualified.get(item.manifest_path);
|
|
93
|
+
return path ? { ...item, manifest_path: path } : item;
|
|
94
|
+
});
|
|
95
|
+
return wireJson({ ...expected, locations, packages }) === storedWire;
|
|
96
|
+
}
|
|
97
|
+
function isCompleteUnscoredOpenGrepReport(report) {
|
|
98
|
+
let rows = report.excluded.length;
|
|
99
|
+
for (const { evidence } of report.findings) {
|
|
100
|
+
const traces = evidence.source_data?.["results"];
|
|
101
|
+
if (evidence.details?.scanner_origin !== "OpenGrep" ||
|
|
102
|
+
evidence.severity !== "unknown" ||
|
|
103
|
+
!Array.isArray(traces))
|
|
104
|
+
return false;
|
|
105
|
+
rows += traces.length;
|
|
106
|
+
}
|
|
107
|
+
return rows === report.read;
|
|
108
|
+
}
|
|
109
|
+
function repositoryFindings(report, severities) {
|
|
110
|
+
return severities
|
|
111
|
+
? report.findings.filter(({ evidence }) => severities.includes(evidence.severity))
|
|
112
|
+
: report.findings;
|
|
113
|
+
}
|
|
114
|
+
function repositorySelection(report, severities, sourcePositions) {
|
|
115
|
+
const findings = repositoryFindings(report, severities);
|
|
116
|
+
if (findings.length === report.findings.length)
|
|
117
|
+
return report;
|
|
118
|
+
const excluded = [...report.excluded];
|
|
119
|
+
const skipped = new Set(excluded.map(({ position }) => position));
|
|
120
|
+
function exclude(position, id, severity) {
|
|
121
|
+
excluded.push({
|
|
122
|
+
position,
|
|
123
|
+
source_finding_id: id,
|
|
124
|
+
reason: `The repository publisher does not accept severity ${JSON.stringify(severity)}. A local import or an available private inbox can retain this finding.`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Serialized OpenGrep selections retain every trace but lose the reader's
|
|
128
|
+
// position map. All these traces have unknown severity, so the remaining
|
|
129
|
+
// source rows are provably excluded even when their individual IDs are lost.
|
|
130
|
+
if (!sourcePositions && isCompleteUnscoredOpenGrepReport(report)) {
|
|
131
|
+
const id = report.findings.length === 1
|
|
132
|
+
? report.findings[0].source_finding_id
|
|
133
|
+
: null;
|
|
134
|
+
for (let row = 1; row <= report.read; row++)
|
|
135
|
+
if (!skipped.has(row))
|
|
136
|
+
exclude(row, id, "unknown");
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const retained = new Set(findings);
|
|
140
|
+
let position = 0;
|
|
141
|
+
for (const finding of report.findings) {
|
|
142
|
+
do {
|
|
143
|
+
position++;
|
|
144
|
+
} while (skipped.has(position));
|
|
145
|
+
if (retained.has(finding))
|
|
146
|
+
continue;
|
|
147
|
+
const { source_finding_id, evidence } = finding;
|
|
148
|
+
for (const row of sourcePositions?.get(source_finding_id) ?? [position])
|
|
149
|
+
exclude(row, source_finding_id, evidence.severity);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...report,
|
|
154
|
+
findings,
|
|
155
|
+
excluded: excluded.sort((a, b) => a.position - b.position),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
61
158
|
function sameSubmission(left, right) {
|
|
62
159
|
return (left.accountId === right.accountId &&
|
|
160
|
+
left.trivyRepositoryUrl === right.trivyRepositoryUrl &&
|
|
63
161
|
left.inspectorProjectMapRequired === right.inspectorProjectMapRequired &&
|
|
64
162
|
wireJson(left.requests) === wireJson(right.requests));
|
|
65
163
|
}
|
|
@@ -100,18 +198,7 @@ function sameFindingSelection(left, right) {
|
|
|
100
198
|
left.every((finding, index) => finding.source_finding_id === right[index].source_finding_id));
|
|
101
199
|
}
|
|
102
200
|
async function readOptionalFile(path) {
|
|
103
|
-
return readFile(path, "utf8").catch(
|
|
104
|
-
if (error.code === "ENOENT")
|
|
105
|
-
return undefined;
|
|
106
|
-
throw error;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function reportForJson(report) {
|
|
110
|
-
const errors = report?.["errors"];
|
|
111
|
-
if (!Array.isArray(errors))
|
|
112
|
-
return report;
|
|
113
|
-
const json = JSON.stringify(errors, (_key, entry) => entry instanceof Error ? { ...entry, message: entry.message } : entry);
|
|
114
|
-
return { ...report, errors: JSON.parse(json) };
|
|
201
|
+
return (await readFile(path, "utf8").catch(nullIfMissingFile)) ?? undefined;
|
|
115
202
|
}
|
|
116
203
|
export function externalPublicationStateDirectory(environment) {
|
|
117
204
|
return join(codexSecurityStateDirectory(environment), "external-finding-publications");
|
|
@@ -145,15 +232,13 @@ class CloudImportError extends CodexSecurityError {
|
|
|
145
232
|
}
|
|
146
233
|
function validatePublicationReceipt(value, batch) {
|
|
147
234
|
const receipt = validateImportReceipt(value);
|
|
148
|
-
const
|
|
235
|
+
const remaining = new Set(batch.items.map((item) => item.client_id));
|
|
149
236
|
if (receipt.id !== batch.request_id ||
|
|
150
237
|
wireJson(receipt.repository) !== wireJson(batch.repository) ||
|
|
151
238
|
wireJson(receipt.source) !== wireJson(batch.source) ||
|
|
152
239
|
receipt.item_count !== batch.items.length ||
|
|
153
240
|
receipt.results.length !== batch.items.length ||
|
|
154
|
-
|
|
155
|
-
batch.items.length ||
|
|
156
|
-
receipt.results.some((item) => !batchItems.has(item.client_id)))
|
|
241
|
+
receipt.results.some((item) => !remaining.delete(item.client_id)))
|
|
157
242
|
throw new CodexSecurityError("Cloud returned a receipt for a different publication.");
|
|
158
243
|
const actual = { created: 0, updated: 0, unchanged: 0, error: 0 };
|
|
159
244
|
for (const result of receipt.results) {
|
|
@@ -183,22 +268,15 @@ async function withImportLocks(state, keys, signal, operation) {
|
|
|
183
268
|
else
|
|
184
269
|
await mkdir(state, { recursive: true, mode: 0o700 });
|
|
185
270
|
await validatePreparedOutputDir(state, undefined, true);
|
|
186
|
-
const
|
|
187
|
-
const Database = (process.versions["bun"]
|
|
188
|
-
? require("bun:sqlite").Database
|
|
189
|
-
: require("node:sqlite").DatabaseSync);
|
|
271
|
+
const openDatabase = sqliteDatabaseOpener();
|
|
190
272
|
const guards = [];
|
|
191
273
|
try {
|
|
192
274
|
for (const key of [...new Set(keys)].sort()) {
|
|
193
275
|
const path = join(state, `${key}.lock.sqlite`);
|
|
194
|
-
const metadata = await lstat(path).catch(
|
|
195
|
-
if (error.code === "ENOENT")
|
|
196
|
-
return undefined;
|
|
197
|
-
throw error;
|
|
198
|
-
});
|
|
276
|
+
const metadata = await lstat(path).catch(nullIfMissingFile);
|
|
199
277
|
if (metadata && !metadata.isFile())
|
|
200
278
|
throw new CodexSecurityError("The publication lock is not a regular file.");
|
|
201
|
-
const guard =
|
|
279
|
+
const guard = openDatabase(path);
|
|
202
280
|
guards.push(guard);
|
|
203
281
|
if (process.platform !== "win32")
|
|
204
282
|
chmodSync(path, 0o600);
|
|
@@ -232,17 +310,271 @@ async function withImportLocks(state, keys, signal, operation) {
|
|
|
232
310
|
guard.close();
|
|
233
311
|
}
|
|
234
312
|
}
|
|
313
|
+
function hostedSourceReferences(readerSources, url, sourcePlatform) {
|
|
314
|
+
// The catalog supplies a GitHub identity only when the reader has no SCM mapping.
|
|
315
|
+
const sources = readerSources.length || !url
|
|
316
|
+
? readerSources
|
|
317
|
+
: [{ url, platform: "github" }];
|
|
318
|
+
return sourcePlatform === "other"
|
|
319
|
+
? sources.filter(({ platform }) => platform !== "github")
|
|
320
|
+
: sources;
|
|
321
|
+
}
|
|
322
|
+
function storedFindingId(finding) {
|
|
323
|
+
const seen = new Set();
|
|
324
|
+
for (let owner = finding; owner && !seen.has(owner); owner = Object.getPrototypeOf(owner)) {
|
|
325
|
+
const property = Object.getOwnPropertyDescriptor(owner, "source_finding_id");
|
|
326
|
+
if (property) {
|
|
327
|
+
const id = property.value;
|
|
328
|
+
return typeof id === "string" || isStringObject(id)
|
|
329
|
+
? String.prototype.valueOf.call(id)
|
|
330
|
+
: "";
|
|
331
|
+
}
|
|
332
|
+
seen.add(owner);
|
|
333
|
+
}
|
|
334
|
+
return "";
|
|
335
|
+
}
|
|
336
|
+
function checkFindingProvider(input, provider) {
|
|
337
|
+
function checkFormat(format) {
|
|
338
|
+
if (format === tenableReportFormat)
|
|
339
|
+
requireCloudReader({ provider: "tenable" });
|
|
340
|
+
if (format === guardianSelectionFormat && provider !== "semgrep")
|
|
341
|
+
throw new CodexSecurityError("Use the semgrep provider for Guardian findings.");
|
|
342
|
+
}
|
|
343
|
+
checkFormat(ownData(ownData(input, "report"), "format"));
|
|
344
|
+
if (!Array.isArray(input?.findings))
|
|
345
|
+
return;
|
|
346
|
+
for (const row of input.findings) {
|
|
347
|
+
if (!row)
|
|
348
|
+
continue;
|
|
349
|
+
if (guardianFindingId.test(storedFindingId(row)))
|
|
350
|
+
checkFormat(guardianSelectionFormat);
|
|
351
|
+
checkFormat(ownData(ownData(row.evidence, "source_data"), "format"));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
235
354
|
export async function prepareExternalPublication(path, options, dependencies = {}) {
|
|
236
|
-
requireExternalImports(dependencies.environment);
|
|
237
355
|
const settings = snapshotImportOptions(options);
|
|
238
|
-
|
|
239
|
-
|
|
356
|
+
requireCloudReader(settings);
|
|
357
|
+
const readerSources = snapshotSourceRepositories(dependencies.sourceRepositories);
|
|
358
|
+
const provider = EXTERNAL_FINDINGS_PROVIDERS[settings.provider];
|
|
359
|
+
let input;
|
|
360
|
+
let fileRepositories;
|
|
361
|
+
if (settings.provider === "semgrep" || settings.provider === "snyk") {
|
|
362
|
+
const semgrep = settings.provider === "semgrep";
|
|
363
|
+
const report = await (semgrep
|
|
364
|
+
? readSemgrepReport(path)
|
|
365
|
+
: readSnykReport(path));
|
|
366
|
+
const normalize = async (url, platform) => {
|
|
367
|
+
const references = hostedSourceReferences(readerSources, url, semgrep ? platform : undefined);
|
|
368
|
+
const semgrepOptions = {
|
|
369
|
+
sourceRepositoryUrl: settings.sourceRepositoryUrl,
|
|
370
|
+
sourceRepositories: references,
|
|
371
|
+
};
|
|
372
|
+
const findings = semgrep
|
|
373
|
+
? normalizeSemgrepFindings(report, semgrepOptions, "cloud")
|
|
374
|
+
: await normalizeSnykFile(report, "cloud", references);
|
|
375
|
+
const selection = normalizedPublicationInput(findings, provider);
|
|
376
|
+
if (semgrep && hasPreviousCloudProjection(findings))
|
|
377
|
+
selection.readPreviousFindings = () => normalizePreviousSemgrepFindings(report, semgrepOptions);
|
|
378
|
+
return selection;
|
|
379
|
+
};
|
|
380
|
+
const hosted = isRecord(report) &&
|
|
381
|
+
(semgrep
|
|
382
|
+
? isSemgrepPlatformFormat(report["format"]) ||
|
|
383
|
+
report["format"] === guardianSelectionFormat
|
|
384
|
+
: isSnykRestFormat(report["format"]));
|
|
385
|
+
if (!semgrep && !hosted)
|
|
386
|
+
fileRepositories = () => snykFileRepositories(report);
|
|
387
|
+
input = hosted
|
|
388
|
+
? async (destination) => {
|
|
389
|
+
try {
|
|
390
|
+
const projection = await normalize(destination.url);
|
|
391
|
+
if (!semgrep)
|
|
392
|
+
return projection;
|
|
393
|
+
return {
|
|
394
|
+
...projection,
|
|
395
|
+
recheckFileRepository: async (approvedUrl, platform) => {
|
|
396
|
+
if (platform === "other")
|
|
397
|
+
await normalize(approvedUrl, platform);
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
catch (error) {
|
|
402
|
+
const project = report["project"];
|
|
403
|
+
const candidate = report["sourceRepositoryUrl"] ??
|
|
404
|
+
settings.sourceRepositoryUrl ??
|
|
405
|
+
(semgrep && isRecord(project) ? project["url"] : undefined);
|
|
406
|
+
if (typeof candidate !== "string" || candidate === destination.url)
|
|
407
|
+
throw error;
|
|
408
|
+
// A renamed repository can require its old spelling to identify the saved request.
|
|
409
|
+
// Only an approved checkpoint can later authorize that spelling.
|
|
410
|
+
const projection = await normalize(normalizeHostedGitRepositoryUrl(candidate, destination.url, true));
|
|
411
|
+
return {
|
|
412
|
+
...projection,
|
|
413
|
+
recheckFileRepository: (approvedUrl, platform) => {
|
|
414
|
+
if (approvedUrl === destination.url)
|
|
415
|
+
throw error;
|
|
416
|
+
return normalize(approvedUrl, platform);
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
: await normalize();
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
const parsed = await readExternalFindings(path, settings);
|
|
425
|
+
checkFindingProvider(parsed.findings, provider);
|
|
426
|
+
input =
|
|
427
|
+
parsed.publication ??
|
|
428
|
+
normalizedPublicationInput(parsed.findings, provider);
|
|
429
|
+
input.readPreviousFindings = parsed.previousFindings;
|
|
430
|
+
if (provider === "endor") {
|
|
431
|
+
fileRepositories = () => parsed.sourceRepositories ?? [];
|
|
432
|
+
input.requiresStructuredReport = requiresStructuredEndorReport(parsed.findings);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return preparePublicationInput(input, { ...settings, provider }, dependencies, readerSources, settings.sourceRepositoryUrl, path, fileRepositories);
|
|
240
436
|
}
|
|
241
437
|
/** Prepare normalized provider evidence without reading a vendor export. */
|
|
242
438
|
export async function prepareNormalizedExternalPublication(input, options, dependencies = {}) {
|
|
243
|
-
requireExternalImports(dependencies.environment);
|
|
244
439
|
const settings = snapshotImportOptions(options);
|
|
245
|
-
|
|
440
|
+
requireCloudReader(settings);
|
|
441
|
+
return preparePublicationInput(normalizedPublicationInput(input, settings.provider), settings, dependencies, snapshotSourceRepositories(dependencies.sourceRepositories));
|
|
442
|
+
}
|
|
443
|
+
function cloudSourceKey(url, platform) {
|
|
444
|
+
return hostedRepositoryUrlKey(url, platform === "github", platform === "gitlab", "cloud");
|
|
445
|
+
}
|
|
446
|
+
/** Verify every source in a hosted selection, including SDK inputs containing typed-only rows. */
|
|
447
|
+
function hostedRepositoryMatcher(input, provider, declaredUrl, destination, readerSources, allowOpaqueLegacyRows = false) {
|
|
448
|
+
const references = hostedSourceReferences(readerSources, destination.url, input.sourceRepositoryPlatform);
|
|
449
|
+
if (provider === "snyk") {
|
|
450
|
+
const declaredSource = input.sourceRepositoryUrl !== undefined ||
|
|
451
|
+
input.sourceRepositoryPlatform !== undefined ||
|
|
452
|
+
declaredUrl !== undefined ||
|
|
453
|
+
readerSources.length > 0;
|
|
454
|
+
const binding = snykRestImportRepository(input, provider, [
|
|
455
|
+
...readerSources.map(({ url }) => url),
|
|
456
|
+
...(declaredUrl === undefined ? [] : [declaredUrl]),
|
|
457
|
+
], references, undefined, allowOpaqueLegacyRows, declaredSource ? destination.url : undefined);
|
|
458
|
+
if (binding)
|
|
459
|
+
return {
|
|
460
|
+
github: binding.platform === "github",
|
|
461
|
+
matches: (url) => snykRestRepositoryMatches(binding, url),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (provider !== "semgrep")
|
|
465
|
+
return;
|
|
466
|
+
const declared = input.sourceRepositoryUrl === undefined
|
|
467
|
+
? undefined
|
|
468
|
+
: hostedRepositoryUrl(input.sourceRepositoryUrl, "Semgrep source repository");
|
|
469
|
+
const reportScope = semgrepPlatformReportScope(input, provider, references);
|
|
470
|
+
const hasNativeSource = reportScope !== undefined ||
|
|
471
|
+
input.findings.some((finding) => isSemgrepPlatformEvidence(finding, provider));
|
|
472
|
+
const claims = new Set();
|
|
473
|
+
let original = input.report?.["format"] === guardianSelectionFormat
|
|
474
|
+
? declaredScannerRepositoryUrl(input.report["repositoryUrl"], "Guardian")
|
|
475
|
+
: undefined;
|
|
476
|
+
const nativeRows = [];
|
|
477
|
+
for (const finding of input.findings) {
|
|
478
|
+
const typed = finding.evidence.details?.repository?.url;
|
|
479
|
+
if (typed)
|
|
480
|
+
claims.add(typed);
|
|
481
|
+
const guardian = guardianFindingRepository(finding, "cloud");
|
|
482
|
+
if (guardian) {
|
|
483
|
+
original ??= guardian;
|
|
484
|
+
claims.add(guardian);
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
const data = finding.evidence.source_data;
|
|
488
|
+
const sarif = semgrepSarifRepositories(finding, hasNativeSource);
|
|
489
|
+
for (const { url } of sarif)
|
|
490
|
+
claims.add(hostedRepositoryUrl(url, "Semgrep source repository"));
|
|
491
|
+
const project = data?.["project"];
|
|
492
|
+
if (!allowOpaqueLegacyRows ||
|
|
493
|
+
!isSemgrepPlatformEvidence(finding, provider) ||
|
|
494
|
+
(isRecord(project) &&
|
|
495
|
+
project["id"] != null &&
|
|
496
|
+
project["name"] != null &&
|
|
497
|
+
data?.["deployment"] != null &&
|
|
498
|
+
data["ref"] != null &&
|
|
499
|
+
data["product"] != null &&
|
|
500
|
+
((isRecord(data["finding"]) && data["finding"]["id"] != null) ||
|
|
501
|
+
typeof data["semgrepPlatformFindingJson"] === "string"))) {
|
|
502
|
+
nativeRows.push({ finding, sarif });
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
// Released SDKs could save partial native records. Retain any source still
|
|
506
|
+
// identifiable on that row while validating complete siblings under the new mapping.
|
|
507
|
+
if (!data)
|
|
508
|
+
continue;
|
|
509
|
+
if (reportScope?.projectId !== undefined) {
|
|
510
|
+
const id = isRecord(project) ? project["id"] : undefined;
|
|
511
|
+
if ((id != null &&
|
|
512
|
+
id !== reportScope.projectId &&
|
|
513
|
+
semgrepV1Id(id) !== reportScope.projectId) ||
|
|
514
|
+
["deployment", "ref", "product"].some((field) => data[field] != null && data[field] !== reportScope[field]))
|
|
515
|
+
throw new CodexSecurityError("The retained Semgrep finding does not match the supplied report scope.");
|
|
516
|
+
}
|
|
517
|
+
const rows = [data["finding"]];
|
|
518
|
+
const raw = data["semgrepPlatformFindingJson"];
|
|
519
|
+
if (typeof raw === "string") {
|
|
520
|
+
try {
|
|
521
|
+
rows.push(parseSemgrepResponse(raw));
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
// An unreadable historical row contributes no URL. Check the remaining claims.
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const nativeUrls = [isRecord(project) ? project["url"] : undefined];
|
|
528
|
+
if (data["format"] === semgrepPlatformFormat)
|
|
529
|
+
nativeUrls.push(data["nativeProjectUrl"]);
|
|
530
|
+
for (const row of rows) {
|
|
531
|
+
if (!isRecord(row))
|
|
532
|
+
continue;
|
|
533
|
+
if (reportScope?.ref !== undefined &&
|
|
534
|
+
row["ref"] !== undefined &&
|
|
535
|
+
row["ref"] !== reportScope.ref)
|
|
536
|
+
throw new CodexSecurityError("The retained Semgrep finding does not match the supplied report scope.");
|
|
537
|
+
const repository = row["repository"];
|
|
538
|
+
if (isRecord(repository))
|
|
539
|
+
nativeUrls.push(repository["url"]);
|
|
540
|
+
}
|
|
541
|
+
const urls = nativeUrls.map((url) => semgrepNativeProjectUrl(url, references));
|
|
542
|
+
for (const url of [...urls, data["sourceRepositoryUrl"]]) {
|
|
543
|
+
if (typeof url !== "string")
|
|
544
|
+
continue;
|
|
545
|
+
original ??= url;
|
|
546
|
+
claims.add(url);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const witnesses = semgrepLegacyRepositoryWitnesses(nativeRows.map(({ finding }) => finding), provider, references, "cloud");
|
|
550
|
+
for (const { finding, sarif } of nativeRows) {
|
|
551
|
+
const native = semgrepPlatformFindingBinding(finding, provider, references, witnesses, reportScope, [{ url: projectedBlackDuckRepositoryUrl(finding, "cloud") }, ...sarif], "cloud", allowOpaqueLegacyRows)?.url;
|
|
552
|
+
if (native) {
|
|
553
|
+
original ??= native;
|
|
554
|
+
claims.add(native);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const source = original ??
|
|
558
|
+
declared ??
|
|
559
|
+
declaredUrl ??
|
|
560
|
+
(readerSources.length || input.sourceRepositoryPlatform !== undefined
|
|
561
|
+
? destination.url
|
|
562
|
+
: undefined);
|
|
563
|
+
if (source === undefined)
|
|
564
|
+
return;
|
|
565
|
+
const { platform } = semgrepPlatformRepositoryReference(source, references);
|
|
566
|
+
const expected = cloudSourceKey(source, platform);
|
|
567
|
+
const matches = (url) => cloudSourceKey(url, platform) === expected;
|
|
568
|
+
if (declared !== undefined)
|
|
569
|
+
claims.add(declared);
|
|
570
|
+
if (declaredUrl !== undefined)
|
|
571
|
+
claims.add(declaredUrl);
|
|
572
|
+
for (const reader of readerSources)
|
|
573
|
+
claims.add(normalizeHostedGitRepositoryUrl(reader.url, source, reader.platform !== undefined));
|
|
574
|
+
for (const url of claims)
|
|
575
|
+
if (!matches(hostedRepositoryUrl(url, "Semgrep source repository")))
|
|
576
|
+
throw new CodexSecurityError("The finding does not match the original Semgrep project repository.");
|
|
577
|
+
return { github: platform === "github", matches };
|
|
246
578
|
}
|
|
247
579
|
function ownData(value, key) {
|
|
248
580
|
return isRecord(value) && !isProxy(value)
|
|
@@ -336,10 +668,13 @@ function previousNormalizedFindings(input, nativeDiagnostics, observe) {
|
|
|
336
668
|
snapshot.report = structuredClone(report);
|
|
337
669
|
return snapshot;
|
|
338
670
|
}
|
|
339
|
-
function publicationIdentity(parsed) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
671
|
+
function publicationIdentity(parsed, provider) {
|
|
672
|
+
// For Trivy, the independently checked header binds the repository. Files
|
|
673
|
+
// and normalized rows use the same checkpoint when their findings agree.
|
|
674
|
+
if (parsed.report === undefined ||
|
|
675
|
+
(provider === "trivy" && isTrivyReportHeader(parsed.report)))
|
|
676
|
+
return parsed.findings;
|
|
677
|
+
return { findings: parsed.findings, report: reportForJson(parsed.report) };
|
|
343
678
|
}
|
|
344
679
|
function validatePublicationFindings(parsed, validateEvidence) {
|
|
345
680
|
validateExternalReport(parsed.report);
|
|
@@ -379,7 +714,7 @@ function historicalPublication(native) {
|
|
|
379
714
|
return;
|
|
380
715
|
}
|
|
381
716
|
}
|
|
382
|
-
function normalizedPublicationInput(input) {
|
|
717
|
+
function normalizedPublicationInput(input, provider) {
|
|
383
718
|
const nativeDiagnostics = new Map();
|
|
384
719
|
let native;
|
|
385
720
|
let plainJson = true;
|
|
@@ -411,6 +746,34 @@ function normalizedPublicationInput(input) {
|
|
|
411
746
|
freshError = error;
|
|
412
747
|
current = { read: native.read, findings: [], excluded: [] };
|
|
413
748
|
}
|
|
749
|
+
// Repository and format declarations can be non-enumerable SDK getters.
|
|
750
|
+
for (const key of [
|
|
751
|
+
"sourceFormat",
|
|
752
|
+
"semgrepPlatformScope",
|
|
753
|
+
"snykRestContext",
|
|
754
|
+
...(provider === "semgrep" || provider === "snyk"
|
|
755
|
+
? ["sourceRepositoryUrl", "sourceRepositoryPlatform"]
|
|
756
|
+
: []),
|
|
757
|
+
]) {
|
|
758
|
+
if (!(key in current) &&
|
|
759
|
+
!Object.prototype.propertyIsEnumerable.call(input, key) &&
|
|
760
|
+
key in input)
|
|
761
|
+
Object.assign(current, {
|
|
762
|
+
[key]: structuredClone(Reflect.get(input, key)),
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
const parsed = current;
|
|
766
|
+
if (parsed.snykRestContext !== undefined) {
|
|
767
|
+
if (provider !== "snyk")
|
|
768
|
+
throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
|
|
769
|
+
if (!isSnykRestFormat(parsed.snykRestContext?.["format"]))
|
|
770
|
+
throw new CodexSecurityError("Expected a versioned Snyk REST report context.");
|
|
771
|
+
}
|
|
772
|
+
const markedSemgrep = "sourceFormat" in parsed && isSemgrepPlatformFormat(parsed.sourceFormat);
|
|
773
|
+
if (markedSemgrep && provider !== "semgrep")
|
|
774
|
+
throw new CodexSecurityError("Semgrep Platform evidence requires the semgrep provider.");
|
|
775
|
+
if (markedSemgrep || "semgrepPlatformScope" in parsed)
|
|
776
|
+
semgrepPlatformReportScope(parsed, provider);
|
|
414
777
|
if (native && nativeDiagnostics.size) {
|
|
415
778
|
const historical = native.report["errors"];
|
|
416
779
|
const exported = current.report?.["errors"];
|
|
@@ -455,6 +818,8 @@ function normalizedPublicationInput(input) {
|
|
|
455
818
|
if (reader)
|
|
456
819
|
native = reader.snapshot;
|
|
457
820
|
const original = historicalPublication(native);
|
|
821
|
+
if (original)
|
|
822
|
+
checkFindingProvider(original.parsed, provider);
|
|
458
823
|
try {
|
|
459
824
|
validatePublicationFindings(current, validateExternalEvidence);
|
|
460
825
|
}
|
|
@@ -469,12 +834,14 @@ function normalizedPublicationInput(input) {
|
|
|
469
834
|
// Only the old selection can be reviewed when fresh validation failed.
|
|
470
835
|
current = { read: original.parsed.read, findings: [], excluded: [] };
|
|
471
836
|
}
|
|
472
|
-
|
|
837
|
+
checkFindingProvider(current, provider);
|
|
838
|
+
const identity = publicationIdentity(current, provider);
|
|
473
839
|
return {
|
|
474
840
|
current,
|
|
475
841
|
legacy: current,
|
|
476
842
|
currentIdentity: identity,
|
|
477
843
|
legacyIdentity: identity,
|
|
844
|
+
sourcePositions: getOpenGrepSourcePositions(ownData(input, "findings")),
|
|
478
845
|
original,
|
|
479
846
|
freshError,
|
|
480
847
|
unprovenIdPrefixes: reader?.unprovenIdPrefixes,
|
|
@@ -516,7 +883,96 @@ function verifiableLegacyMetadata({ report, findings }, wireIdentity) {
|
|
|
516
883
|
});
|
|
517
884
|
return verifiable;
|
|
518
885
|
}
|
|
519
|
-
|
|
886
|
+
// Prefer the current native evidence for new publications. The original SDK input
|
|
887
|
+
// remains a candidate so an approved request can resume under its exact digest.
|
|
888
|
+
function* hostedPublicationProjections(input, provider, destination, readerSources) {
|
|
889
|
+
const current = input.current;
|
|
890
|
+
if (provider === "snyk") {
|
|
891
|
+
const first = current.findings.find(isSnykRestFinding);
|
|
892
|
+
if (!first && current.snykRestContext === undefined)
|
|
893
|
+
return;
|
|
894
|
+
// A previous publisher may have approved the exact raw selection.
|
|
895
|
+
yield input;
|
|
896
|
+
const originalUrl = current.snykRestContext?.["sourceRepositoryUrl"] ??
|
|
897
|
+
current.sourceRepositoryUrl ??
|
|
898
|
+
first?.evidence.source_data?.["sourceRepositoryUrl"];
|
|
899
|
+
// The original spelling reconstructs a lookup key after a catalog rename.
|
|
900
|
+
// Admission validates the input against the saved approval or live destination.
|
|
901
|
+
const retained = structuredClone(current);
|
|
902
|
+
try {
|
|
903
|
+
snykRestImportRepository(retained, provider, [], hostedSourceReferences(readerSources, typeof originalUrl === "string" ? originalUrl : destination.url, current.sourceRepositoryPlatform), (finding, source) => {
|
|
904
|
+
finding.evidence.source_data = source;
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
catch (error) {
|
|
908
|
+
// A headerless input can still identify an already-approved opaque request.
|
|
909
|
+
if (current.snykRestContext !== undefined)
|
|
910
|
+
throw error;
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
yield {
|
|
914
|
+
...input,
|
|
915
|
+
current: retained,
|
|
916
|
+
// The raw input above owns its historical native checkpoint.
|
|
917
|
+
original: undefined,
|
|
918
|
+
currentIdentity: publicationIdentity(retained),
|
|
919
|
+
};
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const originalRow = (finding) => isRecord(finding.evidence.source_data?.["finding"]) &&
|
|
923
|
+
isSemgrepPlatformEvidence(finding, "semgrep");
|
|
924
|
+
const currentBulkRow = (finding) => finding.evidence.source_data?.["format"] === semgrepPlatformFormat;
|
|
925
|
+
const first = current.findings.find(originalRow) ?? current.findings.find(currentBulkRow);
|
|
926
|
+
if (!first)
|
|
927
|
+
return;
|
|
928
|
+
const reportScope = semgrepPlatformReportScope(current, "semgrep");
|
|
929
|
+
const retained = first.evidence.source_data;
|
|
930
|
+
const project = retained?.["project"];
|
|
931
|
+
const retainedUrl = current.sourceRepositoryUrl ??
|
|
932
|
+
retained?.["sourceRepositoryUrl"] ??
|
|
933
|
+
(isRecord(project) ? project["url"] : undefined);
|
|
934
|
+
// A renamed repository may need the original spelling to identify its checkpoint.
|
|
935
|
+
// Preparation validates the unmodified report against the authenticated approval.
|
|
936
|
+
for (const url of new Set([destination.url, retainedUrl])) {
|
|
937
|
+
if (typeof url !== "string")
|
|
938
|
+
continue;
|
|
939
|
+
const references = hostedSourceReferences(readerSources, url, current.sourceRepositoryPlatform);
|
|
940
|
+
try {
|
|
941
|
+
const witnesses = semgrepLegacyRepositoryWitnesses(current.findings, "semgrep", references, "cloud");
|
|
942
|
+
const findings = current.findings.map((finding) => {
|
|
943
|
+
const original = originalRow(finding);
|
|
944
|
+
if (!original && !currentBulkRow(finding))
|
|
945
|
+
return finding;
|
|
946
|
+
const binding = semgrepPlatformFindingBinding(finding, "semgrep", references, witnesses, reportScope, undefined, "cloud");
|
|
947
|
+
// The authenticated repository can make an offline backlog row selectable.
|
|
948
|
+
return binding?.sourceData &&
|
|
949
|
+
(original || binding.sourceData["format"] !== semgrepPlatformFormat)
|
|
950
|
+
? {
|
|
951
|
+
...finding,
|
|
952
|
+
evidence: {
|
|
953
|
+
...finding.evidence,
|
|
954
|
+
...binding.migration,
|
|
955
|
+
source_data: binding.sourceData,
|
|
956
|
+
},
|
|
957
|
+
}
|
|
958
|
+
: finding;
|
|
959
|
+
});
|
|
960
|
+
const upgraded = { ...current, findings };
|
|
961
|
+
yield {
|
|
962
|
+
...input,
|
|
963
|
+
current: upgraded,
|
|
964
|
+
original: undefined,
|
|
965
|
+
currentIdentity: publicationIdentity(upgraded),
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
catch {
|
|
969
|
+
// The released SDK also accepted partial original records; keep the raw
|
|
970
|
+
// identity as a fallback so its exact saved request remains recoverable.
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
yield input;
|
|
974
|
+
}
|
|
975
|
+
async function preparePublicationInput(supplied, options, dependencies, readerSources, declaredUrl, nativePath, fileRepositories) {
|
|
520
976
|
const { inspectorProjectMap } = options;
|
|
521
977
|
const progress = (event) => notify(() => dependencies.onProgress?.(event));
|
|
522
978
|
if (!options.sourceKey.trim() ||
|
|
@@ -524,39 +980,78 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
524
980
|
Buffer.byteLength(options.sourceKey) > 512) {
|
|
525
981
|
throw new CodexSecurityError("The source key must contain 1–512 UTF-8 bytes and no NUL characters. Use a stable scanner organization/project/branch namespace across imports.");
|
|
526
982
|
}
|
|
983
|
+
const environment = dependencies.environment ?? process.env;
|
|
984
|
+
dependencies.signal?.throwIfAborted();
|
|
527
985
|
progress({ phase: "reading", completed: 0 });
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
986
|
+
const trivyReportUrls = options.provider === "trivy" && typeof supplied !== "function"
|
|
987
|
+
? trivyBatchSourceUrls(supplied.current, supplied.current.findings.length > 0)
|
|
988
|
+
: undefined;
|
|
989
|
+
if (trivyReportUrls)
|
|
990
|
+
validateTrivyRepositoryUrl(options.repository);
|
|
991
|
+
const catalogKey = trivyReportUrls
|
|
992
|
+
? (url) => cloudSourceKey(url, "github")
|
|
993
|
+
: cloudRepositoryUrlKey;
|
|
994
|
+
const state = externalPublicationStateDirectory(environment);
|
|
995
|
+
function pendingFile(key) {
|
|
996
|
+
return join(state, `${key}.pending.json`);
|
|
997
|
+
}
|
|
998
|
+
let previousFindings;
|
|
999
|
+
async function previousFindingsIfSaved(input, currentKey) {
|
|
1000
|
+
if (!input.readPreviousFindings || previousFindings)
|
|
1001
|
+
return previousFindings;
|
|
1002
|
+
// An empty state directory (or just this current receipt) needs only the
|
|
1003
|
+
// current reader for its preview.
|
|
1004
|
+
const entries = (await readdir(state).catch(nullIfMissingFile)) ?? [];
|
|
1005
|
+
if (entries.some((name) => /^[a-f0-9]{64}\.(?:pending|private-import)\.json$/u.test(name) &&
|
|
1006
|
+
name.split(".", 1)[0] !== currentKey))
|
|
1007
|
+
previousFindings = input.readPreviousFindings();
|
|
1008
|
+
return previousFindings;
|
|
1009
|
+
}
|
|
1010
|
+
async function checkSelection(input) {
|
|
1011
|
+
const parsed = input.current;
|
|
1012
|
+
checkTrivyReportProvider(options.provider, parsed.report);
|
|
1013
|
+
for (const finding of parsed.findings)
|
|
1014
|
+
checkRetainedTrivyProvider(options.provider, finding);
|
|
1015
|
+
if (!parsed.findings.length &&
|
|
1016
|
+
!input.original?.parsed.findings.length &&
|
|
1017
|
+
input.potentialIds !== null &&
|
|
1018
|
+
!input.potentialIds?.length &&
|
|
1019
|
+
!input.uncertainFindingIds?.length &&
|
|
1020
|
+
!input.unprovenOccurrenceCount &&
|
|
1021
|
+
!input.unprovenIdPrefixes?.length &&
|
|
1022
|
+
!(await previousFindingsIfSaved(input))?.findings.length)
|
|
1023
|
+
throw new NoPublishableFindingsError(parsed);
|
|
1024
|
+
}
|
|
1025
|
+
if (typeof supplied !== "function")
|
|
1026
|
+
await checkSelection(supplied);
|
|
541
1027
|
progress({ phase: "discovering", completed: 0 });
|
|
542
|
-
const environment = dependencies.environment ?? process.env;
|
|
543
|
-
requireExternalImports(environment);
|
|
544
1028
|
const apiBaseUrl = cloudBaseUrl(environment);
|
|
545
1029
|
const cloudApiUrl = `${apiBaseUrl}/external`;
|
|
546
1030
|
// Validate the configured return destination before authentication or uploads.
|
|
547
1031
|
cloudFindingsUrl(environment, options.repository);
|
|
548
1032
|
const credentials = await (dependencies.credentials ?? (() => readCloudCredentials(environment)))();
|
|
549
|
-
let
|
|
1033
|
+
let canStartJob = false;
|
|
1034
|
+
let repositorySeverities;
|
|
1035
|
+
const jobVersionHeader = "Codex-Security-Private-Import-Job-Version";
|
|
1036
|
+
const providerJobVersion = privateJobVersions[options.provider];
|
|
1037
|
+
// Older services recognize an exact v2 request for AWS. Only ask for v3
|
|
1038
|
+
// when publishing a provider introduced by that contract.
|
|
1039
|
+
const requestedJobVersion = String(providerJobVersion ?? 2);
|
|
1040
|
+
let jobApiVersion;
|
|
550
1041
|
async function request(endpoint, body) {
|
|
551
1042
|
dependencies.signal?.throwIfAborted();
|
|
552
1043
|
// Allow upload and response transport around the server's publication budget.
|
|
553
1044
|
const timeout = AbortSignal.timeout(body ? 60_000 : 30_000);
|
|
1045
|
+
const repositoryCatalog = endpoint.startsWith("/repositories?");
|
|
554
1046
|
const response = await (dependencies.fetch ?? globalThis.fetch)(`${cloudApiUrl}${endpoint}`, {
|
|
555
1047
|
method: body ? "POST" : "GET",
|
|
556
1048
|
headers: {
|
|
557
1049
|
Authorization: `Bearer ${credentials.access_token}`,
|
|
558
1050
|
"ChatGPT-Account-ID": credentials.account_id,
|
|
559
1051
|
Accept: "application/json",
|
|
1052
|
+
...(repositoryCatalog
|
|
1053
|
+
? { [jobVersionHeader]: requestedJobVersion }
|
|
1054
|
+
: {}),
|
|
560
1055
|
...(body ? { "Content-Type": "application/json" } : {}),
|
|
561
1056
|
},
|
|
562
1057
|
...(body ? { body: JSON.stringify(body) } : {}),
|
|
@@ -570,37 +1065,54 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
570
1065
|
const retryAfter = response.headers.get("Retry-After");
|
|
571
1066
|
throw new CloudImportError(response.status, `Cloud import failed (HTTP ${response.status}). ${payload?.error?.message ?? response.statusText}${retryAfter ? ` Retry-After: ${retryAfter}.` : ""}`);
|
|
572
1067
|
}
|
|
573
|
-
if (
|
|
574
|
-
const advertised = response.headers
|
|
575
|
-
|
|
576
|
-
|
|
1068
|
+
if (repositoryCatalog) {
|
|
1069
|
+
const advertised = (header) => response.headers
|
|
1070
|
+
.get(header)
|
|
1071
|
+
?.split(",")
|
|
1072
|
+
.map((item) => item.trim());
|
|
1073
|
+
repositorySeverities = advertised("Codex-Security-Repository-Import-Severities");
|
|
1074
|
+
canStartJob =
|
|
1075
|
+
advertised("Codex-Security-Private-Import-Providers")?.includes(options.provider) ?? false;
|
|
1076
|
+
jobApiVersion =
|
|
1077
|
+
response.headers.get(jobVersionHeader) === requestedJobVersion
|
|
1078
|
+
? providerJobVersion
|
|
1079
|
+
: undefined;
|
|
577
1080
|
}
|
|
578
1081
|
return response.json();
|
|
579
1082
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
1083
|
+
async function discoverDestination() {
|
|
1084
|
+
const destinations = [];
|
|
1085
|
+
let page = null;
|
|
1086
|
+
const seenPages = new Set();
|
|
1087
|
+
do {
|
|
1088
|
+
const result = validateRepositories(await request(`/repositories?limit=20&repository=${encodeURIComponent(options.repository)}${page ? `&page=${encodeURIComponent(page)}` : ""}`));
|
|
1089
|
+
destinations.push(...result.data.filter((item) => item.id === options.repository ||
|
|
1090
|
+
catalogKey(item.url) === catalogKey(options.repository)));
|
|
1091
|
+
page = result.next;
|
|
1092
|
+
if (result.has_more !== (page !== null) ||
|
|
1093
|
+
(page !== null && seenPages.has(page)))
|
|
1094
|
+
throw new CodexSecurityError("Cloud returned invalid repository pagination.");
|
|
1095
|
+
if (page !== null)
|
|
1096
|
+
seenPages.add(page);
|
|
1097
|
+
} while (page !== null);
|
|
1098
|
+
if (destinations.length !== 1)
|
|
1099
|
+
throw new CodexSecurityError(destinations.length
|
|
1100
|
+
? "The repository matches multiple connectors. Select an unambiguous Cloud repository."
|
|
1101
|
+
: "The destination repository is not available to this Cloud account. Copy its repository URL or ID from Codex Security Cloud and check that you are signed into the intended account.");
|
|
1102
|
+
const destination = destinations[0];
|
|
1103
|
+
if (trivyReportUrls)
|
|
1104
|
+
validateTrivyRepositoryUrl(destination.url);
|
|
1105
|
+
return destination;
|
|
1106
|
+
}
|
|
1107
|
+
const destination = await discoverDestination();
|
|
1108
|
+
const deferred = typeof supplied === "function";
|
|
1109
|
+
const resolved = deferred ? await supplied(destination) : supplied;
|
|
1110
|
+
if (deferred)
|
|
1111
|
+
await checkSelection(resolved);
|
|
1112
|
+
const report = resolved.current;
|
|
600
1113
|
const source = { provider: options.provider, source_key: options.sourceKey };
|
|
601
1114
|
const importPrefix = source.provider === "sonar" ? "/v2" : "";
|
|
602
1115
|
const sourceReportsPath = importPrefix + sourcePath(destination);
|
|
603
|
-
const state = externalPublicationStateDirectory(environment);
|
|
604
1116
|
const checkpointIdentity = [
|
|
605
1117
|
// Keep existing production checkpoints readable; other deployments must
|
|
606
1118
|
// never share a saved request or receipt with the production default.
|
|
@@ -616,6 +1128,88 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
616
1128
|
function localeKey(rows) {
|
|
617
1129
|
return hash("sha256", canonicalJson([...checkpointIdentity, rows], (left, right) => left.localeCompare(right)));
|
|
618
1130
|
}
|
|
1131
|
+
const hosted = options.provider === "snyk" || options.provider === "semgrep";
|
|
1132
|
+
// Different selections can share native occurrences. Serialize their checkpoint
|
|
1133
|
+
// creation under the authenticated source and release before calling Cloud.
|
|
1134
|
+
const sourceLock = "source-" + hash("sha256", canonicalJson(checkpointIdentity));
|
|
1135
|
+
const withSourceAdmission = (operation) => hosted ? underLocks([sourceLock], operation) : operation();
|
|
1136
|
+
let projection = resolved;
|
|
1137
|
+
let capturedPending;
|
|
1138
|
+
const projectionKeys = new Set();
|
|
1139
|
+
if (options.provider === "semgrep" || options.provider === "snyk") {
|
|
1140
|
+
for (const candidate of hostedPublicationProjections(resolved, options.provider, destination, readerSources)) {
|
|
1141
|
+
const candidateKey = scopeKey(candidate.currentIdentity);
|
|
1142
|
+
if (projectionKeys.has(candidateKey))
|
|
1143
|
+
continue;
|
|
1144
|
+
// New imports use the first reconstructed projection; an exact pending key
|
|
1145
|
+
// takes precedence, including an earlier SDK's unmodified original input.
|
|
1146
|
+
capturedPending = await readOptionalFile(pendingFile(candidateKey));
|
|
1147
|
+
if (projection === resolved || capturedPending !== undefined)
|
|
1148
|
+
projection = candidate;
|
|
1149
|
+
projectionKeys.add(candidateKey);
|
|
1150
|
+
if (capturedPending !== undefined)
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
// Changed reader projections get new keys, but both transports must replay the
|
|
1155
|
+
// exact bytes already approved by the earlier reader when a checkpoint exists.
|
|
1156
|
+
const privateClient = privateImportClient(apiBaseUrl, credentials, dependencies.fetch ?? globalThis.fetch, dependencies.signal);
|
|
1157
|
+
let previewContext;
|
|
1158
|
+
const currentReaderKey = resolved.readPreviousFindings
|
|
1159
|
+
? scopeKey(resolved.currentIdentity)
|
|
1160
|
+
: undefined;
|
|
1161
|
+
let alternateKey;
|
|
1162
|
+
let resumingPreviousReader = false;
|
|
1163
|
+
function previousCandidateKey(previous) {
|
|
1164
|
+
if (!previous?.findings.length)
|
|
1165
|
+
return;
|
|
1166
|
+
// The file reader already validated plain JSON evidence for Cloud. Only a
|
|
1167
|
+
// matching checkpoint needs the full normalized publication snapshot.
|
|
1168
|
+
const previousKey = scopeKey(publicationIdentity(previous, options.provider));
|
|
1169
|
+
return previousKey !== currentReaderKey ? previousKey : undefined;
|
|
1170
|
+
}
|
|
1171
|
+
async function alternateCheckpoint(key, context) {
|
|
1172
|
+
const pending = await readOptionalFile(pendingFile(key));
|
|
1173
|
+
if (pending !== undefined)
|
|
1174
|
+
return { pending };
|
|
1175
|
+
const saved = await readOptionalFile(join(state, key + ".private-import.json"));
|
|
1176
|
+
if (saved === undefined)
|
|
1177
|
+
return;
|
|
1178
|
+
const checkpoint = parsePrivateCheckpoint(saved);
|
|
1179
|
+
// A completed import cannot acknowledge findings newly admitted by the
|
|
1180
|
+
// current reader. Pending uploads and jobs always retain their original bytes.
|
|
1181
|
+
if (!resumingPreviousReader &&
|
|
1182
|
+
previousFindings &&
|
|
1183
|
+
checkpoint.receipt?.status === "completed" &&
|
|
1184
|
+
!sameFindingSelection(previousFindings.findings, resolved.current.findings))
|
|
1185
|
+
return;
|
|
1186
|
+
if (checkpoint.contextVersion === (await context()).context_version)
|
|
1187
|
+
return { pending };
|
|
1188
|
+
}
|
|
1189
|
+
async function assertNoAlternateCheckpoint(context = () => privateClient.context()) {
|
|
1190
|
+
if (alternateKey && (await alternateCheckpoint(alternateKey, context)))
|
|
1191
|
+
throw new CodexSecurityError(resumingPreviousReader
|
|
1192
|
+
? "Both reader versions have saved publications for this report. Resume either one using its original normalized findings."
|
|
1193
|
+
: "Another publication prepared this input. Run the command again to review and resume the saved request.");
|
|
1194
|
+
}
|
|
1195
|
+
if (currentReaderKey)
|
|
1196
|
+
alternateKey = previousCandidateKey(await previousFindingsIfSaved(resolved, currentReaderKey));
|
|
1197
|
+
if (alternateKey && previousFindings) {
|
|
1198
|
+
const context = async () => (previewContext ??= await privateClient.context());
|
|
1199
|
+
const checkpoint = await alternateCheckpoint(alternateKey, context);
|
|
1200
|
+
capturedPending = checkpoint?.pending;
|
|
1201
|
+
if (checkpoint) {
|
|
1202
|
+
projection = normalizedPublicationInput(previousFindings, options.provider);
|
|
1203
|
+
resumingPreviousReader = true;
|
|
1204
|
+
alternateKey = currentReaderKey;
|
|
1205
|
+
await assertNoAlternateCheckpoint(context);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
const input = projection;
|
|
1209
|
+
let { current: parsed, legacy: legacyParsed, currentIdentity, legacyIdentity, recheckFileRepository, } = input;
|
|
1210
|
+
const scopedSemgrepReport = options.provider === "semgrep" &&
|
|
1211
|
+
"sourceFormat" in parsed &&
|
|
1212
|
+
isSemgrepPlatformFormat(parsed.sourceFormat);
|
|
619
1213
|
const original = input.original;
|
|
620
1214
|
const originalParsed = original?.parsed ?? parsed;
|
|
621
1215
|
const originalIdentity = original?.identity ?? currentIdentity;
|
|
@@ -636,7 +1230,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
636
1230
|
originalWireKey,
|
|
637
1231
|
localeKey(original.parsed.findings),
|
|
638
1232
|
])) {
|
|
639
|
-
const bytes = await readOptionalFile(
|
|
1233
|
+
const bytes = await readOptionalFile(pendingFile(pathKey));
|
|
640
1234
|
if (bytes === undefined)
|
|
641
1235
|
continue;
|
|
642
1236
|
const record = JSON.parse(bytes);
|
|
@@ -669,12 +1263,186 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
669
1263
|
destination.repo_connector_id &&
|
|
670
1264
|
wireJson(batch.source) === wireJson(source)));
|
|
671
1265
|
}
|
|
1266
|
+
const originalHostedRetry = "This source has a pending hosted Cloud request. Resume it with the SDK build that created it and the original input before publishing another selection.";
|
|
1267
|
+
const unknownHostedRetry = "A pending hosted request matches this provider and repository, but its deployment could not be established. Resume it with the SDK build that created it, on the original deployment, using the full original input and metadata.";
|
|
1268
|
+
function originalHostedPending(content, filenameKey) {
|
|
1269
|
+
const projection = content.inputProjection;
|
|
1270
|
+
if ((options.provider !== "semgrep" && options.provider !== "snyk") ||
|
|
1271
|
+
content.accountId !== credentials.account_id ||
|
|
1272
|
+
!projection ||
|
|
1273
|
+
!content.requests?.length ||
|
|
1274
|
+
!content.requests.every(({ repository, source: savedSource }) => repository.id === destination.id &&
|
|
1275
|
+
repository.repo_connector_id === destination.repo_connector_id &&
|
|
1276
|
+
canonicalJson(savedSource) === canonicalJson(source)))
|
|
1277
|
+
return false;
|
|
1278
|
+
const findings = submissionFindings(content.requests);
|
|
1279
|
+
if (projection.savedEvidenceDigest !== hash("sha256", canonicalJson(findings)))
|
|
1280
|
+
return false;
|
|
1281
|
+
const projections = [findings];
|
|
1282
|
+
// Historical filenames include caller fields discarded by request validation.
|
|
1283
|
+
// Reuse them by stable ID with the evidence and order of the approved request.
|
|
1284
|
+
const metadata = new Map(legacyParsed.findings
|
|
1285
|
+
.filter((row) => Object.keys(row).some((key) => key !== "evidence" && key !== "source_finding_id"))
|
|
1286
|
+
.map((row) => [row.source_finding_id, row]));
|
|
1287
|
+
if (findings.some((row) => metadata.has(row.source_finding_id)))
|
|
1288
|
+
projections.push(findings.map((row) => ({
|
|
1289
|
+
...metadata.get(row.source_finding_id),
|
|
1290
|
+
...row,
|
|
1291
|
+
})));
|
|
1292
|
+
const identities = [...projections];
|
|
1293
|
+
if (parsed.report !== undefined) {
|
|
1294
|
+
const report = reportForJson(parsed.report);
|
|
1295
|
+
identities.push(...projections.map((rows) => ({ findings: rows, report })));
|
|
1296
|
+
}
|
|
1297
|
+
// Caller metadata on a normalized finding is part of the filename but not the
|
|
1298
|
+
// request body. An exact retry still supplies that original identity.
|
|
1299
|
+
if (filenameKey === scopeKey(legacyIdentity))
|
|
1300
|
+
identities.unshift(legacyIdentity);
|
|
1301
|
+
const identity = identities.find((value) => filenameKey === scopeKey(value));
|
|
1302
|
+
const digest = (value) => hash("sha256", canonicalJson(value));
|
|
1303
|
+
const semgrep = options.provider === "semgrep";
|
|
1304
|
+
const isHosted = (row) => semgrep
|
|
1305
|
+
? isSemgrepPlatformEvidence(row, "semgrep")
|
|
1306
|
+
: isSnykRestFinding(row);
|
|
1307
|
+
const scannerId = (row) => isHosted({
|
|
1308
|
+
...row,
|
|
1309
|
+
evidence: { ...row.evidence, source_data: undefined },
|
|
1310
|
+
});
|
|
1311
|
+
const hasNativeEvidence = (row) => {
|
|
1312
|
+
const data = row.evidence.source_data;
|
|
1313
|
+
// A discriminator alone cannot identify a native occurrence.
|
|
1314
|
+
return (data &&
|
|
1315
|
+
isHosted({
|
|
1316
|
+
source_finding_id: "",
|
|
1317
|
+
evidence: {
|
|
1318
|
+
...row.evidence,
|
|
1319
|
+
source_data: { ...data, format: undefined },
|
|
1320
|
+
},
|
|
1321
|
+
}));
|
|
1322
|
+
};
|
|
1323
|
+
const references = hostedSourceReferences(readerSources, content.approvedRepositoryUrl ?? destination.url, content.approvedRepositoryPlatform);
|
|
1324
|
+
const occurrenceIds = (rows) => {
|
|
1325
|
+
const ids = new Set(rows.map((row) => row.source_finding_id));
|
|
1326
|
+
let native = false;
|
|
1327
|
+
let unresolved = false;
|
|
1328
|
+
for (const row of rows) {
|
|
1329
|
+
if (!hasNativeEvidence(row))
|
|
1330
|
+
continue;
|
|
1331
|
+
native = true;
|
|
1332
|
+
try {
|
|
1333
|
+
const id = semgrep
|
|
1334
|
+
? semgrepPlatformFindingBinding({ ...row, source_finding_id: "" }, "semgrep", references, undefined, undefined, undefined, "cloud")?.nativeId
|
|
1335
|
+
: snykRestCheckpointFindingId(row, references);
|
|
1336
|
+
if (id) {
|
|
1337
|
+
ids.add(id);
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
catch {
|
|
1342
|
+
// An earlier SDK may have accepted a partial native projection.
|
|
1343
|
+
}
|
|
1344
|
+
if (!scannerId(row))
|
|
1345
|
+
unresolved = true;
|
|
1346
|
+
}
|
|
1347
|
+
return { ids, native, unresolved };
|
|
1348
|
+
};
|
|
1349
|
+
const previous = occurrenceIds(findings);
|
|
1350
|
+
const requested = occurrenceIds(parsed.findings);
|
|
1351
|
+
const hostedSelection = projection.retainedHostedSelection ||
|
|
1352
|
+
scopedSemgrepReport ||
|
|
1353
|
+
previous.native ||
|
|
1354
|
+
requested.native;
|
|
1355
|
+
// Submitted and native IDs share one namespace even when one side drops its raw evidence.
|
|
1356
|
+
const couldOverlap = (hostedSelection &&
|
|
1357
|
+
Array.from(requested.ids).some((id) => previous.ids.has(id))) ||
|
|
1358
|
+
(previous.native &&
|
|
1359
|
+
requested.native &&
|
|
1360
|
+
(previous.unresolved || requested.unresolved));
|
|
1361
|
+
if (content.approvedRepositoryUrl && !projection.retainedHostedSelection) {
|
|
1362
|
+
if (!couldOverlap)
|
|
1363
|
+
return false;
|
|
1364
|
+
if (identity)
|
|
1365
|
+
return projection.inputDigest === digest(identity) && "verified";
|
|
1366
|
+
// The filename includes metadata omitted from the saved request. A reproducible
|
|
1367
|
+
// original digest under another filename proves this is another deployment.
|
|
1368
|
+
return (!identities.some((value) => digest(value) === projection.inputDigest) &&
|
|
1369
|
+
"unidentified");
|
|
1370
|
+
}
|
|
1371
|
+
if (identity && projection.inputDigest !== digest(identity))
|
|
1372
|
+
return ((couldOverlap || !previous.native || !requested.native) && "verified");
|
|
1373
|
+
if (!couldOverlap)
|
|
1374
|
+
return false;
|
|
1375
|
+
if (!identity) {
|
|
1376
|
+
// If the saved selections reconstruct an old input digest but not its scoped
|
|
1377
|
+
// filename, the pending request belongs to another deployment. The older
|
|
1378
|
+
// publisher included its repository comparison flags in the digest.
|
|
1379
|
+
const repositories = new Set([destination.url]);
|
|
1380
|
+
for (const { evidence } of findings) {
|
|
1381
|
+
const data = evidence.source_data;
|
|
1382
|
+
const project = data?.["project"];
|
|
1383
|
+
const retained = (semgrep && isRecord(project) ? project["url"] : undefined) ??
|
|
1384
|
+
data?.["sourceRepositoryUrl"];
|
|
1385
|
+
if (typeof retained === "string")
|
|
1386
|
+
repositories.add(retained);
|
|
1387
|
+
}
|
|
1388
|
+
const paths = semgrep ? [null, true] : [false, true];
|
|
1389
|
+
const suffixes = semgrep ? [false] : [false, true];
|
|
1390
|
+
for (const candidate of identities) {
|
|
1391
|
+
if (digest(candidate) === projection.inputDigest)
|
|
1392
|
+
return false;
|
|
1393
|
+
for (const strict of paths) {
|
|
1394
|
+
for (const suffix of suffixes) {
|
|
1395
|
+
for (const repository of repositories) {
|
|
1396
|
+
const url = hostedRepositoryUrlKey(repository, !strict, suffix);
|
|
1397
|
+
if (digest([candidate, [url, strict, suffix]]) ===
|
|
1398
|
+
projection.inputDigest)
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return "unidentified";
|
|
1405
|
+
}
|
|
1406
|
+
return "verified";
|
|
1407
|
+
}
|
|
1408
|
+
function wasReset(content) {
|
|
1409
|
+
return content.requests.some(({ repository }) => repository.reset_marker !== destination.reset_marker);
|
|
1410
|
+
}
|
|
1411
|
+
async function confirmReset() {
|
|
1412
|
+
// A newer pending request may have been written while the catalog response
|
|
1413
|
+
// was in flight. Confirm the reset after observing this immutable request.
|
|
1414
|
+
const confirmed = await discoverDestination();
|
|
1415
|
+
if (confirmed.id !== destination.id ||
|
|
1416
|
+
confirmed.repo_connector_id !== destination.repo_connector_id ||
|
|
1417
|
+
confirmed.reset_marker !== destination.reset_marker)
|
|
1418
|
+
throw new CodexSecurityError("The repository changed while preparing this publication. Review the destination again.");
|
|
1419
|
+
}
|
|
1420
|
+
function suppliedSemgrepScopeDigest() {
|
|
1421
|
+
const scope = semgrepPlatformReportScope(report, options.provider);
|
|
1422
|
+
return hash("sha256", canonicalJson(scope?.format
|
|
1423
|
+
? [
|
|
1424
|
+
scope.deployment,
|
|
1425
|
+
canonicalNumber(scope.projectId),
|
|
1426
|
+
scope.ref,
|
|
1427
|
+
scope.product,
|
|
1428
|
+
]
|
|
1429
|
+
: null));
|
|
1430
|
+
}
|
|
672
1431
|
async function retireIfReset(content, retire) {
|
|
673
|
-
if (content
|
|
1432
|
+
if (wasReset(content)) {
|
|
1433
|
+
if (hosted)
|
|
1434
|
+
await confirmReset();
|
|
674
1435
|
await retire();
|
|
675
1436
|
throw new CloudImportError(409, "The repository was reset after this submission. The saved request was retired without uploading. Review the destination and run the command again to approve a fresh publication.");
|
|
676
1437
|
}
|
|
677
1438
|
}
|
|
1439
|
+
function retirePendingIfReset(content, keys, path, remove = () => rm(path)) {
|
|
1440
|
+
return retireIfReset(content, () => underLocks(keys, async () => {
|
|
1441
|
+
const bytes = await readOptionalFile(path);
|
|
1442
|
+
if (bytes !== undefined && sameSubmission(JSON.parse(bytes), content))
|
|
1443
|
+
await remove();
|
|
1444
|
+
}));
|
|
1445
|
+
}
|
|
678
1446
|
function readSaved(content) {
|
|
679
1447
|
if (!content ||
|
|
680
1448
|
content.accountId !== credentials.account_id ||
|
|
@@ -682,21 +1450,34 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
682
1450
|
content.requests.length === 0)
|
|
683
1451
|
throw new Error("Saved import account or requests do not match.");
|
|
684
1452
|
content.requests = content.requests.map(validateImportRequest);
|
|
1453
|
+
for (const finding of submissionFindings(content.requests))
|
|
1454
|
+
checkRetainedTrivyProvider(options.provider, finding);
|
|
685
1455
|
if (!matchesSavedDestination(content.requests))
|
|
686
1456
|
throw new Error("Saved import destination does not match.");
|
|
1457
|
+
if (source.provider === "trivy" && !content.trivyRepositoryUrl)
|
|
1458
|
+
throw new CodexSecurityError("This build cannot verify the original repository for this pending Trivy import. Check its destination before resuming with the build that created it.");
|
|
687
1459
|
return content;
|
|
688
1460
|
}
|
|
689
|
-
function validateSaved(record, legacy = false) {
|
|
1461
|
+
function validateSaved(record, legacy = false, filenameKey = key) {
|
|
690
1462
|
const content = readSaved(record);
|
|
691
1463
|
const saved = submissionFindings(content.requests);
|
|
692
1464
|
const wire = wireJson(saved);
|
|
693
|
-
const expected = legacy ? legacyParsed.findings : parsed.findings;
|
|
694
1465
|
const projection = content.inputProjection;
|
|
1466
|
+
const expected = repositoryFindings(legacy ? legacyParsed : parsed, projection?.repositorySeverities);
|
|
695
1467
|
if (projection &&
|
|
696
1468
|
(!sameFindingSelection(saved, expected) ||
|
|
697
1469
|
projection.inputDigest !== (legacy ? legacyInputDigest : inputDigest) ||
|
|
698
|
-
projection.savedEvidenceDigest !== hash("sha256", wire)))
|
|
1470
|
+
projection.savedEvidenceDigest !== hash("sha256", wire))) {
|
|
1471
|
+
const status = originalHostedPending(content, filenameKey);
|
|
1472
|
+
if (status === "unidentified")
|
|
1473
|
+
throw new CodexSecurityError(unknownHostedRetry);
|
|
1474
|
+
if (status) {
|
|
1475
|
+
if (wasReset(content))
|
|
1476
|
+
return content;
|
|
1477
|
+
throw new CodexSecurityError(originalHostedRetry);
|
|
1478
|
+
}
|
|
699
1479
|
throw new Error("Saved import evidence does not match the selected input.");
|
|
1480
|
+
}
|
|
700
1481
|
// Older file readers can have a different, explicitly bound projection.
|
|
701
1482
|
// A corrected numeric checkpoint must carry the selected evidence verbatim.
|
|
702
1483
|
const exactWire = historicalOnly || hasBoxedScalars || content.wireKey !== undefined;
|
|
@@ -708,6 +1489,12 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
708
1489
|
projection?.identityFormat !== 2 &&
|
|
709
1490
|
!verifiableLegacyMetadata(originalParsed, true))
|
|
710
1491
|
throw unmatchedPreviousNumbers();
|
|
1492
|
+
checkFindingProvider({ ...parsed, findings: saved }, options.provider);
|
|
1493
|
+
const approvedScope = content.inputProjection?.semgrepPartialScopeDigest;
|
|
1494
|
+
if (approvedScope !== undefined &&
|
|
1495
|
+
!wasReset(content) &&
|
|
1496
|
+
approvedScope !== suppliedSemgrepScopeDigest())
|
|
1497
|
+
throw new CodexSecurityError("The supplied Semgrep report scope does not match the approved request.");
|
|
711
1498
|
return content;
|
|
712
1499
|
}
|
|
713
1500
|
// The original filename and digests identify the previous selection, but
|
|
@@ -716,7 +1503,8 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
716
1503
|
function readPreviousNumbers(record) {
|
|
717
1504
|
const content = readSaved(record);
|
|
718
1505
|
const projection = content.inputProjection;
|
|
719
|
-
const
|
|
1506
|
+
const saved = submissionFindings(content.requests);
|
|
1507
|
+
const savedWire = wireJson(saved);
|
|
720
1508
|
const wireDigest = hash("sha256", savedWire);
|
|
721
1509
|
if (projection?.inputDigest !== jsonDigest(originalIdentity, canonicalJson))
|
|
722
1510
|
throw unmatchedPreviousNumbers();
|
|
@@ -738,8 +1526,10 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
738
1526
|
if ((changedCapture && !historicalOnly) ||
|
|
739
1527
|
!verifiableLegacyMetadata(originalParsed, false))
|
|
740
1528
|
throw unmatchedPreviousNumbers();
|
|
1529
|
+
checkFindingProvider({ ...parsed, findings: saved }, options.provider);
|
|
741
1530
|
content.legacyApproval = true;
|
|
742
1531
|
content.inputProjection = {
|
|
1532
|
+
...content.inputProjection,
|
|
743
1533
|
identityFormat: 2,
|
|
744
1534
|
inputDigest,
|
|
745
1535
|
savedEvidenceDigest: wireDigest,
|
|
@@ -751,7 +1541,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
751
1541
|
}
|
|
752
1542
|
const key = scopeKey(currentIdentity);
|
|
753
1543
|
const stagingKey = originalKey ?? key;
|
|
754
|
-
const canonicalPath =
|
|
1544
|
+
const canonicalPath = pendingFile(key);
|
|
755
1545
|
const lookupPath = join(state, `${key}.lookup.json`);
|
|
756
1546
|
// A lookup only suggests a regular file to validate. A missing or stale hint
|
|
757
1547
|
// leaves the same on-disk discovery available as before.
|
|
@@ -778,7 +1568,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
778
1568
|
for (const legacyKey of legacyKeys) {
|
|
779
1569
|
if (legacyKey === key || legacyKey === originalKey)
|
|
780
1570
|
continue;
|
|
781
|
-
const legacyPath =
|
|
1571
|
+
const legacyPath = pendingFile(legacyKey);
|
|
782
1572
|
const captured = await readOptionalFile(legacyPath);
|
|
783
1573
|
if (captured !== undefined) {
|
|
784
1574
|
// Preserve requests staged by the earlier locale-based filename format.
|
|
@@ -827,7 +1617,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
827
1617
|
sameFindingSelection(submissionFindings(readSaved(prior).requests), rows))
|
|
828
1618
|
return;
|
|
829
1619
|
}
|
|
830
|
-
const content = validateSaved(serialized === undefined ? JSON.parse(captured) : prior, true);
|
|
1620
|
+
const content = validateSaved(serialized === undefined ? JSON.parse(captured) : prior, true, legacyKey);
|
|
831
1621
|
if (!sameFindingSelection(legacyParsed.findings, parsed.findings))
|
|
832
1622
|
throw new CodexSecurityError("The saved import selects different findings from this input. Resume the original selection before publishing this selection.");
|
|
833
1623
|
await retireIfReset(content, async () => {
|
|
@@ -851,15 +1641,17 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
851
1641
|
recovered = content;
|
|
852
1642
|
if (serialized === undefined)
|
|
853
1643
|
return;
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1644
|
+
await withSourceAdmission(async () => {
|
|
1645
|
+
if (!rebindProjection) {
|
|
1646
|
+
await rename(legacyPath, canonicalPath);
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
// Bind the new input projection to the original immutable evidence,
|
|
1650
|
+
// so later inventory reordering still resumes these exact requests.
|
|
1651
|
+
await writeAtomicJson(canonicalPath, content);
|
|
1652
|
+
await rm(legacyPath);
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
863
1655
|
});
|
|
864
1656
|
}
|
|
865
1657
|
}
|
|
@@ -1007,11 +1799,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1007
1799
|
}
|
|
1008
1800
|
}
|
|
1009
1801
|
async function selectedCheckpoint(knownFileKey, preparing = false) {
|
|
1010
|
-
const directory = await validatePreparedOutputDir(state, undefined, true).catch(
|
|
1011
|
-
if (error.code === "ENOENT")
|
|
1012
|
-
return undefined;
|
|
1013
|
-
throw error;
|
|
1014
|
-
});
|
|
1802
|
+
const directory = await validatePreparedOutputDir(state, undefined, true).catch(nullIfMissingFile);
|
|
1015
1803
|
if (!directory)
|
|
1016
1804
|
return undefined;
|
|
1017
1805
|
const known = new Set([key, originalKey, knownFileKey].filter((value) => value !== undefined));
|
|
@@ -1020,11 +1808,12 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1020
1808
|
let incomplete = false;
|
|
1021
1809
|
let stagingPathOccupied = false;
|
|
1022
1810
|
async function readCandidate(fileKey, selected, contents) {
|
|
1023
|
-
const path =
|
|
1811
|
+
const path = pendingFile(fileKey);
|
|
1024
1812
|
const serialized = contents ??
|
|
1025
1813
|
(selected?.fileKey === key && !known.has(fileKey)
|
|
1026
1814
|
? await readOptionalRegularFile(path)
|
|
1027
|
-
: await readOptionalFile(path))
|
|
1815
|
+
: await readOptionalFile(path)) ??
|
|
1816
|
+
(preparing && fileKey === key ? capturedPending : undefined);
|
|
1028
1817
|
if (serialized === undefined) {
|
|
1029
1818
|
if (!known.has(fileKey))
|
|
1030
1819
|
incomplete = true;
|
|
@@ -1049,6 +1838,25 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1049
1838
|
const ownerKey = tagged ? tag : fileKey;
|
|
1050
1839
|
const historical = !tagged && fileKey === originalKey && fileKey !== key;
|
|
1051
1840
|
if (ownerKey !== key && !historical) {
|
|
1841
|
+
if (hosted && record?.inputProjection) {
|
|
1842
|
+
let status;
|
|
1843
|
+
try {
|
|
1844
|
+
status = originalHostedPending(record, ownerKey);
|
|
1845
|
+
}
|
|
1846
|
+
catch {
|
|
1847
|
+
// An unrelated or unreadable checkpoint cannot identify this source.
|
|
1848
|
+
}
|
|
1849
|
+
if (status === "unidentified")
|
|
1850
|
+
throw new CodexSecurityError(unknownHostedRetry);
|
|
1851
|
+
if (status) {
|
|
1852
|
+
if (wasReset(record)) {
|
|
1853
|
+
if (!preparing)
|
|
1854
|
+
throw new CodexSecurityError("The pending request and this preview have different repository reset markers. Review the destination again.");
|
|
1855
|
+
await retirePendingIfReset(record, [fileKey], path);
|
|
1856
|
+
}
|
|
1857
|
+
throw new CodexSecurityError(originalHostedRetry);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1052
1860
|
if (record &&
|
|
1053
1861
|
(!tagged || cannotCaptureOriginal || possibleBufferExport) &&
|
|
1054
1862
|
potentialOriginal(record, fileKey))
|
|
@@ -1105,11 +1913,11 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1105
1913
|
for (const fileKey of known)
|
|
1106
1914
|
selected = await readCandidate(fileKey, selected);
|
|
1107
1915
|
// A known file that disappeared can be checked against its completed receipt.
|
|
1108
|
-
if (!selected && knownFileKey !== undefined)
|
|
1916
|
+
if (!selected && knownFileKey !== undefined && !hosted)
|
|
1109
1917
|
return undefined;
|
|
1110
1918
|
const hint = await lookupFileKey();
|
|
1111
1919
|
if (hint && !known.has(hint)) {
|
|
1112
|
-
const contents = await readOptionalRegularFile(
|
|
1920
|
+
const contents = await readOptionalRegularFile(pendingFile(hint));
|
|
1113
1921
|
if (contents !== undefined) {
|
|
1114
1922
|
selected = await readCandidate(hint, selected, contents);
|
|
1115
1923
|
known.add(hint);
|
|
@@ -1124,11 +1932,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1124
1932
|
selected.content.canonicalChecked ||
|
|
1125
1933
|
selected.content.inputProjection?.identityFormat === 2))
|
|
1126
1934
|
return selected;
|
|
1127
|
-
const entries = await readdir(state, { withFileTypes: true }).catch(
|
|
1128
|
-
if (error.code === "ENOENT")
|
|
1129
|
-
return [];
|
|
1130
|
-
throw error;
|
|
1131
|
-
});
|
|
1935
|
+
const entries = (await readdir(state, { withFileTypes: true }).catch(nullIfMissingFile)) ?? [];
|
|
1132
1936
|
for (const entry of entries) {
|
|
1133
1937
|
if (!entry.isFile() || !/^[a-f0-9]{64}\.pending\.json$/u.test(entry.name))
|
|
1134
1938
|
continue;
|
|
@@ -1172,7 +1976,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1172
1976
|
}
|
|
1173
1977
|
let selected = await selectedCheckpoint(recovered ? key : undefined, true);
|
|
1174
1978
|
const fileKey = selected?.fileKey ?? (recovered ? key : stagingKey);
|
|
1175
|
-
const pendingPath =
|
|
1979
|
+
const pendingPath = pendingFile(fileKey);
|
|
1176
1980
|
async function rememberFile() {
|
|
1177
1981
|
if (fileKey !== key && (await lookupFileKey()) !== fileKey)
|
|
1178
1982
|
await writeAtomicJson(lookupPath, fileKey).catch(() => undefined);
|
|
@@ -1183,6 +1987,19 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1183
1987
|
await rm(lookupPath, { force: true }).catch(() => undefined);
|
|
1184
1988
|
}
|
|
1185
1989
|
const lockKeys = [key, fileKey, stagingKey];
|
|
1990
|
+
if (alternateKey)
|
|
1991
|
+
lockKeys.push(alternateKey);
|
|
1992
|
+
async function underPublishLocks(operation) {
|
|
1993
|
+
// An older publisher may already hold its lock before its checkpoint exists.
|
|
1994
|
+
// Derive that key for actual writes, even after a checkpoint-free preview.
|
|
1995
|
+
if (resolved.readPreviousFindings && !previousFindings) {
|
|
1996
|
+
previousFindings = resolved.readPreviousFindings();
|
|
1997
|
+
alternateKey = previousCandidateKey(previousFindings);
|
|
1998
|
+
if (alternateKey)
|
|
1999
|
+
lockKeys.push(alternateKey);
|
|
2000
|
+
}
|
|
2001
|
+
return underLocks(lockKeys, operation);
|
|
2002
|
+
}
|
|
1186
2003
|
if (selected?.historical) {
|
|
1187
2004
|
const observed = selected;
|
|
1188
2005
|
selected = await underLocks(lockKeys, async () => {
|
|
@@ -1203,138 +2020,315 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1203
2020
|
if (historicalOnly && !saved)
|
|
1204
2021
|
throw unmatchedPreviousNumbers();
|
|
1205
2022
|
if (!parsed.findings.length)
|
|
1206
|
-
|
|
1207
|
-
if (saved)
|
|
1208
|
-
await
|
|
1209
|
-
const current = await readOptionalFile(pendingPath);
|
|
1210
|
-
if (current !== undefined &&
|
|
1211
|
-
sameSubmission(JSON.parse(current), saved))
|
|
1212
|
-
await removePending();
|
|
1213
|
-
}));
|
|
1214
|
-
}
|
|
2023
|
+
throw new NoPublishableFindingsError(parsed);
|
|
2024
|
+
if (saved)
|
|
2025
|
+
await retirePendingIfReset(saved, lockKeys, pendingPath, removePending);
|
|
1215
2026
|
if (saved?.inspectorProjectMapRequired && !inspectorProjectMap)
|
|
1216
2027
|
throw new CodexSecurityError("Supply the verified Inspector project binding again to resume.");
|
|
1217
|
-
|
|
2028
|
+
// Existing repository submissions keep their original request bodies and receipts.
|
|
2029
|
+
const privatePath = join(state, `${key}.private-import.json`);
|
|
2030
|
+
const privateSaved = await readOptionalFile(privatePath);
|
|
2031
|
+
if (resumingPreviousReader && !saved && privateSaved === undefined)
|
|
2032
|
+
throw new CodexSecurityError("The saved publication changed. Run the command again to preview this report.");
|
|
2033
|
+
const usePrivateImport = !saved && (canStartJob || privateSaved !== undefined);
|
|
2034
|
+
async function preparePrivateAttempt() {
|
|
2035
|
+
const context = previewContext ?? (await privateClient.context());
|
|
2036
|
+
if (source.source_key.trim() !== source.source_key)
|
|
2037
|
+
throw new CodexSecurityError("A private source key cannot have leading or trailing whitespace.");
|
|
2038
|
+
const report = await selectPrivateReport(parsed, source.provider, nativePath, context, privateSaved, resolved.requiresStructuredReport);
|
|
2039
|
+
const binding = {
|
|
2040
|
+
format: report.format,
|
|
2041
|
+
apiBaseUrl,
|
|
2042
|
+
accountId: credentials.account_id,
|
|
2043
|
+
source,
|
|
2044
|
+
repository: {
|
|
2045
|
+
id: destination.id,
|
|
2046
|
+
repo_connector_id: destination.repo_connector_id,
|
|
2047
|
+
},
|
|
2048
|
+
sha256: report.digest,
|
|
2049
|
+
contextVersion: context.context_version,
|
|
2050
|
+
};
|
|
2051
|
+
return { context, report, binding };
|
|
2052
|
+
}
|
|
2053
|
+
function acceptsJob(context, format) {
|
|
2054
|
+
return context.can_create_import_jobs && context.formats.includes(format);
|
|
2055
|
+
}
|
|
2056
|
+
// Use an earlier catalog URL only after the account, connector, repository,
|
|
2057
|
+
// inbox context and exact upload digest all match the immutable checkpoint.
|
|
2058
|
+
const existingPrivate = usePrivateImport && privateSaved !== undefined
|
|
2059
|
+
? await preparePrivateAttempt()
|
|
2060
|
+
: undefined;
|
|
2061
|
+
const previous = existingPrivate &&
|
|
2062
|
+
readPrivateCheckpoint(privateSaved, existingPrivate.binding);
|
|
2063
|
+
const retryOfJobId = unsuccessfulJob(previous?.receipt) &&
|
|
2064
|
+
canStartJob &&
|
|
2065
|
+
existingPrivate?.context.can_upload &&
|
|
2066
|
+
acceptsJob(existingPrivate.context, existingPrivate.report.format)
|
|
2067
|
+
? previous?.jobId
|
|
2068
|
+
: undefined;
|
|
2069
|
+
const resumed = previous !== undefined && retryOfJobId === undefined;
|
|
2070
|
+
const privateApproval = resumed ? previous : undefined;
|
|
2071
|
+
const privateUrl = privateApproval?.approvedRepositoryUrl;
|
|
2072
|
+
const approvedPlatform = saved?.approvedRepositoryPlatform ??
|
|
2073
|
+
privateApproval?.approvedRepositoryPlatform;
|
|
2074
|
+
// The findings-only checkpoint key lets projected and native callers resume one immutable
|
|
2075
|
+
// request. Supplemental report claims are outside that digest and must still match its source.
|
|
2076
|
+
const recheckOriginal = options.provider === "semgrep" &&
|
|
2077
|
+
projection !== resolved &&
|
|
2078
|
+
saved?.approvedRepositoryPlatform === "other";
|
|
2079
|
+
// Native Semgrep and OpenGrep files include their required source URL in every
|
|
2080
|
+
// saved finding. An exact replay by repository ID survives a catalog rename.
|
|
2081
|
+
const recordedFileSource = saved &&
|
|
2082
|
+
!saved.approvedRepositoryUrl &&
|
|
2083
|
+
options.provider === "semgrep" &&
|
|
2084
|
+
!deferred &&
|
|
2085
|
+
declaredUrl !== undefined &&
|
|
2086
|
+
saved.requests.every(({ items }) => items.every(({ evidence }) => evidence.details?.repository?.url === declaredUrl));
|
|
2087
|
+
const declaredSource = recheckOriginal ||
|
|
2088
|
+
readerSources.length > 0 ||
|
|
2089
|
+
(declaredUrl !== undefined && !recordedFileSource) ||
|
|
2090
|
+
report.sourceRepositoryUrl !== undefined ||
|
|
2091
|
+
report.sourceRepositoryPlatform !== undefined ||
|
|
2092
|
+
report.snykRestContext !== undefined;
|
|
2093
|
+
let legacyTypedUrl;
|
|
2094
|
+
let suppliedReport = report;
|
|
2095
|
+
const sourceFor = (url, platform) => {
|
|
2096
|
+
try {
|
|
2097
|
+
return hostedRepositoryMatcher(platform
|
|
2098
|
+
? { ...suppliedReport, sourceRepositoryPlatform: platform }
|
|
2099
|
+
: suppliedReport, options.provider, declaredUrl, { url }, readerSources, saved !== undefined);
|
|
2100
|
+
}
|
|
2101
|
+
catch (error) {
|
|
2102
|
+
if (!recheckOriginal || readerSources.length)
|
|
2103
|
+
throw error;
|
|
2104
|
+
// An older strict approval did not distinguish GitLab from another case-sensitive SCM.
|
|
2105
|
+
throw new CodexSecurityError(`${error instanceof Error ? error.message : String(error)} Resume with the original Semgrep input and SCM repository mapping, or the SDK build that created this request.`, { cause: error });
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
if (hosted && saved && declaredSource) {
|
|
2109
|
+
// The released publisher checked typed repository URLs against its authenticated catalog.
|
|
2110
|
+
// Opaque original records could name a different project and cannot establish a rename.
|
|
2111
|
+
const findings = submissionFindings(saved.requests);
|
|
2112
|
+
if (!saved.approvedRepositoryUrl)
|
|
2113
|
+
legacyTypedUrl = findings.find(({ evidence }) => evidence.details?.repository?.url)?.evidence.details?.repository?.url;
|
|
2114
|
+
// Supplemental claims must agree with each verifiable row from the immutable request.
|
|
2115
|
+
suppliedReport = {
|
|
2116
|
+
...report,
|
|
2117
|
+
// The v1 upgrade may drop a redundant mapping using the catalog's GitHub casing.
|
|
2118
|
+
findings: recheckOriginal ? [...report.findings, ...findings] : findings,
|
|
2119
|
+
};
|
|
2120
|
+
}
|
|
2121
|
+
// The released request retained its typed finding URL, but only the authenticated
|
|
2122
|
+
// catalog or a previously recorded approval can bind a new source declaration.
|
|
2123
|
+
const approvedUrl = saved?.approvedRepositoryUrl ?? privateUrl ?? destination.url;
|
|
2124
|
+
if (hosted &&
|
|
2125
|
+
readerSources.some(({ platform, url }) => {
|
|
2126
|
+
const source = normalizeHostedGitRepositoryUrl(url, approvedUrl, platform !== undefined);
|
|
2127
|
+
return (cloudSourceKey(source, platform) !==
|
|
2128
|
+
cloudSourceKey(approvedUrl, platform));
|
|
2129
|
+
}))
|
|
2130
|
+
throw new CodexSecurityError("The reader's source repository does not match the selected Cloud repository.");
|
|
2131
|
+
await recheckFileRepository?.(approvedUrl, approvedPlatform);
|
|
2132
|
+
const hostedSource = hosted && (!saved || declaredSource)
|
|
2133
|
+
? sourceFor(approvedUrl, approvedPlatform)
|
|
2134
|
+
: undefined;
|
|
2135
|
+
const matchesHostedRepository = hostedSource?.matches;
|
|
2136
|
+
function requireApprovedSource(url, platform) {
|
|
2137
|
+
const binding = platform && hostedSource?.github
|
|
2138
|
+
? sourceFor(url, platform)
|
|
2139
|
+
: hostedSource;
|
|
2140
|
+
if (binding && !binding.matches(url))
|
|
2141
|
+
throw new CodexSecurityError("The source project does not match the selected Cloud repository.");
|
|
2142
|
+
}
|
|
2143
|
+
requireApprovedSource(approvedUrl);
|
|
2144
|
+
if (legacyTypedUrl)
|
|
2145
|
+
requireApprovedSource(legacyTypedUrl);
|
|
2146
|
+
const trivyTarget = saved?.trivyRepositoryUrl ?? privateUrl ?? destination.url;
|
|
2147
|
+
function requireTrivyRemote(url, id) {
|
|
2148
|
+
if (trivyRemoteKey(url, trivyTarget) !== catalogKey(trivyTarget)) {
|
|
2149
|
+
const label = id === undefined ? "Source report" : `Finding ${JSON.stringify(id)}`;
|
|
2150
|
+
throw new CodexSecurityError(`${label} belongs to ${JSON.stringify(url)}, which does not match the selected Cloud repository ${JSON.stringify(trivyTarget)}. Verify the source repository mapping before publishing.`);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
if (trivyReportUrls) {
|
|
2154
|
+
for (const url of trivyReportUrls)
|
|
2155
|
+
requireTrivyRemote(url);
|
|
2156
|
+
if (parsed !== resolved.current)
|
|
2157
|
+
for (const url of trivyBatchSourceUrls(parsed, true))
|
|
2158
|
+
requireTrivyRemote(url);
|
|
2159
|
+
}
|
|
2160
|
+
function checkRepositories({ findings, report }, historical = Boolean(saved)) {
|
|
2161
|
+
const { provider } = options;
|
|
2162
|
+
checkTrivyReportProvider(provider, report);
|
|
2163
|
+
// A catalog casing or spelling change keeps the original source comparison target.
|
|
2164
|
+
const approved = hosted ? saved?.approvedRepositoryUrl : undefined;
|
|
2165
|
+
const sameCatalog = approved !== undefined &&
|
|
2166
|
+
cloudSourceKey(approved, "github") ===
|
|
2167
|
+
cloudSourceKey(destination.url, "github");
|
|
2168
|
+
const comparisonUrl = trivyReportUrls
|
|
2169
|
+
? trivyTarget
|
|
2170
|
+
: sameCatalog
|
|
2171
|
+
? approved
|
|
2172
|
+
: (privateUrl ?? destination.url);
|
|
2173
|
+
const key = sameCatalog
|
|
2174
|
+
? (url) => cloudSourceKey(url, saved?.approvedRepositoryPlatform === "other"
|
|
2175
|
+
? undefined
|
|
2176
|
+
: "github")
|
|
2177
|
+
: catalogKey;
|
|
1218
2178
|
function requireDestination(id, url) {
|
|
1219
2179
|
if (url &&
|
|
1220
|
-
|
|
2180
|
+
(matchesHostedRepository
|
|
2181
|
+
? !matchesHostedRepository(url) ||
|
|
2182
|
+
!matchesHostedRepository(comparisonUrl)
|
|
2183
|
+
: key(url) !== key(comparisonUrl)))
|
|
1221
2184
|
throw new CodexSecurityError(`Finding ${JSON.stringify(id)} belongs to ${JSON.stringify(url)}, which does not match the selected Cloud repository ${JSON.stringify(destination.url)}. Verify the source repository mapping before publishing.`);
|
|
1222
2185
|
}
|
|
2186
|
+
if (report?.["format"] === guardianSelectionFormat)
|
|
2187
|
+
requireDestination("Guardian source", declaredScannerRepositoryUrl(report["repositoryUrl"], "Guardian"));
|
|
2188
|
+
// An immutable retry may refer to an earlier repository name. Additional
|
|
2189
|
+
// file declarations outside its saved findings authorize no new writes.
|
|
2190
|
+
if (!historical)
|
|
2191
|
+
for (const { url } of fileRepositories?.() ?? [])
|
|
2192
|
+
requireDestination("Source report", provider === "snyk"
|
|
2193
|
+
? normalizeHostedGitRepositoryUrl(url, destination.url, true)
|
|
2194
|
+
: url);
|
|
1223
2195
|
// Historical checkpoints already fixed the provider and request bytes.
|
|
1224
2196
|
// Recheck any projected source against the destination discovered for this retry.
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
2197
|
+
const checkNative = (...providers) => !historical ||
|
|
2198
|
+
trivyReportUrls !== undefined ||
|
|
2199
|
+
providers.includes(provider);
|
|
2200
|
+
if (checkNative("sonar")) {
|
|
2201
|
+
for (const url of sonarRepositoryUrls(provider, findings, report, "cloud"))
|
|
1228
2202
|
requireDestination("Sonar source", url);
|
|
1229
2203
|
}
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
2204
|
+
const checkmarx = checkmarxSelection(provider, findings, report, "cloud", historical);
|
|
2205
|
+
requireDestination("Checkmarx source", checkmarx.reportUrl);
|
|
2206
|
+
const blackDuck = checkNative("blackduck")
|
|
2207
|
+
? blackDuckReportRepositories(provider, findings, "cloud")
|
|
2208
|
+
: undefined;
|
|
2209
|
+
const checkmarxRepository = checkmarx.repositories();
|
|
2210
|
+
for (const [scanner, repositories] of [
|
|
1234
2211
|
["veracode", veracodeReportRepositories],
|
|
1235
2212
|
["continuum", continuumReportRepositories],
|
|
1236
2213
|
]) {
|
|
1237
|
-
if (
|
|
2214
|
+
if (!checkNative(scanner))
|
|
1238
2215
|
continue;
|
|
1239
|
-
for (const [id, source] of repositories(
|
|
2216
|
+
for (const [id, source] of repositories(provider, findings, "cloud"))
|
|
1240
2217
|
requireDestination(id, source.url);
|
|
1241
2218
|
}
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
options.provider === "veracode") {
|
|
1245
|
-
const binding = inspectorReportRepository(options.provider, findings, "cloud", inspectorProjectMap);
|
|
2219
|
+
if (checkNative("blackduck", "inspector", "veracode")) {
|
|
2220
|
+
const binding = inspectorReportRepository(provider, findings, "cloud", inspectorProjectMap);
|
|
1246
2221
|
if (binding)
|
|
1247
2222
|
requireDestination(binding.findingId, binding.url);
|
|
1248
2223
|
}
|
|
2224
|
+
const checkOnlyProjected = !checkNative("blackduck", "inspector", "veracode", "checkmarx", "continuum", "sonar");
|
|
1249
2225
|
for (const finding of findings) {
|
|
1250
2226
|
const { source_finding_id: id, evidence } = finding;
|
|
1251
|
-
const
|
|
1252
|
-
|
|
2227
|
+
const guardian = guardianFindingRepository(finding, "cloud");
|
|
2228
|
+
if (guardian) {
|
|
2229
|
+
requireDestination(id, guardian);
|
|
2230
|
+
requireDestination(id, evidence.details?.repository?.url);
|
|
2231
|
+
}
|
|
2232
|
+
checkRetainedTrivyProvider(provider, finding);
|
|
2233
|
+
if (trivyReportUrls) {
|
|
2234
|
+
const remote = trivyRepositoryUrl(retainedTrivyReport(finding), trivyTarget);
|
|
2235
|
+
if (remote)
|
|
2236
|
+
requireTrivyRemote(remote, id);
|
|
2237
|
+
}
|
|
2238
|
+
const blackDuckUrl = blackDuck
|
|
2239
|
+
? blackDuck.get(id)?.url
|
|
1253
2240
|
: projectedBlackDuckRepositoryUrl(finding, "cloud");
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
options.provider !== "inspector" &&
|
|
1257
|
-
options.provider !== "veracode" &&
|
|
1258
|
-
options.provider !== "continuum" &&
|
|
1259
|
-
options.provider !== "sonar")
|
|
2241
|
+
const hasProjection = !!blackDuckUrl || checkmarx.projections.has(finding);
|
|
2242
|
+
if (checkOnlyProjected && !hasProjection)
|
|
1260
2243
|
continue;
|
|
1261
|
-
|
|
1262
|
-
|
|
2244
|
+
let urls = [
|
|
2245
|
+
blackDuckUrl,
|
|
2246
|
+
checkmarxRepository(finding)?.url,
|
|
1263
2247
|
evidence.details?.repository?.url,
|
|
1264
|
-
options.provider === "wiz"
|
|
1265
|
-
? projected
|
|
1266
|
-
? wizFindingRepository(evidence, "cloud")?.url
|
|
1267
|
-
: wizCsvRepositoryUrl(evidence)
|
|
1268
|
-
: undefined,
|
|
1269
|
-
...(options.provider === "snyk"
|
|
1270
|
-
? snykRepositoryUrls(evidence.source_data, {
|
|
1271
|
-
cloudRepositoryUrl: destination.url,
|
|
1272
|
-
})
|
|
1273
|
-
: []),
|
|
1274
|
-
...(options.provider === "endor"
|
|
1275
|
-
? endorRepositoryUrls(evidence.source_data)
|
|
1276
|
-
: []),
|
|
1277
|
-
options.provider === "github"
|
|
1278
|
-
? dependabotRepository(finding)
|
|
1279
|
-
: undefined,
|
|
1280
2248
|
];
|
|
2249
|
+
if (provider === "wiz") {
|
|
2250
|
+
const native = hasProjection ||
|
|
2251
|
+
(!historical && isWizPackageFinding(evidence.source_data));
|
|
2252
|
+
urls.push(native
|
|
2253
|
+
? wizFindingRepository(evidence, "cloud")?.url
|
|
2254
|
+
: wizCsvRepositoryUrl(evidence));
|
|
2255
|
+
}
|
|
2256
|
+
else if (provider === "snyk") {
|
|
2257
|
+
urls = urls.concat(snykRepositoryUrls(evidence.source_data, {
|
|
2258
|
+
cloudRepositoryUrl: destination.url,
|
|
2259
|
+
}));
|
|
2260
|
+
}
|
|
2261
|
+
else if (provider === "endor") {
|
|
2262
|
+
urls = urls.concat(endorRepositoryUrls(evidence.source_data, !blackDuck && !blackDuckUrl));
|
|
2263
|
+
}
|
|
2264
|
+
else if (provider === "github") {
|
|
2265
|
+
if (!historical)
|
|
2266
|
+
urls.push(retainedGitHubRepository(finding));
|
|
2267
|
+
urls.push(dependabotRepository(finding));
|
|
2268
|
+
}
|
|
1281
2269
|
for (const url of urls)
|
|
1282
2270
|
requireDestination(id, url);
|
|
1283
2271
|
}
|
|
1284
2272
|
}
|
|
1285
|
-
|
|
2273
|
+
if (!saved) {
|
|
2274
|
+
for (const finding of parsed.findings) {
|
|
2275
|
+
if (options.provider !== "semgrep" &&
|
|
2276
|
+
isSemgrepPlatformEvidence(finding, options.provider))
|
|
2277
|
+
throw new CodexSecurityError("Semgrep Platform evidence requires the semgrep provider.");
|
|
2278
|
+
if (options.provider !== "snyk" && isSnykRestFinding(finding))
|
|
2279
|
+
throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
if (!usePrivateImport)
|
|
2283
|
+
checkRepositories(parsed);
|
|
1286
2284
|
// A retry sends its saved projection, which may differ from today's reader.
|
|
1287
2285
|
if (saved) {
|
|
1288
|
-
//
|
|
1289
|
-
// associated with the input digest in the saved checkpoint.
|
|
2286
|
+
// Only use the report associated with the input digest in the saved checkpoint.
|
|
1290
2287
|
const report = saved.inputProjection?.inputDigest === inputDigest
|
|
1291
2288
|
? parsed.report
|
|
1292
2289
|
: undefined;
|
|
1293
|
-
checkRepositories(submissionFindings(saved.requests), report);
|
|
2290
|
+
checkRepositories({ findings: submissionFindings(saved.requests), report });
|
|
1294
2291
|
}
|
|
1295
|
-
//
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
2292
|
+
// An older, genuinely unbound checkpoint first acquires a URL on a matching preview.
|
|
2293
|
+
// Retain it at the original path so its bare caller can still recover the same request.
|
|
2294
|
+
if (saved && !saved.approvedRepositoryUrl && hostedSource) {
|
|
2295
|
+
await underLocks(lockKeys, async () => {
|
|
2296
|
+
const serialized = await readOptionalFile(pendingPath);
|
|
2297
|
+
if (serialized === undefined)
|
|
2298
|
+
return;
|
|
2299
|
+
const current = validateSaved(JSON.parse(serialized));
|
|
2300
|
+
if (!sameSubmission(current, saved))
|
|
2301
|
+
throw new CodexSecurityError("Another publication prepared this input. Review the saved request again.");
|
|
2302
|
+
if (current.approvedRepositoryUrl) {
|
|
2303
|
+
requireApprovedSource(current.approvedRepositoryUrl, current.approvedRepositoryPlatform);
|
|
2304
|
+
}
|
|
2305
|
+
else {
|
|
2306
|
+
// Adding the catalog URL cannot erase an older SDK's same-selection hold.
|
|
2307
|
+
if (current.inputProjection &&
|
|
2308
|
+
originalHostedPending(current, current.wireKey ?? fileKey) ===
|
|
2309
|
+
"verified")
|
|
2310
|
+
current.inputProjection.retainedHostedSelection = true;
|
|
2311
|
+
current.approvedRepositoryUrl = approvedUrl;
|
|
2312
|
+
await writeAtomicJson(pendingPath, current);
|
|
2313
|
+
}
|
|
2314
|
+
saved.inputProjection = current.inputProjection;
|
|
2315
|
+
saved.approvedRepositoryUrl = current.approvedRepositoryUrl;
|
|
2316
|
+
saved.approvedRepositoryPlatform = current.approvedRepositoryPlatform;
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
if (usePrivateImport) {
|
|
2320
|
+
const client = privateClient;
|
|
2321
|
+
const { context, report, binding } = existingPrivate ?? (await preparePrivateAttempt());
|
|
2322
|
+
function requireAccess(value, saved) {
|
|
1324
2323
|
if (!value.can_read ||
|
|
1325
|
-
(!
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
!value
|
|
2324
|
+
(!saved && !canStartJob) ||
|
|
2325
|
+
(!saved?.jobId &&
|
|
2326
|
+
((!saved?.fileId && !value.can_upload) ||
|
|
2327
|
+
!acceptsJob(value, report.format))))
|
|
1329
2328
|
throw new CodexSecurityError("Private findings import is unavailable for this account or report format.");
|
|
1330
2329
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
context.can_upload &&
|
|
1334
|
-
context.can_create_import_jobs &&
|
|
1335
|
-
context.formats.includes(report.format)
|
|
1336
|
-
? previous?.jobId
|
|
1337
|
-
: undefined;
|
|
2330
|
+
checkRepositories(parsed, resumed);
|
|
2331
|
+
requireAccess(context, previous);
|
|
1338
2332
|
const privateImport = {
|
|
1339
2333
|
format: report.format,
|
|
1340
2334
|
contextVersion: binding.contextVersion,
|
|
@@ -1348,31 +2342,45 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1348
2342
|
accountId: credentials.account_id,
|
|
1349
2343
|
destination,
|
|
1350
2344
|
source,
|
|
1351
|
-
resumed
|
|
2345
|
+
resumed,
|
|
1352
2346
|
requests: [],
|
|
1353
2347
|
privateImport,
|
|
1354
2348
|
};
|
|
1355
2349
|
return {
|
|
1356
2350
|
preview: structuredClone(preview),
|
|
1357
|
-
publish: () =>
|
|
2351
|
+
publish: () => underPublishLocks(async () => {
|
|
1358
2352
|
const current = await client.context();
|
|
1359
2353
|
if (current.context_version !== binding.contextVersion)
|
|
1360
2354
|
throw new CodexSecurityError("The private inbox changed. Run the command again to review the new destination.");
|
|
1361
|
-
|
|
2355
|
+
await assertNoAlternateCheckpoint(async () => current);
|
|
2356
|
+
const stored = readPrivateCheckpoint(await readOptionalFile(privatePath), binding);
|
|
2357
|
+
if (!stored &&
|
|
2358
|
+
(resumingPreviousReader ||
|
|
2359
|
+
(privateUrl && privateUrl !== destination.url)))
|
|
2360
|
+
throw new CodexSecurityError("The saved private import changed. Run the command again to preview this report.");
|
|
1362
2361
|
// Only a preview of this terminal job can start a new attempt.
|
|
1363
2362
|
const retrying = retryOfJobId !== undefined && stored?.receipt?.id === retryOfJobId;
|
|
1364
2363
|
const active = retrying ? undefined : stored;
|
|
1365
|
-
|
|
2364
|
+
if (resumed && !active)
|
|
2365
|
+
checkRepositories(parsed);
|
|
2366
|
+
requireAccess(current, active);
|
|
1366
2367
|
if (await selectedCheckpoint())
|
|
1367
2368
|
throw new CodexSecurityError("A repository submission is pending. Review its saved request before continuing.");
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
2369
|
+
// Both routes share request IDs. A server upgrade can promote an
|
|
2370
|
+
// existing job, and its saved route also survives gate rollback.
|
|
2371
|
+
const checkpoint = {
|
|
2372
|
+
...(active ?? {
|
|
2373
|
+
...binding,
|
|
2374
|
+
approvedRepositoryUrl: destination.url,
|
|
2375
|
+
approvedRepositoryPlatform: hostedSource?.github === false ? "other" : undefined,
|
|
2376
|
+
uploadRequestId: randomUUID(),
|
|
2377
|
+
jobRequestId: randomUUID(),
|
|
2378
|
+
fileId: undefined,
|
|
2379
|
+
jobId: undefined,
|
|
2380
|
+
receipt: undefined,
|
|
2381
|
+
previousReceipt: retrying ? stored?.receipt : undefined,
|
|
2382
|
+
}),
|
|
2383
|
+
jobApiVersion: stored?.jobApiVersion ?? jobApiVersion,
|
|
1376
2384
|
};
|
|
1377
2385
|
const result = {
|
|
1378
2386
|
cloudApiUrl: preview.cloudApiUrl,
|
|
@@ -1412,7 +2420,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1412
2420
|
const savedReceipt = checkpoint.receipt ?? checkpoint.previousReceipt;
|
|
1413
2421
|
if (savedReceipt)
|
|
1414
2422
|
acknowledge(savedReceipt);
|
|
1415
|
-
if (!active)
|
|
2423
|
+
if (!active || active.jobApiVersion !== checkpoint.jobApiVersion)
|
|
1416
2424
|
await writeAtomicJson(privatePath, checkpoint);
|
|
1417
2425
|
if (!checkpoint.fileId) {
|
|
1418
2426
|
progress({ phase: "uploading", completed: 0 });
|
|
@@ -1433,6 +2441,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1433
2441
|
source,
|
|
1434
2442
|
repository: binding.repository,
|
|
1435
2443
|
jobId: checkpoint.jobId,
|
|
2444
|
+
jobApiVersion: checkpoint.jobApiVersion,
|
|
1436
2445
|
}, async (id) => {
|
|
1437
2446
|
checkpoint.jobId = id;
|
|
1438
2447
|
await writeAtomicJson(privatePath, checkpoint);
|
|
@@ -1453,15 +2462,22 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1453
2462
|
}),
|
|
1454
2463
|
};
|
|
1455
2464
|
}
|
|
2465
|
+
// The original selection and request bytes govern a retry even if discovery changes.
|
|
2466
|
+
const severities = saved
|
|
2467
|
+
? saved.inputProjection?.repositorySeverities
|
|
2468
|
+
: repositorySeverities;
|
|
2469
|
+
const direct = repositorySelection(parsed, severities, input.sourcePositions);
|
|
2470
|
+
if (!direct.findings.length)
|
|
2471
|
+
throw new NoPublishableFindingsError(direct);
|
|
1456
2472
|
let requests = saved?.requests;
|
|
1457
2473
|
if (!requests) {
|
|
1458
2474
|
let preparedCount = 0;
|
|
1459
2475
|
progress({
|
|
1460
2476
|
phase: "preparing",
|
|
1461
2477
|
completed: 0,
|
|
1462
|
-
total:
|
|
2478
|
+
total: direct.findings.length,
|
|
1463
2479
|
});
|
|
1464
|
-
const previousReports = await readInBatches(
|
|
2480
|
+
const previousReports = await readInBatches(direct.findings, async (finding) => {
|
|
1465
2481
|
const query = new URLSearchParams({
|
|
1466
2482
|
provider: source.provider,
|
|
1467
2483
|
source_key: source.source_key,
|
|
@@ -1482,14 +2498,14 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1482
2498
|
progress({
|
|
1483
2499
|
phase: "preparing",
|
|
1484
2500
|
completed: ++preparedCount,
|
|
1485
|
-
total:
|
|
2501
|
+
total: direct.findings.length,
|
|
1486
2502
|
});
|
|
1487
2503
|
return previous;
|
|
1488
2504
|
});
|
|
1489
2505
|
requests = [];
|
|
1490
2506
|
let current;
|
|
1491
2507
|
let currentBytes = 0;
|
|
1492
|
-
for (const [index, finding] of
|
|
2508
|
+
for (const [index, finding] of direct.findings.entries()) {
|
|
1493
2509
|
const previous = previousReports[index];
|
|
1494
2510
|
const environmentId = previous?.environment_id ?? destination.import_environment_id;
|
|
1495
2511
|
if (environmentId == null)
|
|
@@ -1531,22 +2547,40 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1531
2547
|
if (current)
|
|
1532
2548
|
requests.push(validateImportRequest(current));
|
|
1533
2549
|
}
|
|
2550
|
+
const bindSemgrepScope = !saved &&
|
|
2551
|
+
options.provider === "semgrep" &&
|
|
2552
|
+
report.findings.some((finding) => !isSemgrepPlatformEvidence(finding, "semgrep") &&
|
|
2553
|
+
(scopedSemgrepReport ||
|
|
2554
|
+
hasRetainedSemgrepScope(finding.evidence.source_data?.["finding"])));
|
|
1534
2555
|
const submission = {
|
|
1535
2556
|
accountId: credentials.account_id,
|
|
2557
|
+
...(trivyReportUrls && { trivyRepositoryUrl: trivyTarget }),
|
|
1536
2558
|
requests,
|
|
1537
2559
|
receipts: saved?.receipts,
|
|
1538
2560
|
legacyApproval: saved?.legacyApproval,
|
|
1539
2561
|
wireKey: saved?.wireKey ?? (fileKey === key ? undefined : key),
|
|
1540
2562
|
inputProjection: saved?.inputProjection ?? {
|
|
2563
|
+
...(direct !== parsed && { repositorySeverities: severities }),
|
|
1541
2564
|
identityFormat: saved ? undefined : 2,
|
|
2565
|
+
...(scopedSemgrepReport && { retainedHostedSelection: true }),
|
|
2566
|
+
...(bindSemgrepScope && {
|
|
2567
|
+
semgrepPartialScopeDigest: suppliedSemgrepScopeDigest(),
|
|
2568
|
+
}),
|
|
1542
2569
|
inputDigest,
|
|
1543
2570
|
savedEvidenceDigest: jsonDigest(submissionFindings(requests)),
|
|
1544
2571
|
},
|
|
1545
2572
|
};
|
|
2573
|
+
if (hosted &&
|
|
2574
|
+
(!saved || saved.approvedRepositoryUrl || matchesHostedRepository))
|
|
2575
|
+
submission.approvedRepositoryUrl =
|
|
2576
|
+
saved?.approvedRepositoryUrl ?? approvedUrl;
|
|
2577
|
+
if (saved?.approvedRepositoryPlatform ||
|
|
2578
|
+
(hostedSource && !hostedSource.github))
|
|
2579
|
+
submission.approvedRepositoryPlatform = "other";
|
|
1546
2580
|
if (inspectorProjectMap)
|
|
1547
2581
|
submission.inspectorProjectMapRequired = true;
|
|
1548
2582
|
const preview = {
|
|
1549
|
-
...
|
|
2583
|
+
...direct,
|
|
1550
2584
|
findings: submissionFindings(requests),
|
|
1551
2585
|
cloudApiUrl,
|
|
1552
2586
|
cloudUrl: cloudFindingsUrl(environment, destination.id),
|
|
@@ -1580,17 +2614,17 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1580
2614
|
return {
|
|
1581
2615
|
cloudApiUrl,
|
|
1582
2616
|
cloudUrl: preview.cloudUrl,
|
|
1583
|
-
status:
|
|
2617
|
+
status: direct.excluded.length || counts.error ? "partial" : "complete",
|
|
1584
2618
|
read: parsed.read,
|
|
1585
2619
|
...(parsed.report === undefined
|
|
1586
2620
|
? {}
|
|
1587
2621
|
: snapshotNormalizedFindings({ report: parsed.report })),
|
|
1588
|
-
ready:
|
|
1589
|
-
excluded:
|
|
2622
|
+
ready: direct.findings.length,
|
|
2623
|
+
excluded: direct.excluded,
|
|
1590
2624
|
receipts: acknowledged,
|
|
1591
2625
|
counts,
|
|
1592
2626
|
failures,
|
|
1593
|
-
unacknowledged:
|
|
2627
|
+
unacknowledged: direct.findings.length -
|
|
1594
2628
|
Object.values(counts).reduce((sum, count) => sum + count, 0),
|
|
1595
2629
|
verified,
|
|
1596
2630
|
};
|
|
@@ -1610,20 +2644,23 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1610
2644
|
}, cause);
|
|
1611
2645
|
}
|
|
1612
2646
|
let acquired = false;
|
|
1613
|
-
return await
|
|
2647
|
+
return await underPublishLocks(async () => {
|
|
1614
2648
|
acquired = true;
|
|
2649
|
+
await assertNoAlternateCheckpoint();
|
|
1615
2650
|
// Re-read under the lock to keep checkpoints from another publisher.
|
|
1616
2651
|
const selected = await selectedCheckpoint(saved ? fileKey : undefined).catch((error) => {
|
|
1617
2652
|
if (!submission.receipts?.length)
|
|
1618
2653
|
throw error;
|
|
1619
2654
|
throw interruptedPreview(errorMessage(error), error);
|
|
1620
2655
|
});
|
|
1621
|
-
|
|
2656
|
+
let pending = selected?.content;
|
|
1622
2657
|
const current = pending ?? submission;
|
|
1623
2658
|
const adoptProjectMap = submission.inspectorProjectMapRequired &&
|
|
1624
2659
|
current.inspectorProjectMapRequired === undefined;
|
|
1625
2660
|
if (adoptProjectMap)
|
|
1626
2661
|
current.inspectorProjectMapRequired = true;
|
|
2662
|
+
if (current.approvedRepositoryUrl)
|
|
2663
|
+
requireApprovedSource(current.approvedRepositoryUrl, current.approvedRepositoryPlatform);
|
|
1627
2664
|
if (!selected ||
|
|
1628
2665
|
selected.fileKey !== fileKey ||
|
|
1629
2666
|
selected.historical ||
|
|
@@ -1644,18 +2681,42 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1644
2681
|
if ((await readOptionalFile(pendingPath)) !== undefined)
|
|
1645
2682
|
throw occupiedCheckpoint();
|
|
1646
2683
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
2684
|
+
// A preview can pin the catalog URL. Tighten its SCM comparison only
|
|
2685
|
+
// once the caller confirms publication, including when resuming a request.
|
|
2686
|
+
const adoptStrictRepository = submission.approvedRepositoryPlatform === "other" &&
|
|
2687
|
+
!current.approvedRepositoryPlatform;
|
|
2688
|
+
if (adoptStrictRepository)
|
|
2689
|
+
current.approvedRepositoryPlatform = "other";
|
|
2690
|
+
const cached = (current.receipts ?? []).map(validateImportReceipt);
|
|
2691
|
+
if (cached.length > requests.length)
|
|
1649
2692
|
throw new CodexSecurityError("Saved publication has more receipts than requests.");
|
|
1650
2693
|
const acknowledged = [];
|
|
1651
2694
|
let verified = 0;
|
|
1652
|
-
let persisted = pending !== undefined;
|
|
1653
2695
|
try {
|
|
1654
2696
|
if (selected?.checkedCanonical)
|
|
1655
2697
|
current.canonicalChecked = true;
|
|
1656
|
-
if (pending === undefined
|
|
2698
|
+
if (pending === undefined) {
|
|
2699
|
+
await withSourceAdmission(async () => {
|
|
2700
|
+
if (hosted) {
|
|
2701
|
+
for (const otherKey of new Set([
|
|
2702
|
+
...projectionKeys,
|
|
2703
|
+
...legacyKeys,
|
|
2704
|
+
])) {
|
|
2705
|
+
if (otherKey !== key &&
|
|
2706
|
+
otherKey !== fileKey &&
|
|
2707
|
+
(await readOptionalFile(pendingFile(otherKey))) !==
|
|
2708
|
+
undefined)
|
|
2709
|
+
throw new CodexSecurityError("Another publication prepared this input. Run the command again to review and resume that saved request.");
|
|
2710
|
+
}
|
|
2711
|
+
if (await selectedCheckpoint())
|
|
2712
|
+
throw new CodexSecurityError("Another publication prepared this input. Run the command again to review and resume that saved request.");
|
|
2713
|
+
}
|
|
2714
|
+
await writeAtomicJson(pendingPath, current);
|
|
2715
|
+
});
|
|
2716
|
+
pending = current;
|
|
2717
|
+
}
|
|
2718
|
+
else if (adoptProjectMap || adoptStrictRepository) {
|
|
1657
2719
|
await writeAtomicJson(pendingPath, current);
|
|
1658
|
-
persisted = true;
|
|
1659
2720
|
}
|
|
1660
2721
|
else if (selected?.checkedCanonical) {
|
|
1661
2722
|
// The existing approval and receipts are usable if caching the scan fails.
|
|
@@ -1665,33 +2726,32 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1665
2726
|
progress({
|
|
1666
2727
|
phase: "uploading",
|
|
1667
2728
|
completed: 0,
|
|
1668
|
-
total:
|
|
2729
|
+
total: direct.findings.length,
|
|
1669
2730
|
});
|
|
1670
2731
|
let acknowledgedCount = 0;
|
|
1671
2732
|
for (const [batchIndex, batch] of requests.entries()) {
|
|
1672
|
-
const receipt = validatePublicationReceipt(
|
|
2733
|
+
const receipt = validatePublicationReceipt(cached[batchIndex] ??
|
|
1673
2734
|
(await request(`${importPrefix}/finding_imports`, batch)), batch);
|
|
1674
2735
|
acknowledged.push(receipt);
|
|
1675
2736
|
acknowledgedCount += receipt.item_count;
|
|
1676
2737
|
progress({
|
|
1677
2738
|
phase: "uploading",
|
|
1678
2739
|
completed: acknowledgedCount,
|
|
1679
|
-
total:
|
|
2740
|
+
total: direct.findings.length,
|
|
1680
2741
|
});
|
|
1681
|
-
if (batchIndex
|
|
1682
|
-
receipts.push(receipt);
|
|
2742
|
+
if (batchIndex >= cached.length) {
|
|
1683
2743
|
// Acknowledged batches must not consume another POST quota on retry.
|
|
1684
2744
|
// Readback can still resume after this checkpoint without replaying writes.
|
|
1685
2745
|
await writeAtomicJson(pendingPath, {
|
|
1686
2746
|
...submission,
|
|
1687
2747
|
canonicalChecked: current.canonicalChecked,
|
|
1688
|
-
receipts,
|
|
2748
|
+
receipts: acknowledged,
|
|
1689
2749
|
});
|
|
1690
2750
|
}
|
|
1691
2751
|
}
|
|
1692
2752
|
// Verify readable source records without mistaking a newer concurrent
|
|
1693
2753
|
// observation for failure of the original, immutable import receipt.
|
|
1694
|
-
const readbacks =
|
|
2754
|
+
const readbacks = acknowledged.flatMap((receipt, batchIndex) => {
|
|
1695
2755
|
const batch = requests[batchIndex];
|
|
1696
2756
|
const batchItems = new Map(batch.items.map((item) => [item.client_id, item]));
|
|
1697
2757
|
return receipt.results
|
|
@@ -1714,7 +2774,7 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1714
2774
|
report.version < item.version ||
|
|
1715
2775
|
(report.version === item.version &&
|
|
1716
2776
|
(report.observation_id !== item.observation_id ||
|
|
1717
|
-
|
|
2777
|
+
!matchesRepositoryEvidence(expected.evidence, report.evidence))) ||
|
|
1718
2778
|
report.source_finding_id !== expected.source_finding_id ||
|
|
1719
2779
|
report.repo_id !== destination.id ||
|
|
1720
2780
|
report.repo_connector_id !== destination.repo_connector_id ||
|
|
@@ -1738,14 +2798,14 @@ async function preparePublicationInput(input, options, dependencies, nativePath)
|
|
|
1738
2798
|
catch (error) {
|
|
1739
2799
|
if (error instanceof CloudImportError && error.status === 409) {
|
|
1740
2800
|
await removePending();
|
|
1741
|
-
|
|
2801
|
+
pending = undefined;
|
|
1742
2802
|
}
|
|
1743
|
-
const message = `${error instanceof Error ? error.message : String(error)} ${error instanceof CloudImportError && error.status === 409 ? "The old submission was retired. Rediscover and approve a fresh publication." :
|
|
2803
|
+
const message = `${error instanceof Error ? error.message : String(error)} ${error instanceof CloudImportError && error.status === 409 ? "The old submission was retired. Rediscover and approve a fresh publication." : pending ? `Repeat the same command to resume the saved request. Saved submission: ${pendingPath}` : "No resumable request was saved. Correct the error and review the input before retrying."}`;
|
|
1744
2804
|
throw new ExternalPublicationError(message, {
|
|
1745
2805
|
...result(acknowledged, verified),
|
|
1746
2806
|
status: "interrupted",
|
|
1747
2807
|
error: message,
|
|
1748
|
-
...(
|
|
2808
|
+
...(pending ? { savedSubmission: pendingPath } : {}),
|
|
1749
2809
|
}, error);
|
|
1750
2810
|
}
|
|
1751
2811
|
}).catch((error) => {
|