@openai/codex-security 0.9.1 → 0.10.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 +37 -788
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +3 -0
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/references/access-advisory.md +1 -1
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/baseline-auditor.md +18 -0
- package/_bundled_plugin/references/core-scan.md +5 -42
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/focused-investigator.md +13 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -2
- package/_bundled_plugin/references/scan-runtime.md +4 -2
- package/_bundled_plugin/references/security-guidance.md +14 -1
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/references/validate-scan-findings.md +3 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +30 -12
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +47 -9
- package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
- package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
- package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
- package/_bundled_plugin/scripts/workbench/storage.py +25 -5
- package/_bundled_plugin/scripts/workbench_cli.py +24 -2
- package/_bundled_plugin/scripts/workbench_constants.py +2 -0
- package/_bundled_plugin/scripts/workbench_db.py +257 -268
- package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
- package/_bundled_plugin/scripts/workbench_progress.py +159 -3
- package/_bundled_plugin/scripts/workbench_publication.py +2 -3
- package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
- package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
- package/_bundled_plugin/scripts/workbench_scan_history.py +291 -134
- package/_bundled_plugin/scripts/workbench_scan_start.py +208 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
- package/_bundled_plugin/scripts/workbench_schema.py +220 -14
- package/_bundled_plugin/scripts/workbench_setup.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
- package/_bundled_plugin/scripts/workbench_target.py +486 -85
- package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
- package/_bundled_plugin/shared/workbench-history-repairs.json +64 -14
- package/_bundled_plugin/shared/workbench-migrations.json +66 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
- package/_bundled_plugin/skills/publish-findings/SKILL.md +26 -160
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
- package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
- package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
- package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
- package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
- package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
- package/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +459 -157
- package/dist/api.js.map +1 -1
- package/dist/armorcode-findings.d.ts +9 -0
- package/dist/armorcode-findings.d.ts.map +1 -0
- package/dist/armorcode-findings.js +145 -0
- package/dist/armorcode-findings.js.map +1 -0
- package/dist/artifact-export.d.ts +2 -0
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +29 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +6 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +33 -12
- package/dist/auth.js.map +1 -1
- package/dist/batch-cost.d.ts +18 -0
- package/dist/batch-cost.d.ts.map +1 -0
- package/dist/batch-cost.js +41 -0
- package/dist/batch-cost.js.map +1 -0
- package/dist/blackduck-findings.d.ts +1 -1
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +5 -18
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bundled-plugin.d.ts +4 -0
- package/dist/bundled-plugin.d.ts.map +1 -0
- package/dist/bundled-plugin.js +23 -0
- package/dist/bundled-plugin.js.map +1 -0
- package/dist/classify-scan-severity.d.ts +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +11 -3
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity-diagnostics.d.ts +10 -0
- package/dist/classify-severity-diagnostics.d.ts.map +1 -0
- package/dist/classify-severity-diagnostics.js +57 -0
- package/dist/classify-severity-diagnostics.js.map +1 -0
- package/dist/classify-severity-records.d.ts +4 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +35 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +9 -6
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-argument.d.ts +4 -0
- package/dist/cli-argument.d.ts.map +1 -0
- package/dist/cli-argument.js +17 -0
- package/dist/cli-argument.js.map +1 -0
- package/dist/cli-help.d.ts +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +71 -29
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-hook.d.ts +3 -0
- package/dist/cli-hook.d.ts.map +1 -0
- package/dist/cli-hook.js +87 -0
- package/dist/cli-hook.js.map +1 -0
- package/dist/cli-integrations.d.ts +13 -0
- package/dist/cli-integrations.d.ts.map +1 -0
- package/dist/cli-integrations.js +333 -0
- package/dist/cli-integrations.js.map +1 -0
- package/dist/cli-mcp.d.ts +15 -0
- package/dist/cli-mcp.d.ts.map +1 -0
- package/dist/cli-mcp.js +178 -0
- package/dist/cli-mcp.js.map +1 -0
- package/dist/cli-token-view.d.ts +10 -0
- package/dist/cli-token-view.d.ts.map +1 -0
- package/dist/cli-token-view.js +41 -0
- package/dist/cli-token-view.js.map +1 -0
- package/dist/cli.d.ts +8 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1860 -903
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +33 -31
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +6 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +19 -0
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/command-words.d.ts +3 -0
- package/dist/command-words.d.ts.map +1 -0
- package/dist/command-words.js +46 -0
- package/dist/command-words.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +3 -3
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +3 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +40 -7
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +30 -1
- package/dist/config.js.map +1 -1
- package/dist/continuum-aws.d.ts +6 -0
- package/dist/continuum-aws.d.ts.map +1 -0
- package/dist/continuum-aws.js +202 -0
- package/dist/continuum-aws.js.map +1 -0
- package/dist/continuum-collector.d.ts +44 -0
- package/dist/continuum-collector.d.ts.map +1 -0
- package/dist/continuum-collector.js +266 -0
- package/dist/continuum-collector.js.map +1 -0
- package/dist/continuum-findings.d.ts +31 -2
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +497 -59
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -0
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +1 -45
- package/dist/cost.js.map +1 -1
- package/dist/crowdstrike-findings.d.ts +7 -0
- package/dist/crowdstrike-findings.d.ts.map +1 -0
- package/dist/crowdstrike-findings.js +210 -0
- package/dist/crowdstrike-findings.js.map +1 -0
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +29 -19
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/local.d.ts +3 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +8 -1
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +2 -1
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +16 -15
- package/dist/deep-scan.js.map +1 -1
- package/dist/endor-findings.d.ts +2 -2
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +6 -23
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -3
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +3 -0
- package/dist/executable-path.d.ts.map +1 -1
- package/dist/executable-path.js +26 -0
- package/dist/executable-path.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +12 -1
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +66 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +258 -59
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +6 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +330 -1633
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +11 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +56 -53
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +1 -1
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +12 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +6 -11
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +35 -177
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-prompt.d.ts.map +1 -1
- package/dist/finding-prompt.js +2 -2
- package/dist/finding-prompt.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +3 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +19 -287
- package/dist/github-findings.js.map +1 -1
- package/dist/host-protocol.d.ts +6 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +11 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +2 -0
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +4 -0
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-remediation.d.ts +1 -0
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +23 -3
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +19 -35
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +34 -27
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts +11 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -2
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +8 -4
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +4 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +83 -39
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts +4 -2
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +39 -22
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/private-finding-import.d.ts +8 -13
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +69 -129
- package/dist/private-finding-import.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +56 -13
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +7 -2
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +42 -20
- package/dist/prompt-files.js.map +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +4 -9
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.d.ts +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js.map +1 -1
- package/dist/record.d.ts +1 -5
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +3 -51
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -1
- package/dist/remediation.js.map +1 -1
- package/dist/runtime.d.ts +35 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +782 -153
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +6 -1
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +267 -115
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-archive-path.d.ts +2 -0
- package/dist/scan-archive-path.d.ts.map +1 -0
- package/dist/scan-archive-path.js +5 -0
- package/dist/scan-archive-path.js.map +1 -0
- package/dist/scan-comparison.d.ts +20 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +26 -5
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +18 -2
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +4 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +25 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +28 -4
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +5 -11
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +16 -89
- package/dist/scanner-import.js.map +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +26 -6
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +14 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +20 -70
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +116 -333
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +1 -0
- package/dist/severity-review.js.map +1 -1
- package/dist/snyk-findings.d.ts +2 -0
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +5 -8
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +3 -20
- package/dist/snyk-rest-findings.d.ts.map +1 -1
- package/dist/snyk-rest-findings.js +45 -217
- package/dist/snyk-rest-findings.js.map +1 -1
- package/dist/sonar-findings.d.ts +1 -1
- package/dist/sonar-findings.d.ts.map +1 -1
- package/dist/sonar-findings.js +2 -4
- package/dist/sonar-findings.js.map +1 -1
- package/dist/sonar-import.d.ts +3 -0
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +28 -30
- package/dist/sonar-import.js.map +1 -1
- package/dist/stored-finding-projection.d.ts +6 -0
- package/dist/stored-finding-projection.d.ts.map +1 -0
- package/dist/stored-finding-projection.js +129 -0
- package/dist/stored-finding-projection.js.map +1 -0
- package/dist/stored-findings-publication.d.ts +23 -0
- package/dist/stored-findings-publication.d.ts.map +1 -0
- package/dist/stored-findings-publication.js +169 -0
- package/dist/stored-findings-publication.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +103 -23
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +1 -4
- package/dist/tenable-findings.d.ts.map +1 -1
- package/dist/tenable-findings.js.map +1 -1
- package/dist/trivy-findings.d.ts.map +1 -1
- package/dist/trivy-findings.js +0 -11
- package/dist/trivy-findings.js.map +1 -1
- package/dist/trusted-executable.d.ts +7 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +148 -37
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.js +3 -1
- package/dist/value.js.map +1 -1
- package/dist/veracode-findings.d.ts +1 -3
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +13 -38
- package/dist/veracode-findings.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +184 -32
- package/dist/version.js.map +1 -1
- package/dist/wiz-findings.d.ts +2 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +14 -92
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +30 -0
- package/docs/cli.md +537 -124
- package/docs/findings-service.md +22 -9
- package/docs/hosted-remediation.md +13 -4
- package/docs/sdk.md +918 -0
- package/package.json +15 -6
- package/schemas/external-findings.schema.json +2 -1
- package/schemas/project-config.schema.json +5 -0
- package/dist/hosted-scanner-v1.d.ts +0 -6
- package/dist/hosted-scanner-v1.d.ts.map +0 -1
- package/dist/hosted-scanner-v1.js +0 -60
- package/dist/hosted-scanner-v1.js.map +0 -1
- package/dist/reader-selection.d.ts +0 -15
- package/dist/reader-selection.d.ts.map +0 -1
- package/dist/reader-selection.js +0 -89
- package/dist/reader-selection.js.map +0 -1
- package/dist/semgrep-platform-v1.d.ts +0 -6
- package/dist/semgrep-platform-v1.d.ts.map +0 -1
- package/dist/semgrep-platform-v1.js +0 -83
- package/dist/semgrep-platform-v1.js.map +0 -1
- package/dist/snyk-rest-v1.d.ts +0 -28
- package/dist/snyk-rest-v1.d.ts.map +0 -1
- package/dist/snyk-rest-v1.js +0 -132
- package/dist/snyk-rest-v1.js.map +0 -1
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
import { readScannerJson } from "./scanner-import.js";
|
|
1
2
|
import { hash, randomUUID } from "node:crypto";
|
|
2
3
|
import { chmodSync } from "node:fs";
|
|
3
|
-
import { lstat, mkdir, open, readFile,
|
|
4
|
+
import { lstat, mkdir, open, readFile, rename, rm } from "node:fs/promises";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { nullIfMissingFile } from "./targets.js";
|
|
6
7
|
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
-
import {
|
|
8
|
+
import { isProxy } from "node:util/types";
|
|
8
9
|
import { privateImportClient, privateJobVersions, selectPrivateReport, readPrivateCheckpoint, parsePrivateCheckpoint, unsuccessfulJob, } from "./private-finding-import.js";
|
|
9
10
|
import { readCloudCredentials } from "./cloud-publish.js";
|
|
11
|
+
import { armorCodeRepositoryUrl } from "./armorcode-findings.js";
|
|
10
12
|
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
11
13
|
import { tenableReportFormat } from "./tenable-findings.js";
|
|
14
|
+
import { crowdstrikeReportFormat } from "./crowdstrike-findings.js";
|
|
12
15
|
import { guardianFindingId, guardianFindingRepository, guardianSelectionFormat, } from "./semgrep-guardian-findings.js";
|
|
13
|
-
import { cloudBaseUrl, cloudFindingsUrl
|
|
16
|
+
import { cloudBaseUrl, cloudFindingsUrl } from "./cloud-endpoint.js";
|
|
14
17
|
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
15
18
|
import { codexSecurityStateDirectory, createWindowsOutputDirectory, validatePreparedOutputDir, sqliteDatabaseOpener, } from "./runtime.js";
|
|
16
19
|
import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, requireCloudReader, semgrepSarifRepositories, snykFileRepositories, } from "./external-findings-read.js";
|
|
17
|
-
import {
|
|
20
|
+
import { canonicalJson, isRecord } from "./record.js";
|
|
18
21
|
import { notify } from "./value.js";
|
|
19
22
|
import { wizCsvRepositoryUrl } from "./wiz-csv.js";
|
|
20
23
|
import { isWizPackageFinding, wizFindingRepository } from "./wiz-findings.js";
|
|
21
24
|
import { getOpenGrepSourcePositions } from "./opengrep-findings.js";
|
|
22
|
-
import { previousReaderSelection, hasPreviousCloudProjection, } from "./reader-selection.js";
|
|
23
25
|
import { dependabotRepository } from "./github-dependabot-findings.js";
|
|
24
26
|
import { retainedGitHubRepository } from "./github-findings.js";
|
|
25
|
-
import {
|
|
26
|
-
import { normalizeSnykFile,
|
|
27
|
-
import { isSnykRestFinding, isSnykRestFormat,
|
|
28
|
-
import { hasRetainedSemgrepScope, isSemgrepPlatformEvidence, isSemgrepPlatformFormat, semgrepPlatformFormat,
|
|
29
|
-
import { semgrepV1Id } from "./semgrep-platform-v1.js";
|
|
27
|
+
import { normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
|
|
28
|
+
import { normalizeSnykFile, snykRepositoryUrls } from "./snyk-findings.js";
|
|
29
|
+
import { isSnykRestFinding, isSnykRestFormat, snykRestImportRepository, snykRestRepositoryMatches, } from "./snyk-rest-findings.js";
|
|
30
|
+
import { hasRetainedSemgrepScope, isSemgrepPlatformEvidence, isSemgrepPlatformFormat, semgrepPlatformFormat, semgrepPlatformFindingBinding, semgrepPlatformRepositoryReference, semgrepPlatformReportScope, } from "./semgrep-platform-findings.js";
|
|
30
31
|
import { hostedRepositoryUrlKey, normalizeHostedGitRepositoryUrl, } from "./hosted-git-repository.js";
|
|
31
32
|
import { trivyRemoteKey, trivyRepositoryUrl } from "./trivy-findings.js";
|
|
32
33
|
import { hostedRepositoryUrl } from "./hosted-scanner-http.js";
|
|
33
|
-
import { endorRepositoryUrls
|
|
34
|
+
import { endorRepositoryUrls } from "./endor-findings.js";
|
|
34
35
|
import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
|
|
35
36
|
import { checkmarxSelection } from "./checkmarx-repository.js";
|
|
36
37
|
import { continuumReportRepositories } from "./continuum-findings.js";
|
|
@@ -38,8 +39,8 @@ import { veracodeReportRepositories } from "./veracode-findings.js";
|
|
|
38
39
|
import { inspectorReportRepository } from "./inspector-findings.js";
|
|
39
40
|
import { sonarRepositoryUrls } from "./sonar-findings.js";
|
|
40
41
|
import { checkRetainedTrivyProvider, checkTrivyReportProvider, isTrivyReportHeader, retainedTrivyReport, trivyBatchSourceUrls, validateTrivyRepositoryUrl, } from "./trivy-import.js";
|
|
41
|
-
import { NoPublishableFindingsError, reportForJson, snapshotSourceRepositories, snapshotImportOptions, cloneImportPreview,
|
|
42
|
-
import { canonicalNumber, cloudRepositoryUrlKey,
|
|
42
|
+
import { NoPublishableFindingsError, reportForJson, snapshotSourceRepositories, snapshotImportOptions, cloneImportPreview, snapshotNormalizedFindings, } from "./external-findings.js";
|
|
43
|
+
import { canonicalNumber, cloudRepositoryUrlKey, validateImportRequest, validateExternalEvidence, validateExternalReport, validateImportReceipt, validateRepositories, validateSourceReports, validateSourceReport, } from "./external-import-contract.js";
|
|
43
44
|
const MAX_REQUEST_BYTES = 5 * 1024 * 1024;
|
|
44
45
|
/** Preserve accepted work in CLI JSON output when publication cannot finish. */
|
|
45
46
|
export class ExternalPublicationError extends CodexSecurityError {
|
|
@@ -49,6 +50,27 @@ export class ExternalPublicationError extends CodexSecurityError {
|
|
|
49
50
|
this.result = result;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
/** Bind reviewed evidence to its account, repository, connector and destination version. */
|
|
54
|
+
export function cloudReviewDigest(preview, checkout, findings) {
|
|
55
|
+
return hash("sha256", canonicalJson({
|
|
56
|
+
checkout,
|
|
57
|
+
api: preview.cloudApiUrl,
|
|
58
|
+
account: preview.accountId,
|
|
59
|
+
repository: preview.destination.id,
|
|
60
|
+
connector: preview.destination.repo_connector_id,
|
|
61
|
+
url: preview.destination.url,
|
|
62
|
+
reset: preview.destination.reset_marker,
|
|
63
|
+
source: preview.source,
|
|
64
|
+
privateImport: preview.privateImport,
|
|
65
|
+
...(findings && { findings, excluded: preview.excluded }),
|
|
66
|
+
items: preview.requests.flatMap((request) => request.items.map((item) => [
|
|
67
|
+
item.source_finding_id,
|
|
68
|
+
item.expected_version,
|
|
69
|
+
request.repository.environment_id,
|
|
70
|
+
item.evidence,
|
|
71
|
+
])),
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
52
74
|
// Limit read concurrency to avoid one network round trip per finding in series.
|
|
53
75
|
// Wait for the entire batch on failure so callers never outlive their read tasks.
|
|
54
76
|
async function readInBatches(items, read) {
|
|
@@ -63,17 +85,9 @@ async function readInBatches(items, read) {
|
|
|
63
85
|
}
|
|
64
86
|
return output;
|
|
65
87
|
}
|
|
66
|
-
// JSON.stringify serializes boxed primitives after the replacer. Let it
|
|
67
|
-
// produce their actual wire values, including false and strings.
|
|
68
|
-
function wireJson(value) {
|
|
69
|
-
return canonicalJson(value, undefined, isBoxedPrimitive);
|
|
70
|
-
}
|
|
71
|
-
function jsonDigest(value, serialize = wireJson) {
|
|
72
|
-
return hash("sha256", serialize(value));
|
|
73
|
-
}
|
|
74
88
|
function matchesRepositoryEvidence(expected, stored) {
|
|
75
|
-
const storedWire =
|
|
76
|
-
if (
|
|
89
|
+
const storedWire = canonicalJson(stored);
|
|
90
|
+
if (canonicalJson(expected) === storedWire)
|
|
77
91
|
return true;
|
|
78
92
|
// A repository can store a literal first-component colon with an explicit
|
|
79
93
|
// relative prefix. Match only that spelling in typed locations and their manifests.
|
|
@@ -92,7 +106,7 @@ function matchesRepositoryEvidence(expected, stored) {
|
|
|
92
106
|
const path = item.manifest_path && qualified.get(item.manifest_path);
|
|
93
107
|
return path ? { ...item, manifest_path: path } : item;
|
|
94
108
|
});
|
|
95
|
-
return
|
|
109
|
+
return canonicalJson({ ...expected, locations, packages }) === storedWire;
|
|
96
110
|
}
|
|
97
111
|
function isCompleteUnscoredOpenGrepReport(report) {
|
|
98
112
|
let rows = report.excluded.length;
|
|
@@ -159,7 +173,7 @@ function sameSubmission(left, right) {
|
|
|
159
173
|
return (left.accountId === right.accountId &&
|
|
160
174
|
left.trivyRepositoryUrl === right.trivyRepositoryUrl &&
|
|
161
175
|
left.inspectorProjectMapRequired === right.inspectorProjectMapRequired &&
|
|
162
|
-
|
|
176
|
+
canonicalJson(left.requests) === canonicalJson(right.requests));
|
|
163
177
|
}
|
|
164
178
|
function wireFinding({ source_finding_id, evidence, }) {
|
|
165
179
|
return { source_finding_id, evidence };
|
|
@@ -167,36 +181,6 @@ function wireFinding({ source_finding_id, evidence, }) {
|
|
|
167
181
|
function submissionFindings(requests) {
|
|
168
182
|
return requests.flatMap((batch) => batch.items.map(wireFinding));
|
|
169
183
|
}
|
|
170
|
-
function sameLegacyJson(saved, current, equivalent) {
|
|
171
|
-
if (saved === current || equivalent(saved, current))
|
|
172
|
-
return true;
|
|
173
|
-
if (Array.isArray(saved) && Array.isArray(current))
|
|
174
|
-
return (saved.length === current.length &&
|
|
175
|
-
saved.every((child, i) => sameLegacyJson(child, current[i], equivalent)));
|
|
176
|
-
if (!isRecord(saved) || !isRecord(current))
|
|
177
|
-
return false;
|
|
178
|
-
return (Object.keys(current).every((key) => Object.hasOwn(saved, key)) &&
|
|
179
|
-
Object.keys(saved).every((key) => sameLegacyJson(saved[key], current[key], equivalent)));
|
|
180
|
-
}
|
|
181
|
-
// A copied reader result can retain the JSON from Buffer.toJSON but lose
|
|
182
|
-
// the native Buffer that the previous reader cloned into a Uint8Array.
|
|
183
|
-
function previousBufferJson(saved, current) {
|
|
184
|
-
if (!isRecord(current) ||
|
|
185
|
-
current["type"] !== "Buffer" ||
|
|
186
|
-
!Array.isArray(current["data"]))
|
|
187
|
-
return false;
|
|
188
|
-
return (isRecord(saved) &&
|
|
189
|
-
Object.keys(current).length === 2 &&
|
|
190
|
-
Object.keys(saved).length === current["data"].length &&
|
|
191
|
-
current["data"].every((byte, index) => Number.isInteger(byte) &&
|
|
192
|
-
byte >= 0 &&
|
|
193
|
-
byte <= 255 &&
|
|
194
|
-
saved[index] === byte));
|
|
195
|
-
}
|
|
196
|
-
function sameFindingSelection(left, right) {
|
|
197
|
-
return (left.length === right.length &&
|
|
198
|
-
left.every((finding, index) => finding.source_finding_id === right[index].source_finding_id));
|
|
199
|
-
}
|
|
200
184
|
async function readOptionalFile(path) {
|
|
201
185
|
return (await readFile(path, "utf8").catch(nullIfMissingFile)) ?? undefined;
|
|
202
186
|
}
|
|
@@ -234,8 +218,8 @@ function validatePublicationReceipt(value, batch) {
|
|
|
234
218
|
const receipt = validateImportReceipt(value);
|
|
235
219
|
const remaining = new Set(batch.items.map((item) => item.client_id));
|
|
236
220
|
if (receipt.id !== batch.request_id ||
|
|
237
|
-
|
|
238
|
-
|
|
221
|
+
canonicalJson(receipt.repository) !== canonicalJson(batch.repository) ||
|
|
222
|
+
canonicalJson(receipt.source) !== canonicalJson(batch.source) ||
|
|
239
223
|
receipt.item_count !== batch.items.length ||
|
|
240
224
|
receipt.results.length !== batch.items.length ||
|
|
241
225
|
receipt.results.some((item) => !remaining.delete(item.client_id)))
|
|
@@ -258,56 +242,47 @@ function validatePublicationReceipt(value, batch) {
|
|
|
258
242
|
result.version === null)
|
|
259
243
|
throw new CodexSecurityError("Cloud returned an incomplete saved finding.");
|
|
260
244
|
}
|
|
261
|
-
if (
|
|
245
|
+
if (canonicalJson(receipt.counts) !== canonicalJson(actual))
|
|
262
246
|
throw new CodexSecurityError("Cloud returned inconsistent publication counts.");
|
|
263
247
|
return receipt;
|
|
264
248
|
}
|
|
265
|
-
|
|
249
|
+
function acknowledgedReceipts({ receipts = [], requests }) {
|
|
250
|
+
if (receipts.length > requests.length)
|
|
251
|
+
throw new CodexSecurityError("Saved publication has more receipts than requests.");
|
|
252
|
+
return receipts.map((receipt, index) => validatePublicationReceipt(receipt, requests[index]));
|
|
253
|
+
}
|
|
254
|
+
async function withImportLock(state, key, signal, operation) {
|
|
266
255
|
if (process.platform === "win32")
|
|
267
256
|
await createWindowsOutputDirectory(state, true);
|
|
268
257
|
else
|
|
269
258
|
await mkdir(state, { recursive: true, mode: 0o700 });
|
|
270
259
|
await validatePreparedOutputDir(state, undefined, true);
|
|
271
|
-
const
|
|
272
|
-
const
|
|
260
|
+
const path = join(state, key + ".lock.sqlite");
|
|
261
|
+
const metadata = await lstat(path).catch(nullIfMissingFile);
|
|
262
|
+
if (metadata && !metadata.isFile())
|
|
263
|
+
throw new CodexSecurityError("The publication lock is not a regular file.");
|
|
264
|
+
const guard = sqliteDatabaseOpener()(path);
|
|
273
265
|
try {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (metadata && !metadata.isFile())
|
|
278
|
-
throw new CodexSecurityError("The publication lock is not a regular file.");
|
|
279
|
-
const guard = openDatabase(path);
|
|
280
|
-
guards.push(guard);
|
|
281
|
-
if (process.platform !== "win32")
|
|
282
|
-
chmodSync(path, 0o600);
|
|
283
|
-
guard.exec("PRAGMA busy_timeout = 0");
|
|
284
|
-
}
|
|
266
|
+
if (process.platform !== "win32")
|
|
267
|
+
chmodSync(path, 0o600);
|
|
268
|
+
guard.exec("PRAGMA busy_timeout = 0");
|
|
285
269
|
for (;;) {
|
|
286
270
|
signal?.throwIfAborted();
|
|
287
|
-
let acquired = 0;
|
|
288
271
|
try {
|
|
289
|
-
|
|
290
|
-
for (const guard of guards) {
|
|
291
|
-
guard.exec("BEGIN EXCLUSIVE");
|
|
292
|
-
acquired++;
|
|
293
|
-
}
|
|
272
|
+
guard.exec("BEGIN EXCLUSIVE");
|
|
294
273
|
break;
|
|
295
274
|
}
|
|
296
275
|
catch (error) {
|
|
297
276
|
const sqliteError = error;
|
|
298
277
|
if (sqliteError.errcode !== 5 && sqliteError.code !== "SQLITE_BUSY")
|
|
299
278
|
throw error;
|
|
300
|
-
// Older SDKs can acquire historical keys in a different order.
|
|
301
|
-
for (const guard of guards.slice(0, acquired))
|
|
302
|
-
guard.exec("ROLLBACK");
|
|
303
279
|
await delay(50, undefined, { signal });
|
|
304
280
|
}
|
|
305
281
|
}
|
|
306
282
|
return await operation();
|
|
307
283
|
}
|
|
308
284
|
finally {
|
|
309
|
-
|
|
310
|
-
guard.close();
|
|
285
|
+
guard.close();
|
|
311
286
|
}
|
|
312
287
|
}
|
|
313
288
|
function hostedSourceReferences(readerSources, url, sourcePlatform) {
|
|
@@ -319,36 +294,20 @@ function hostedSourceReferences(readerSources, url, sourcePlatform) {
|
|
|
319
294
|
? sources.filter(({ platform }) => platform !== "github")
|
|
320
295
|
: sources;
|
|
321
296
|
}
|
|
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
297
|
function checkFindingProvider(input, provider) {
|
|
337
298
|
function checkFormat(format) {
|
|
338
299
|
if (format === tenableReportFormat)
|
|
339
300
|
requireCloudReader({ provider: "tenable" });
|
|
301
|
+
if (format === crowdstrikeReportFormat)
|
|
302
|
+
requireCloudReader({ provider: "crowdstrike" });
|
|
340
303
|
if (format === guardianSelectionFormat && provider !== "semgrep")
|
|
341
304
|
throw new CodexSecurityError("Use the semgrep provider for Guardian findings.");
|
|
342
305
|
}
|
|
343
|
-
checkFormat(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
for (const row of input.findings) {
|
|
347
|
-
if (!row)
|
|
348
|
-
continue;
|
|
349
|
-
if (guardianFindingId.test(storedFindingId(row)))
|
|
306
|
+
checkFormat(input.report?.["format"]);
|
|
307
|
+
for (const { source_finding_id, evidence } of input.findings) {
|
|
308
|
+
if (guardianFindingId.test(source_finding_id))
|
|
350
309
|
checkFormat(guardianSelectionFormat);
|
|
351
|
-
checkFormat(
|
|
310
|
+
checkFormat(evidence.source_data?.["format"]);
|
|
352
311
|
}
|
|
353
312
|
}
|
|
354
313
|
export async function prepareExternalPublication(path, options, dependencies = {}) {
|
|
@@ -362,7 +321,7 @@ export async function prepareExternalPublication(path, options, dependencies = {
|
|
|
362
321
|
const semgrep = settings.provider === "semgrep";
|
|
363
322
|
const report = await (semgrep
|
|
364
323
|
? readSemgrepReport(path)
|
|
365
|
-
:
|
|
324
|
+
: readScannerJson(path));
|
|
366
325
|
const normalize = async (url, platform) => {
|
|
367
326
|
const references = hostedSourceReferences(readerSources, url, semgrep ? platform : undefined);
|
|
368
327
|
const semgrepOptions = {
|
|
@@ -372,10 +331,7 @@ export async function prepareExternalPublication(path, options, dependencies = {
|
|
|
372
331
|
const findings = semgrep
|
|
373
332
|
? normalizeSemgrepFindings(report, semgrepOptions, "cloud")
|
|
374
333
|
: await normalizeSnykFile(report, "cloud", references);
|
|
375
|
-
|
|
376
|
-
if (semgrep && hasPreviousCloudProjection(findings))
|
|
377
|
-
selection.readPreviousFindings = () => normalizePreviousSemgrepFindings(report, semgrepOptions);
|
|
378
|
-
return selection;
|
|
334
|
+
return normalizedPublicationInput(findings, provider);
|
|
379
335
|
};
|
|
380
336
|
const hosted = isRecord(report) &&
|
|
381
337
|
(semgrep
|
|
@@ -422,29 +378,28 @@ export async function prepareExternalPublication(path, options, dependencies = {
|
|
|
422
378
|
}
|
|
423
379
|
else {
|
|
424
380
|
const parsed = await readExternalFindings(path, settings);
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
parsed.
|
|
428
|
-
normalizedPublicationInput(parsed.findings, provider);
|
|
429
|
-
input.readPreviousFindings = parsed.previousFindings;
|
|
430
|
-
if (provider === "endor") {
|
|
381
|
+
input = normalizedPublicationInput(parsed.findings, provider);
|
|
382
|
+
if (provider === "endor" ||
|
|
383
|
+
(provider === "continuum" && parsed.findings.report))
|
|
431
384
|
fileRepositories = () => parsed.sourceRepositories ?? [];
|
|
432
|
-
input.requiresStructuredReport = requiresStructuredEndorReport(parsed.findings);
|
|
433
|
-
}
|
|
434
385
|
}
|
|
435
|
-
return preparePublicationInput(input, { ...settings, provider }, dependencies, readerSources, settings.sourceRepositoryUrl,
|
|
386
|
+
return preparePublicationInput(input, { ...settings, provider }, dependencies, readerSources, undefined, settings.sourceRepositoryUrl, fileRepositories);
|
|
436
387
|
}
|
|
437
388
|
/** Prepare normalized provider evidence without reading a vendor export. */
|
|
438
389
|
export async function prepareNormalizedExternalPublication(input, options, dependencies = {}) {
|
|
390
|
+
return prepareNormalizedPublication(input, options, dependencies);
|
|
391
|
+
}
|
|
392
|
+
/** @internal The workbench persists acknowledgements before a repository checkpoint is retired. */
|
|
393
|
+
export async function prepareNormalizedPublication(input, options, dependencies, workbench) {
|
|
439
394
|
const settings = snapshotImportOptions(options);
|
|
440
395
|
requireCloudReader(settings);
|
|
441
|
-
return preparePublicationInput(normalizedPublicationInput(input, settings.provider), settings, dependencies, snapshotSourceRepositories(dependencies.sourceRepositories));
|
|
396
|
+
return preparePublicationInput(normalizedPublicationInput(input, settings.provider), settings, dependencies, snapshotSourceRepositories(dependencies.sourceRepositories), workbench);
|
|
442
397
|
}
|
|
443
398
|
function cloudSourceKey(url, platform) {
|
|
444
399
|
return hostedRepositoryUrlKey(url, platform === "github", platform === "gitlab", "cloud");
|
|
445
400
|
}
|
|
446
401
|
/** Verify every source in a hosted selection, including SDK inputs containing typed-only rows. */
|
|
447
|
-
function hostedRepositoryMatcher(input, provider, declaredUrl, destination, readerSources
|
|
402
|
+
function hostedRepositoryMatcher(input, provider, declaredUrl, destination, readerSources) {
|
|
448
403
|
const references = hostedSourceReferences(readerSources, destination.url, input.sourceRepositoryPlatform);
|
|
449
404
|
if (provider === "snyk") {
|
|
450
405
|
const declaredSource = input.sourceRepositoryUrl !== undefined ||
|
|
@@ -454,7 +409,7 @@ function hostedRepositoryMatcher(input, provider, declaredUrl, destination, read
|
|
|
454
409
|
const binding = snykRestImportRepository(input, provider, [
|
|
455
410
|
...readerSources.map(({ url }) => url),
|
|
456
411
|
...(declaredUrl === undefined ? [] : [declaredUrl]),
|
|
457
|
-
], references, undefined,
|
|
412
|
+
], references, undefined, declaredSource ? destination.url : undefined);
|
|
458
413
|
if (binding)
|
|
459
414
|
return {
|
|
460
415
|
github: binding.platform === "github",
|
|
@@ -484,71 +439,13 @@ function hostedRepositoryMatcher(input, provider, declaredUrl, destination, read
|
|
|
484
439
|
claims.add(guardian);
|
|
485
440
|
continue;
|
|
486
441
|
}
|
|
487
|
-
const data = finding.evidence.source_data;
|
|
488
442
|
const sarif = semgrepSarifRepositories(finding, hasNativeSource);
|
|
489
443
|
for (const { url } of sarif)
|
|
490
444
|
claims.add(hostedRepositoryUrl(url, "Semgrep source repository"));
|
|
491
|
-
|
|
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
|
-
}
|
|
445
|
+
nativeRows.push({ finding, sarif });
|
|
548
446
|
}
|
|
549
|
-
const witnesses = semgrepLegacyRepositoryWitnesses(nativeRows.map(({ finding }) => finding), provider, references, "cloud");
|
|
550
447
|
for (const { finding, sarif } of nativeRows) {
|
|
551
|
-
const native = semgrepPlatformFindingBinding(finding, provider, references,
|
|
448
|
+
const native = semgrepPlatformFindingBinding(finding, provider, references, reportScope, [{ url: projectedBlackDuckRepositoryUrl(finding, "cloud") }, ...sarif], "cloud")?.url;
|
|
552
449
|
if (native) {
|
|
553
450
|
original ??= native;
|
|
554
451
|
claims.add(native);
|
|
@@ -581,93 +478,6 @@ function ownData(value, key) {
|
|
|
581
478
|
? Object.getOwnPropertyDescriptor(value, key)?.value
|
|
582
479
|
: undefined;
|
|
583
480
|
}
|
|
584
|
-
// When native capture would invoke caller code, only the original data
|
|
585
|
-
// properties can identify the earlier selection. Unknown IDs cannot rule it out.
|
|
586
|
-
function previousFindingIds(input) {
|
|
587
|
-
const rows = ownData(input, "findings");
|
|
588
|
-
if (!Array.isArray(rows) || isProxy(rows))
|
|
589
|
-
return null;
|
|
590
|
-
return Array.from({ length: rows.length }, (_, index) => {
|
|
591
|
-
const row = Object.getOwnPropertyDescriptor(rows, index)?.value;
|
|
592
|
-
const id = ownData(row, "source_finding_id");
|
|
593
|
-
return typeof id === "string" ? id : undefined;
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
function withDataProperty(record, key, value) {
|
|
597
|
-
const fields = Object.getOwnPropertyDescriptors(record);
|
|
598
|
-
return Object.create(Object.getPrototypeOf(record), {
|
|
599
|
-
...fields,
|
|
600
|
-
[key]: { ...fields[key], value },
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
// Native cloning discarded enumerable diagnostic fields. Recover its message
|
|
604
|
-
// without reading the caller's stack getter or changing their report.
|
|
605
|
-
const nativeDiagnosticPrototypes = new Set([
|
|
606
|
-
Error.prototype,
|
|
607
|
-
EvalError.prototype,
|
|
608
|
-
RangeError.prototype,
|
|
609
|
-
ReferenceError.prototype,
|
|
610
|
-
SyntaxError.prototype,
|
|
611
|
-
TypeError.prototype,
|
|
612
|
-
URIError.prototype,
|
|
613
|
-
]);
|
|
614
|
-
function previousDiagnosticMessage(diagnostic) {
|
|
615
|
-
const stack = Object.getOwnPropertyDescriptor(diagnostic, "stack");
|
|
616
|
-
const message = ownData(diagnostic, "message");
|
|
617
|
-
const cause = Object.getOwnPropertyDescriptor(diagnostic, "cause");
|
|
618
|
-
const name = Object.getOwnPropertyDescriptor(diagnostic, "name");
|
|
619
|
-
if (!nativeDiagnosticPrototypes.has(Object.getPrototypeOf(diagnostic)) ||
|
|
620
|
-
typeof message !== "string" ||
|
|
621
|
-
(stack?.get && stack.get !== nativeErrorStackGetter) ||
|
|
622
|
-
(name && typeof name.value !== "string") ||
|
|
623
|
-
(cause &&
|
|
624
|
-
(!Object.hasOwn(cause, "value") ||
|
|
625
|
-
!canSnapshotWithoutGetters(cause.value))))
|
|
626
|
-
return;
|
|
627
|
-
return message;
|
|
628
|
-
}
|
|
629
|
-
function previousDiagnosticInput(input, nativeDiagnostics) {
|
|
630
|
-
const report = ownData(input, "report");
|
|
631
|
-
const errors = ownData(report, "errors");
|
|
632
|
-
if (!isRecord(report) || !Array.isArray(errors) || isProxy(errors))
|
|
633
|
-
return input;
|
|
634
|
-
let entries;
|
|
635
|
-
for (let index = 0; index < errors.length; index++) {
|
|
636
|
-
const descriptor = Object.getOwnPropertyDescriptor(errors, index);
|
|
637
|
-
const diagnostic = descriptor?.value;
|
|
638
|
-
if (!descriptor || !isNativeError(diagnostic))
|
|
639
|
-
continue;
|
|
640
|
-
const message = previousDiagnosticMessage(diagnostic);
|
|
641
|
-
if (message === undefined)
|
|
642
|
-
return input;
|
|
643
|
-
nativeDiagnostics.set(index, diagnostic);
|
|
644
|
-
(entries ??= Object.getOwnPropertyDescriptors(errors))[index] = {
|
|
645
|
-
...descriptor,
|
|
646
|
-
value: { message },
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
if (!entries)
|
|
650
|
-
return input;
|
|
651
|
-
const capturedErrors = Object.defineProperties([], entries);
|
|
652
|
-
const capturedReport = withDataProperty(report, "errors", capturedErrors);
|
|
653
|
-
return withDataProperty(input, "report", capturedReport);
|
|
654
|
-
}
|
|
655
|
-
// Capture before JSON hooks can change their source. If native capture would
|
|
656
|
-
// invoke caller code too, the original bytes cannot be observed independently.
|
|
657
|
-
function previousNormalizedFindings(input, nativeDiagnostics, observe) {
|
|
658
|
-
input = previousDiagnosticInput(input, nativeDiagnostics);
|
|
659
|
-
if (!canSnapshotWithoutGetters(input, observe))
|
|
660
|
-
return;
|
|
661
|
-
// Object spread skips a hidden report, but explicitly reading it could run a getter.
|
|
662
|
-
const reportField = Object.getOwnPropertyDescriptor(input, "report");
|
|
663
|
-
if (reportField && !Object.hasOwn(reportField, "value"))
|
|
664
|
-
return;
|
|
665
|
-
const { report, ...parsed } = input;
|
|
666
|
-
const snapshot = structuredClone(parsed);
|
|
667
|
-
if (report !== undefined)
|
|
668
|
-
snapshot.report = structuredClone(report);
|
|
669
|
-
return snapshot;
|
|
670
|
-
}
|
|
671
481
|
function publicationIdentity(parsed, provider) {
|
|
672
482
|
// For Trivy, the independently checked header binds the repository. Files
|
|
673
483
|
// and normalized rows use the same checkpoint when their findings agree.
|
|
@@ -676,7 +486,7 @@ function publicationIdentity(parsed, provider) {
|
|
|
676
486
|
return parsed.findings;
|
|
677
487
|
return { findings: parsed.findings, report: reportForJson(parsed.report) };
|
|
678
488
|
}
|
|
679
|
-
function validatePublicationFindings(parsed
|
|
489
|
+
function validatePublicationFindings(parsed) {
|
|
680
490
|
validateExternalReport(parsed.report);
|
|
681
491
|
const ids = new Set();
|
|
682
492
|
for (const finding of parsed.findings) {
|
|
@@ -686,293 +496,121 @@ function validatePublicationFindings(parsed, validateEvidence) {
|
|
|
686
496
|
if (ids.has(id))
|
|
687
497
|
throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(id)}.`);
|
|
688
498
|
ids.add(id);
|
|
689
|
-
finding.evidence =
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
function historicalPublication(native) {
|
|
693
|
-
if (!native)
|
|
694
|
-
return;
|
|
695
|
-
try {
|
|
696
|
-
// Older SDKs detached all raw records before Cloud validation added defaults.
|
|
697
|
-
for (const finding of native.findings)
|
|
698
|
-
if (finding.evidence.source_data !== undefined)
|
|
699
|
-
finding.evidence.source_data = structuredClone(finding.evidence.source_data);
|
|
700
|
-
validatePublicationFindings(native, validatePreviousCloudEvidence);
|
|
701
|
-
const identity = publicationIdentity(native);
|
|
702
|
-
let hasBoxedScalars = false;
|
|
703
|
-
const wire = canonicalJson(identity, undefined, (value) => {
|
|
704
|
-
if (!isBoxedPrimitive(value))
|
|
705
|
-
return false;
|
|
706
|
-
hasBoxedScalars = true;
|
|
707
|
-
return true;
|
|
708
|
-
});
|
|
709
|
-
return { parsed: native, identity, wire, hasBoxedScalars };
|
|
710
|
-
}
|
|
711
|
-
catch {
|
|
712
|
-
// The caller may export valid JSON even if the native candidate cannot be
|
|
713
|
-
// validated or hashed, for example when an unused row property holds a BigInt.
|
|
714
|
-
return;
|
|
499
|
+
finding.evidence = validateExternalEvidence(finding.evidence);
|
|
715
500
|
}
|
|
716
501
|
}
|
|
717
502
|
function normalizedPublicationInput(input, provider) {
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
let plainJson = true;
|
|
721
|
-
try {
|
|
722
|
-
native = previousNormalizedFindings(input, nativeDiagnostics, (value) => {
|
|
723
|
-
if (!plainJson)
|
|
724
|
-
return;
|
|
725
|
-
const prototype = Object.getPrototypeOf(value);
|
|
726
|
-
plainJson =
|
|
727
|
-
(prototype === null ||
|
|
728
|
-
prototype === Object.prototype ||
|
|
729
|
-
prototype === Array.prototype) &&
|
|
730
|
-
!("toJSON" in value);
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
catch {
|
|
734
|
-
/* A valid JSON export can contain an uncloneable value. */
|
|
735
|
-
}
|
|
736
|
-
let priorIds = native ? undefined : previousFindingIds(input);
|
|
737
|
-
let current;
|
|
738
|
-
let freshError;
|
|
739
|
-
try {
|
|
740
|
-
current = snapshotNormalizedFindings(input, undefined, "cloud");
|
|
741
|
-
}
|
|
742
|
-
catch (error) {
|
|
743
|
-
if ((!isNativeError(error) && !(error instanceof Error)) ||
|
|
744
|
-
!native?.findings.length)
|
|
745
|
-
throw error;
|
|
746
|
-
freshError = error;
|
|
747
|
-
current = { read: native.read, findings: [], excluded: [] };
|
|
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) {
|
|
503
|
+
const current = snapshotNormalizedFindings(input, undefined, "cloud", provider);
|
|
504
|
+
if (current.snykRestContext !== undefined) {
|
|
767
505
|
if (provider !== "snyk")
|
|
768
506
|
throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
|
|
769
|
-
if (!isSnykRestFormat(
|
|
507
|
+
if (!isSnykRestFormat(current.snykRestContext?.["format"]))
|
|
770
508
|
throw new CodexSecurityError("Expected a versioned Snyk REST report context.");
|
|
771
509
|
}
|
|
772
|
-
const markedSemgrep = "sourceFormat" in
|
|
510
|
+
const markedSemgrep = "sourceFormat" in current && isSemgrepPlatformFormat(current.sourceFormat);
|
|
773
511
|
if (markedSemgrep && provider !== "semgrep")
|
|
774
512
|
throw new CodexSecurityError("Semgrep Platform evidence requires the semgrep provider.");
|
|
775
|
-
if (markedSemgrep || "semgrepPlatformScope" in
|
|
776
|
-
semgrepPlatformReportScope(
|
|
777
|
-
|
|
778
|
-
const historical = native.report["errors"];
|
|
779
|
-
const exported = current.report?.["errors"];
|
|
780
|
-
for (const [index, source] of nativeDiagnostics) {
|
|
781
|
-
const message = historical[index].message;
|
|
782
|
-
let diagnostic = Array.isArray(exported) && exported[index];
|
|
783
|
-
// A failed export may never reach the report. Its hooks have already run,
|
|
784
|
-
// so check the original descriptors again before native cloning reads a stack.
|
|
785
|
-
if (freshError && previousDiagnosticMessage(source) === message)
|
|
786
|
-
diagnostic = source;
|
|
787
|
-
if (isNativeError(diagnostic) &&
|
|
788
|
-
Object.getPrototypeOf(diagnostic) === Object.getPrototypeOf(source)) {
|
|
789
|
-
try {
|
|
790
|
-
const copy = structuredClone(diagnostic);
|
|
791
|
-
if (copy.message === message) {
|
|
792
|
-
historical[index] = copy;
|
|
793
|
-
continue;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
catch {
|
|
797
|
-
// A failed native clone cannot establish a historical report.
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
if (freshError)
|
|
801
|
-
throw freshError;
|
|
802
|
-
priorIds = previousFindingIds(native);
|
|
803
|
-
native = undefined;
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
// A Cloud depth error can interrupt a local reader's JSON export. Its plain,
|
|
808
|
-
// independently captured output can still verify the original reader selection.
|
|
809
|
-
const readerOutput = freshError
|
|
810
|
-
? freshError instanceof CloudEvidenceDepthError &&
|
|
811
|
-
plainJson &&
|
|
812
|
-
!nativeDiagnostics.size &&
|
|
813
|
-
native
|
|
814
|
-
: current;
|
|
815
|
-
const reader = readerOutput
|
|
816
|
-
? previousReaderSelection(input, readerOutput, native ?? null)
|
|
817
|
-
: undefined;
|
|
818
|
-
if (reader)
|
|
819
|
-
native = reader.snapshot;
|
|
820
|
-
const original = historicalPublication(native);
|
|
821
|
-
if (original)
|
|
822
|
-
checkFindingProvider(original.parsed, provider);
|
|
823
|
-
try {
|
|
824
|
-
validatePublicationFindings(current, validateExternalEvidence);
|
|
825
|
-
}
|
|
826
|
-
catch (error) {
|
|
827
|
-
if (!(error instanceof Error) || !original?.parsed.findings.length)
|
|
828
|
-
throw error;
|
|
829
|
-
freshError = error;
|
|
830
|
-
}
|
|
831
|
-
if (freshError) {
|
|
832
|
-
if (!original)
|
|
833
|
-
throw freshError;
|
|
834
|
-
// Only the old selection can be reviewed when fresh validation failed.
|
|
835
|
-
current = { read: original.parsed.read, findings: [], excluded: [] };
|
|
836
|
-
}
|
|
513
|
+
if (markedSemgrep || "semgrepPlatformScope" in current)
|
|
514
|
+
semgrepPlatformReportScope(current, provider);
|
|
515
|
+
validatePublicationFindings(current);
|
|
837
516
|
checkFindingProvider(current, provider);
|
|
838
|
-
const identity = publicationIdentity(current, provider);
|
|
839
517
|
return {
|
|
840
518
|
current,
|
|
841
|
-
legacy: current,
|
|
842
|
-
currentIdentity: identity,
|
|
843
|
-
legacyIdentity: identity,
|
|
844
519
|
sourcePositions: getOpenGrepSourcePositions(ownData(input, "findings")),
|
|
845
|
-
original,
|
|
846
|
-
freshError,
|
|
847
|
-
unprovenIdPrefixes: reader?.unprovenIdPrefixes,
|
|
848
|
-
uncertainFindingIds: reader?.uncertainFindingIds,
|
|
849
|
-
unprovenOccurrenceCount: reader?.unprovenOccurrenceCount,
|
|
850
|
-
knownFindings: reader?.knownFindings,
|
|
851
|
-
potentialIds: reader?.sourceFindingIds ??
|
|
852
|
-
(original
|
|
853
|
-
? undefined
|
|
854
|
-
: (native?.findings.map((row) => row.source_finding_id) ?? priorIds)),
|
|
855
520
|
};
|
|
856
521
|
}
|
|
857
|
-
//
|
|
858
|
-
// and
|
|
859
|
-
function
|
|
860
|
-
let verifiable = true;
|
|
861
|
-
// Only values in these records can be old scalar projections. Their record
|
|
862
|
-
// containers are required by the normalized selection, including an empty report.
|
|
863
|
-
const { errors, ...metadata } = report ?? {};
|
|
864
|
-
JSON.stringify([
|
|
865
|
-
Object.values(metadata),
|
|
866
|
-
// The original hash used the serialized form of report.errors arrays.
|
|
867
|
-
Array.isArray(errors) ? undefined : errors,
|
|
868
|
-
findings.map(({ evidence: _, ...fields }) => Object.values(fields)),
|
|
869
|
-
], (_key, value) => {
|
|
870
|
-
if (isRecord(value) && !(wireIdentity && isBoxedPrimitive(value))) {
|
|
871
|
-
// {} and string-index records can both be the old form of a scalar.
|
|
872
|
-
let index = 0;
|
|
873
|
-
if (Object.keys(value).every((key) => {
|
|
874
|
-
const item = value[key];
|
|
875
|
-
return (item === undefined ||
|
|
876
|
-
(key === String(index++) &&
|
|
877
|
-
typeof item === "string" &&
|
|
878
|
-
item.length === 1));
|
|
879
|
-
}))
|
|
880
|
-
verifiable = false;
|
|
881
|
-
}
|
|
882
|
-
return value;
|
|
883
|
-
});
|
|
884
|
-
return verifiable;
|
|
885
|
-
}
|
|
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;
|
|
522
|
+
// A normalized hosted input can omit native fields that the authenticated
|
|
523
|
+
// repository and the retained source response establish for each occurrence.
|
|
524
|
+
function hostedPublicationFindings(current, provider, destination, readerSources) {
|
|
890
525
|
if (provider === "snyk") {
|
|
891
526
|
const first = current.findings.find(isSnykRestFinding);
|
|
892
527
|
if (!first && current.snykRestContext === undefined)
|
|
893
|
-
return;
|
|
894
|
-
|
|
895
|
-
yield input;
|
|
896
|
-
const originalUrl = current.snykRestContext?.["sourceRepositoryUrl"] ??
|
|
528
|
+
return current;
|
|
529
|
+
const url = current.snykRestContext?.["sourceRepositoryUrl"] ??
|
|
897
530
|
current.sourceRepositoryUrl ??
|
|
898
531
|
first?.evidence.source_data?.["sourceRepositoryUrl"];
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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;
|
|
532
|
+
snykRestImportRepository(current, provider, [], hostedSourceReferences(readerSources, typeof url === "string" ? url : destination.url, current.sourceRepositoryPlatform), (finding, source) => {
|
|
533
|
+
finding.evidence.source_data = source;
|
|
534
|
+
});
|
|
535
|
+
return current;
|
|
921
536
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
const
|
|
925
|
-
const first = current.findings.find(originalRow) ?? current.findings.find(currentBulkRow);
|
|
537
|
+
if (provider !== "semgrep")
|
|
538
|
+
return current;
|
|
539
|
+
const first = current.findings.find((finding) => isSemgrepPlatformEvidence(finding, provider));
|
|
926
540
|
if (!first)
|
|
927
|
-
return;
|
|
928
|
-
const reportScope = semgrepPlatformReportScope(current, "semgrep");
|
|
541
|
+
return current;
|
|
929
542
|
const retained = first.evidence.source_data;
|
|
930
543
|
const project = retained?.["project"];
|
|
931
|
-
const
|
|
544
|
+
const url = current.sourceRepositoryUrl ??
|
|
932
545
|
retained?.["sourceRepositoryUrl"] ??
|
|
933
546
|
(isRecord(project) ? project["url"] : undefined);
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
547
|
+
const references = hostedSourceReferences(readerSources, typeof url === "string"
|
|
548
|
+
? normalizeHostedGitRepositoryUrl(url, destination.url, true)
|
|
549
|
+
: destination.url, current.sourceRepositoryPlatform);
|
|
550
|
+
const scope = semgrepPlatformReportScope(current, provider, references);
|
|
551
|
+
const findings = current.findings.map((finding) => {
|
|
552
|
+
const data = finding.evidence.source_data;
|
|
553
|
+
const original = isRecord(data?.["finding"]) &&
|
|
554
|
+
isSemgrepPlatformEvidence(finding, provider);
|
|
555
|
+
if (!original && data?.["format"] !== semgrepPlatformFormat)
|
|
556
|
+
return finding;
|
|
557
|
+
const binding = semgrepPlatformFindingBinding(finding, provider, references, scope, undefined, "cloud");
|
|
558
|
+
return binding?.sourceData &&
|
|
559
|
+
(original || binding.sourceData["format"] !== semgrepPlatformFormat)
|
|
560
|
+
? {
|
|
561
|
+
...finding,
|
|
562
|
+
evidence: {
|
|
563
|
+
...finding.evidence,
|
|
564
|
+
...binding.migration,
|
|
565
|
+
source_data: binding.sourceData,
|
|
566
|
+
},
|
|
567
|
+
}
|
|
568
|
+
: finding;
|
|
569
|
+
});
|
|
570
|
+
return { ...current, findings };
|
|
571
|
+
}
|
|
572
|
+
async function preparePublicationInput(supplied, options, dependencies, readerSources, workbench, declaredUrl, fileRepositories) {
|
|
573
|
+
const record = workbench !== "preview" && workbench?.record;
|
|
574
|
+
function withReceipts(scope, prepared) {
|
|
575
|
+
return {
|
|
576
|
+
preview: prepared.preview,
|
|
577
|
+
async publish() {
|
|
578
|
+
if (!record)
|
|
579
|
+
return prepared.publish();
|
|
580
|
+
let recorded = false;
|
|
581
|
+
const persist = async (result) => {
|
|
582
|
+
if (recorded)
|
|
583
|
+
return;
|
|
584
|
+
recorded = true;
|
|
585
|
+
const job = result.privateJob;
|
|
586
|
+
const privateJobId = job?.status === "completed" &&
|
|
587
|
+
!result.counts.error &&
|
|
588
|
+
!result.unacknowledged
|
|
589
|
+
? job.id
|
|
590
|
+
: undefined;
|
|
591
|
+
if (!privateJobId && !result.receipts.length)
|
|
592
|
+
return;
|
|
593
|
+
try {
|
|
594
|
+
await record(scope, result.receipts, privateJobId);
|
|
957
595
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
596
|
+
catch (error) {
|
|
597
|
+
throw new ExternalPublicationError(`Cloud returned receipts, but the workbench could not record them: ${errorMessage(error)}`, result, error);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
let result;
|
|
601
|
+
try {
|
|
602
|
+
result = await prepared.publish(persist);
|
|
603
|
+
}
|
|
604
|
+
catch (error) {
|
|
605
|
+
if (error instanceof ExternalPublicationError)
|
|
606
|
+
await persist(error.result);
|
|
607
|
+
throw error;
|
|
608
|
+
}
|
|
609
|
+
await persist(result);
|
|
610
|
+
return result;
|
|
611
|
+
},
|
|
612
|
+
};
|
|
972
613
|
}
|
|
973
|
-
yield input;
|
|
974
|
-
}
|
|
975
|
-
async function preparePublicationInput(supplied, options, dependencies, readerSources, declaredUrl, nativePath, fileRepositories) {
|
|
976
614
|
const { inspectorProjectMap } = options;
|
|
977
615
|
const progress = (event) => notify(() => dependencies.onProgress?.(event));
|
|
978
616
|
if (!options.sourceKey.trim() ||
|
|
@@ -992,44 +630,23 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
992
630
|
? (url) => cloudSourceKey(url, "github")
|
|
993
631
|
: cloudRepositoryUrlKey;
|
|
994
632
|
const state = externalPublicationStateDirectory(environment);
|
|
995
|
-
function
|
|
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) {
|
|
633
|
+
function checkSelection(input) {
|
|
1011
634
|
const parsed = input.current;
|
|
1012
635
|
checkTrivyReportProvider(options.provider, parsed.report);
|
|
1013
636
|
for (const finding of parsed.findings)
|
|
1014
637
|
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)
|
|
638
|
+
if (!parsed.findings.length)
|
|
1023
639
|
throw new NoPublishableFindingsError(parsed);
|
|
1024
640
|
}
|
|
1025
641
|
if (typeof supplied !== "function")
|
|
1026
|
-
|
|
642
|
+
checkSelection(supplied);
|
|
1027
643
|
progress({ phase: "discovering", completed: 0 });
|
|
1028
644
|
const apiBaseUrl = cloudBaseUrl(environment);
|
|
1029
645
|
const cloudApiUrl = `${apiBaseUrl}/external`;
|
|
1030
646
|
// Validate the configured return destination before authentication or uploads.
|
|
1031
647
|
cloudFindingsUrl(environment, options.repository);
|
|
1032
|
-
const credentials = await (dependencies.credentials ??
|
|
648
|
+
const credentials = await (dependencies.credentials ??
|
|
649
|
+
(() => readCloudCredentials(environment, dependencies.signal)))();
|
|
1033
650
|
let canStartJob = false;
|
|
1034
651
|
let repositorySeverities;
|
|
1035
652
|
const jobVersionHeader = "Codex-Security-Private-Import-Job-Version";
|
|
@@ -1063,7 +680,19 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
1063
680
|
if (!response.ok) {
|
|
1064
681
|
const payload = (await response.json().catch(() => null));
|
|
1065
682
|
const retryAfter = response.headers.get("Retry-After");
|
|
1066
|
-
|
|
683
|
+
const detail = payload?.error?.message ?? response.statusText;
|
|
684
|
+
let message = `Cloud import failed (HTTP ${response.status}).`;
|
|
685
|
+
if (detail)
|
|
686
|
+
message += ` ${detail}`;
|
|
687
|
+
if (repositoryCatalog && response.status === 404) {
|
|
688
|
+
if (!/[.!?]$/u.test(message))
|
|
689
|
+
message += ".";
|
|
690
|
+
message +=
|
|
691
|
+
" Cloud import is not available for this account or deployment.";
|
|
692
|
+
}
|
|
693
|
+
if (retryAfter)
|
|
694
|
+
message += ` Retry-After: ${retryAfter}.`;
|
|
695
|
+
throw new CloudImportError(response.status, message);
|
|
1067
696
|
}
|
|
1068
697
|
if (repositoryCatalog) {
|
|
1069
698
|
const advertised = (header) => response.headers
|
|
@@ -1108,303 +737,34 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
1108
737
|
const deferred = typeof supplied === "function";
|
|
1109
738
|
const resolved = deferred ? await supplied(destination) : supplied;
|
|
1110
739
|
if (deferred)
|
|
1111
|
-
|
|
740
|
+
checkSelection(resolved);
|
|
1112
741
|
const report = resolved.current;
|
|
1113
742
|
const source = { provider: options.provider, source_key: options.sourceKey };
|
|
1114
743
|
const importPrefix = source.provider === "sonar" ? "/v2" : "";
|
|
1115
744
|
const sourceReportsPath = importPrefix + sourcePath(destination);
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
745
|
+
const hosted = options.provider === "snyk" || options.provider === "semgrep";
|
|
746
|
+
const parsed = hostedPublicationFindings(report, options.provider, destination, readerSources);
|
|
747
|
+
const key = hash("sha256", canonicalJson([
|
|
748
|
+
"external-findings/2",
|
|
749
|
+
apiBaseUrl,
|
|
1120
750
|
credentials.account_id,
|
|
1121
751
|
destination.id,
|
|
1122
752
|
destination.repo_connector_id,
|
|
1123
753
|
source,
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
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.
|
|
754
|
+
publicationIdentity(parsed, options.provider),
|
|
755
|
+
...(workbench === "preview"
|
|
756
|
+
? ["preview"]
|
|
757
|
+
: workbench
|
|
758
|
+
? [workbench.checkout, workbench.findings]
|
|
759
|
+
: []),
|
|
760
|
+
]));
|
|
761
|
+
const pendingPath = join(state, key + ".pending.json");
|
|
762
|
+
const underPublishLock = (operation) => withImportLock(state, key, dependencies.signal, operation);
|
|
763
|
+
const removePending = () => rm(pendingPath, { force: true });
|
|
1156
764
|
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
765
|
const scopedSemgrepReport = options.provider === "semgrep" &&
|
|
1211
766
|
"sourceFormat" in parsed &&
|
|
1212
767
|
isSemgrepPlatformFormat(parsed.sourceFormat);
|
|
1213
|
-
const original = input.original;
|
|
1214
|
-
const originalParsed = original?.parsed ?? parsed;
|
|
1215
|
-
const originalIdentity = original?.identity ?? currentIdentity;
|
|
1216
|
-
const hasBoxedScalars = original?.hasBoxedScalars === true;
|
|
1217
|
-
const changedCapture = original && original.wire !== wireJson(currentIdentity);
|
|
1218
|
-
const originalKey = changedCapture || hasBoxedScalars
|
|
1219
|
-
? scopeKey(originalIdentity, canonicalJson)
|
|
1220
|
-
: undefined;
|
|
1221
|
-
let historicalOnly = false;
|
|
1222
|
-
const originalWireKey = changedCapture
|
|
1223
|
-
? scopeKey(originalIdentity)
|
|
1224
|
-
: undefined;
|
|
1225
|
-
if (changedCapture && originalKey && originalWireKey) {
|
|
1226
|
-
// A released SDK could stage either spelling. A modern approval for the
|
|
1227
|
-
// fresh JSON can occupy the very same historical filename.
|
|
1228
|
-
for (const pathKey of new Set([
|
|
1229
|
-
originalKey,
|
|
1230
|
-
originalWireKey,
|
|
1231
|
-
localeKey(original.parsed.findings),
|
|
1232
|
-
])) {
|
|
1233
|
-
const bytes = await readOptionalFile(pendingFile(pathKey));
|
|
1234
|
-
if (bytes === undefined)
|
|
1235
|
-
continue;
|
|
1236
|
-
const record = JSON.parse(bytes);
|
|
1237
|
-
if ((record?.legacyApproval &&
|
|
1238
|
-
(record.wireKey ?? pathKey) === originalWireKey) ||
|
|
1239
|
-
(record?.wireKey === undefined &&
|
|
1240
|
-
record?.inputProjection?.identityFormat !== 2 &&
|
|
1241
|
-
(pathKey === originalKey ||
|
|
1242
|
-
pathKey === originalWireKey ||
|
|
1243
|
-
original.parsed.report === undefined ||
|
|
1244
|
-
record?.inputProjection?.inputDigest ===
|
|
1245
|
-
jsonDigest(originalIdentity, canonicalJson)))) {
|
|
1246
|
-
parsed = legacyParsed = original.parsed;
|
|
1247
|
-
currentIdentity = legacyIdentity = original.identity;
|
|
1248
|
-
historicalOnly = true;
|
|
1249
|
-
break;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
if (input.freshError && !historicalOnly)
|
|
1254
|
-
throw input.freshError;
|
|
1255
|
-
const inputDigest = jsonDigest(currentIdentity);
|
|
1256
|
-
const legacyInputDigest = currentIdentity === legacyIdentity
|
|
1257
|
-
? inputDigest
|
|
1258
|
-
: jsonDigest(legacyIdentity);
|
|
1259
|
-
function matchesSavedDestination(requests) {
|
|
1260
|
-
return (requests.length > 0 &&
|
|
1261
|
-
requests.every((batch) => batch.repository.id === destination.id &&
|
|
1262
|
-
batch.repository.repo_connector_id ===
|
|
1263
|
-
destination.repo_connector_id &&
|
|
1264
|
-
wireJson(batch.source) === wireJson(source)));
|
|
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
768
|
function wasReset(content) {
|
|
1409
769
|
return content.requests.some(({ repository }) => repository.reset_marker !== destination.reset_marker);
|
|
1410
770
|
}
|
|
@@ -1428,21 +788,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
1428
788
|
]
|
|
1429
789
|
: null));
|
|
1430
790
|
}
|
|
1431
|
-
async function retireIfReset(content, retire) {
|
|
1432
|
-
if (wasReset(content)) {
|
|
1433
|
-
if (hosted)
|
|
1434
|
-
await confirmReset();
|
|
1435
|
-
await retire();
|
|
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.");
|
|
1437
|
-
}
|
|
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
|
-
}
|
|
1446
791
|
function readSaved(content) {
|
|
1447
792
|
if (!content ||
|
|
1448
793
|
content.accountId !== credentials.account_id ||
|
|
@@ -1450,592 +795,77 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
1450
795
|
content.requests.length === 0)
|
|
1451
796
|
throw new Error("Saved import account or requests do not match.");
|
|
1452
797
|
content.requests = content.requests.map(validateImportRequest);
|
|
1453
|
-
|
|
798
|
+
const actual = submissionFindings(content.requests);
|
|
799
|
+
for (const finding of actual)
|
|
1454
800
|
checkRetainedTrivyProvider(options.provider, finding);
|
|
1455
|
-
if (
|
|
801
|
+
if (content.requests.some((batch) => batch.repository.id !== destination.id ||
|
|
802
|
+
batch.repository.repo_connector_id !==
|
|
803
|
+
destination.repo_connector_id ||
|
|
804
|
+
canonicalJson(batch.source) !== canonicalJson(source)))
|
|
1456
805
|
throw new Error("Saved import destination does not match.");
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
const saved = submissionFindings(content.requests);
|
|
1464
|
-
const wire = wireJson(saved);
|
|
1465
|
-
const projection = content.inputProjection;
|
|
1466
|
-
const expected = repositoryFindings(legacy ? legacyParsed : parsed, projection?.repositorySeverities);
|
|
1467
|
-
if (projection &&
|
|
1468
|
-
(!sameFindingSelection(saved, expected) ||
|
|
1469
|
-
projection.inputDigest !== (legacy ? legacyInputDigest : inputDigest) ||
|
|
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
|
-
}
|
|
1479
|
-
throw new Error("Saved import evidence does not match the selected input.");
|
|
1480
|
-
}
|
|
1481
|
-
// Older file readers can have a different, explicitly bound projection.
|
|
1482
|
-
// A corrected numeric checkpoint must carry the selected evidence verbatim.
|
|
1483
|
-
const exactWire = historicalOnly || hasBoxedScalars || content.wireKey !== undefined;
|
|
1484
|
-
if ((!projection || exactWire) &&
|
|
1485
|
-
wire !== wireJson(exactWire ? expected.map(wireFinding) : expected))
|
|
1486
|
-
throw new Error("Saved import evidence does not match the selected input.");
|
|
1487
|
-
if (!legacy &&
|
|
1488
|
-
hasBoxedScalars &&
|
|
1489
|
-
projection?.identityFormat !== 2 &&
|
|
1490
|
-
!verifiableLegacyMetadata(originalParsed, true))
|
|
1491
|
-
throw unmatchedPreviousNumbers();
|
|
1492
|
-
checkFindingProvider({ ...parsed, findings: saved }, options.provider);
|
|
1493
|
-
const approvedScope = content.inputProjection?.semgrepPartialScopeDigest;
|
|
1494
|
-
if (approvedScope !== undefined &&
|
|
806
|
+
checkFindingProvider({ ...parsed, findings: actual }, options.provider);
|
|
807
|
+
const expected = repositoryFindings(parsed, content.repositorySeverities);
|
|
808
|
+
if (canonicalJson(actual) !== canonicalJson(expected.map(wireFinding)))
|
|
809
|
+
throw new CodexSecurityError("Saved import evidence does not match the selected input.");
|
|
810
|
+
const scope = content.semgrepPartialScopeDigest;
|
|
811
|
+
if (scope !== undefined &&
|
|
1495
812
|
!wasReset(content) &&
|
|
1496
|
-
|
|
813
|
+
scope !== suppliedSemgrepScopeDigest())
|
|
1497
814
|
throw new CodexSecurityError("The supplied Semgrep report scope does not match the approved request.");
|
|
1498
815
|
return content;
|
|
1499
816
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
function readPreviousNumbers(record) {
|
|
1504
|
-
const content = readSaved(record);
|
|
1505
|
-
const projection = content.inputProjection;
|
|
1506
|
-
const saved = submissionFindings(content.requests);
|
|
1507
|
-
const savedWire = wireJson(saved);
|
|
1508
|
-
const wireDigest = hash("sha256", savedWire);
|
|
1509
|
-
if (projection?.inputDigest !== jsonDigest(originalIdentity, canonicalJson))
|
|
1510
|
-
throw unmatchedPreviousNumbers();
|
|
1511
|
-
if (projection.identityFormat === 2) {
|
|
1512
|
-
// A current writer may own the old filename for an ordinary object.
|
|
1513
|
-
if (projection.savedEvidenceDigest === wireDigest)
|
|
1514
|
-
return undefined;
|
|
1515
|
-
throw unmatchedPreviousNumbers();
|
|
1516
|
-
}
|
|
1517
|
-
const selected = originalParsed.findings.map(wireFinding);
|
|
1518
|
-
if (projection.savedEvidenceDigest !== jsonDigest(selected, canonicalJson))
|
|
1519
|
-
throw unmatchedPreviousNumbers();
|
|
1520
|
-
if (savedWire !== wireJson(selected)) {
|
|
1521
|
-
// A genuinely empty object at this key is a separate ordinary selection.
|
|
1522
|
-
if (wireDigest === projection.savedEvidenceDigest)
|
|
1523
|
-
return undefined;
|
|
1524
|
-
return "different-wire";
|
|
1525
|
-
}
|
|
1526
|
-
if ((changedCapture && !historicalOnly) ||
|
|
1527
|
-
!verifiableLegacyMetadata(originalParsed, false))
|
|
1528
|
-
throw unmatchedPreviousNumbers();
|
|
1529
|
-
checkFindingProvider({ ...parsed, findings: saved }, options.provider);
|
|
1530
|
-
content.legacyApproval = true;
|
|
1531
|
-
content.inputProjection = {
|
|
1532
|
-
...content.inputProjection,
|
|
1533
|
-
identityFormat: 2,
|
|
1534
|
-
inputDigest,
|
|
1535
|
-
savedEvidenceDigest: wireDigest,
|
|
1536
|
-
};
|
|
1537
|
-
return content;
|
|
1538
|
-
}
|
|
1539
|
-
function unmatchedPreviousNumbers() {
|
|
1540
|
-
return new CodexSecurityError("The older saved import cannot be matched to the selected input. Its checkpoint was preserved without uploading.");
|
|
1541
|
-
}
|
|
1542
|
-
const key = scopeKey(currentIdentity);
|
|
1543
|
-
const stagingKey = originalKey ?? key;
|
|
1544
|
-
const canonicalPath = pendingFile(key);
|
|
1545
|
-
const lookupPath = join(state, `${key}.lookup.json`);
|
|
1546
|
-
// A lookup only suggests a regular file to validate. A missing or stale hint
|
|
1547
|
-
// leaves the same on-disk discovery available as before.
|
|
1548
|
-
async function readOptionalRegularFile(path) {
|
|
1549
|
-
try {
|
|
1550
|
-
if ((await lstat(path)).isFile())
|
|
1551
|
-
return await readFile(path, "utf8");
|
|
1552
|
-
}
|
|
1553
|
-
catch {
|
|
1554
|
-
// Optional discovery must not veto an independently verified checkpoint.
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
async function lookupFileKey() {
|
|
1558
|
-
const serialized = await readOptionalRegularFile(lookupPath);
|
|
1559
|
-
return serialized?.trim().match(/^"([a-f0-9]{64})"$/u)?.[1];
|
|
1560
|
-
}
|
|
1561
|
-
const historicalKey = localeKey(legacyParsed.findings);
|
|
1562
|
-
const legacyIdentityKey = scopeKey(legacyIdentity);
|
|
1563
|
-
const legacyKeys = new Set([legacyIdentityKey, historicalKey]);
|
|
1564
|
-
function underLocks(keys, operation) {
|
|
1565
|
-
return withImportLocks(state, keys, dependencies.signal, operation);
|
|
817
|
+
async function readPending() {
|
|
818
|
+
const bytes = await readOptionalFile(pendingPath);
|
|
819
|
+
return bytes === undefined ? undefined : readSaved(JSON.parse(bytes));
|
|
1566
820
|
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
if (
|
|
1570
|
-
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
let prior;
|
|
1580
|
-
if (serialized !== undefined) {
|
|
1581
|
-
try {
|
|
1582
|
-
prior = JSON.parse(serialized);
|
|
1583
|
-
}
|
|
1584
|
-
catch (error) {
|
|
1585
|
-
if (current === undefined || !(error instanceof SyntaxError))
|
|
1586
|
-
throw error;
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
if (prior?.wireKey !== undefined)
|
|
1590
|
-
return;
|
|
1591
|
-
if (current !== undefined) {
|
|
1592
|
-
recovered = validateSaved(JSON.parse(current));
|
|
1593
|
-
if (prior && sameSubmission(prior, recovered))
|
|
1594
|
-
await rm(legacyPath);
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
// A report-free approval at the locale-era filename can be a separate input.
|
|
1598
|
-
if (legacyKey !== legacyIdentityKey &&
|
|
1599
|
-
prior?.inputProjection &&
|
|
1600
|
-
prior.inputProjection.inputDigest !== legacyInputDigest) {
|
|
1601
|
-
const projection = prior.inputProjection;
|
|
1602
|
-
const rows = legacyParsed.findings;
|
|
1603
|
-
if (projection.identityFormat === 2 ||
|
|
1604
|
-
(projection.inputDigest === jsonDigest(rows) &&
|
|
1605
|
-
projection.savedEvidenceDigest ===
|
|
1606
|
-
jsonDigest(submissionFindings(prior.requests))))
|
|
1607
|
-
return;
|
|
1608
|
-
// The released SDK hashed report-free rows as an array and boxed scores as {}.
|
|
1609
|
-
const originalRows = original?.parsed.findings ?? rows;
|
|
1610
|
-
if (hasBoxedScalars &&
|
|
1611
|
-
legacyParsed.report !== undefined &&
|
|
1612
|
-
legacyKey === scopeKey(originalRows, canonicalJson) &&
|
|
1613
|
-
projection.inputDigest ===
|
|
1614
|
-
jsonDigest(originalRows, canonicalJson) &&
|
|
1615
|
-
projection.savedEvidenceDigest ===
|
|
1616
|
-
jsonDigest(originalRows.map(wireFinding), canonicalJson) &&
|
|
1617
|
-
sameFindingSelection(submissionFindings(readSaved(prior).requests), rows))
|
|
1618
|
-
return;
|
|
1619
|
-
}
|
|
1620
|
-
const content = validateSaved(serialized === undefined ? JSON.parse(captured) : prior, true, legacyKey);
|
|
1621
|
-
if (!sameFindingSelection(legacyParsed.findings, parsed.findings))
|
|
1622
|
-
throw new CodexSecurityError("The saved import selects different findings from this input. Resume the original selection before publishing this selection.");
|
|
1623
|
-
await retireIfReset(content, async () => {
|
|
1624
|
-
if (serialized !== undefined)
|
|
1625
|
-
await rm(legacyPath);
|
|
1626
|
-
});
|
|
1627
|
-
const savedEvidenceDigest = content.inputProjection?.savedEvidenceDigest ??
|
|
1628
|
-
jsonDigest(legacyParsed.findings);
|
|
1629
|
-
const rebindProjection = content.inputProjection !== undefined ||
|
|
1630
|
-
savedEvidenceDigest !== inputDigest;
|
|
1631
|
-
if (rebindProjection) {
|
|
1632
|
-
if (content.inputProjection?.identityFormat !== 2)
|
|
1633
|
-
content.legacyApproval = true;
|
|
1634
|
-
content.inputProjection = {
|
|
1635
|
-
...content.inputProjection,
|
|
1636
|
-
identityFormat: 2,
|
|
1637
|
-
inputDigest,
|
|
1638
|
-
savedEvidenceDigest,
|
|
1639
|
-
};
|
|
1640
|
-
}
|
|
1641
|
-
recovered = content;
|
|
1642
|
-
if (serialized === undefined)
|
|
1643
|
-
return;
|
|
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
|
-
});
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
// Some getter-backed batches cannot reproduce a released filename. Their IDs
|
|
1659
|
-
// can stop a conflicting upload, but never authorize replay of a saved request.
|
|
1660
|
-
const potentialIds = input.potentialIds === undefined && changedCapture
|
|
1661
|
-
? original.parsed.findings.map((row) => row.source_finding_id)
|
|
1662
|
-
: input.potentialIds;
|
|
1663
|
-
const unprovenPrefixes = new Set(input.unprovenIdPrefixes);
|
|
1664
|
-
const uncertainIds = new Set(input.uncertainFindingIds);
|
|
1665
|
-
const uncertainMembership = input.unprovenOccurrenceCount ||
|
|
1666
|
-
uncertainIds.size > 0 ||
|
|
1667
|
-
unprovenPrefixes.size > 0;
|
|
1668
|
-
function uncertainId(id) {
|
|
1669
|
-
return (uncertainIds.has(id) ||
|
|
1670
|
-
unprovenPrefixes.has(id.replace(/\/[a-f0-9]{64}$/u, "/")));
|
|
1671
|
-
}
|
|
1672
|
-
const stableIds = uncertainMembership
|
|
1673
|
-
? (potentialIds ?? parsed.findings.map((row) => row.source_finding_id)).filter((id) => id === undefined || !uncertainId(id))
|
|
1674
|
-
: undefined;
|
|
1675
|
-
const knownMembership = input.unprovenOccurrenceCount
|
|
1676
|
-
? new Set(stableIds)
|
|
1677
|
-
: undefined;
|
|
1678
|
-
const knownRows = new Map(input.knownFindings?.map((row) => [
|
|
1679
|
-
row.source_finding_id,
|
|
1680
|
-
wireFinding(row),
|
|
1681
|
-
]));
|
|
1682
|
-
let originalInputDigest;
|
|
1683
|
-
const cannotCaptureOriginal = !input.original &&
|
|
1684
|
-
(potentialIds === null || !!(potentialIds?.length || uncertainMembership));
|
|
1685
|
-
const possibleBufferExport = options.provider === "github" && original && !changedCapture;
|
|
1686
|
-
function potentialOriginal(record, fileKey) {
|
|
1687
|
-
const projection = record.inputProjection;
|
|
1688
|
-
if (record.accountId !== credentials.account_id)
|
|
1689
|
-
return false;
|
|
1690
|
-
if (!projection) {
|
|
1691
|
-
// Locale-era requests had no projection. Their scoped occurrence IDs
|
|
1692
|
-
// can stop an opaque retry but cannot authorize replay.
|
|
1693
|
-
if (!cannotCaptureOriginal || record.wireKey !== undefined)
|
|
1694
|
-
return false;
|
|
1695
|
-
}
|
|
1696
|
-
else if (!/^[a-f0-9]{64}$/u.test(projection.inputDigest) ||
|
|
1697
|
-
!/^[a-f0-9]{64}$/u.test(projection.savedEvidenceDigest) ||
|
|
1698
|
-
(projection.identityFormat === 2 && !record.legacyApproval))
|
|
1699
|
-
return false;
|
|
1700
|
-
try {
|
|
1701
|
-
// Older evidence may fail today's limits. Scope and selection can still
|
|
1702
|
-
// identify an outstanding approval and prevent a duplicate submission.
|
|
1703
|
-
if (!matchesSavedDestination(record.requests))
|
|
1704
|
-
return false;
|
|
1705
|
-
const rows = submissionFindings(record.requests);
|
|
1706
|
-
const savedWire = wireJson(rows);
|
|
1707
|
-
const evidenceMatches = projection &&
|
|
1708
|
-
projection.savedEvidenceDigest === hash("sha256", savedWire);
|
|
1709
|
-
if (evidenceMatches) {
|
|
1710
|
-
// Matching old digests reconstruct its scoped filename. A report from
|
|
1711
|
-
// this caller is useful only when the saved digest independently binds it.
|
|
1712
|
-
const reportFree = projection.inputDigest === projection.savedEvidenceDigest;
|
|
1713
|
-
const identity = reportFree
|
|
1714
|
-
? rows
|
|
1715
|
-
: parsed.report !== undefined
|
|
1716
|
-
? { findings: rows, report: reportForJson(parsed.report) }
|
|
1717
|
-
: undefined;
|
|
1718
|
-
if (identity &&
|
|
1719
|
-
(reportFree || projection.inputDigest === jsonDigest(identity))) {
|
|
1720
|
-
if (record.wireKey
|
|
1721
|
-
? record.wireKey !== scopeKey(identity)
|
|
1722
|
-
: fileKey !== scopeKey(identity, canonicalJson) &&
|
|
1723
|
-
fileKey !== localeKey(rows))
|
|
1724
|
-
return false;
|
|
1725
|
-
if (possibleBufferExport &&
|
|
1726
|
-
projection.inputDigest !== inputDigest &&
|
|
1727
|
-
sameLegacyJson(identity, currentIdentity, previousBufferJson)) {
|
|
1728
|
-
return true;
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
if (!record.wireKey &&
|
|
1732
|
-
reportFree &&
|
|
1733
|
-
original &&
|
|
1734
|
-
original.wire !== savedWire)
|
|
1735
|
-
return false;
|
|
1736
|
-
}
|
|
1737
|
-
if (record.wireKey && !cannotCaptureOriginal)
|
|
1738
|
-
return false;
|
|
1739
|
-
if (projection &&
|
|
1740
|
-
original &&
|
|
1741
|
-
fileKey !== stagingKey &&
|
|
1742
|
-
fileKey !== originalWireKey &&
|
|
1743
|
-
projection.inputDigest ===
|
|
1744
|
-
(originalInputDigest ??= jsonDigest(original.identity, canonicalJson)) &&
|
|
1745
|
-
fileKey !== localeKey(original.parsed.findings) &&
|
|
1746
|
-
projection.savedEvidenceDigest ===
|
|
1747
|
-
jsonDigest(original.parsed.findings.map(wireFinding), canonicalJson) &&
|
|
1748
|
-
savedWire === wireJson(original.parsed.findings.map(wireFinding)))
|
|
1749
|
-
return false;
|
|
1750
|
-
if (stableIds) {
|
|
1751
|
-
// An opaque occurrence may have had a different old ID. Compare all
|
|
1752
|
-
// definite members and count the remaining IDs without claiming them.
|
|
1753
|
-
const certain = rows.filter((row) => !uncertainId(row.source_finding_id));
|
|
1754
|
-
const stableSaved = knownMembership
|
|
1755
|
-
? certain.filter((row) => knownMembership.has(row.source_finding_id))
|
|
1756
|
-
: certain;
|
|
1757
|
-
if (certain.length - stableSaved.length >
|
|
1758
|
-
(input.unprovenOccurrenceCount ?? 0))
|
|
1759
|
-
return false;
|
|
1760
|
-
return (rows.length > 0 &&
|
|
1761
|
-
stableSaved.length === stableIds.length &&
|
|
1762
|
-
stableSaved.every((row, i) => {
|
|
1763
|
-
const known = knownRows.get(row.source_finding_id);
|
|
1764
|
-
return (row.source_finding_id === stableIds[i] &&
|
|
1765
|
-
(!known || wireJson(row) === wireJson(known)));
|
|
1766
|
-
}));
|
|
1767
|
-
}
|
|
1768
|
-
const candidates = originalParsed.findings;
|
|
1769
|
-
const ids = potentialIds === undefined
|
|
1770
|
-
? parsed.findings.map((row) => row.source_finding_id)
|
|
1771
|
-
: potentialIds;
|
|
1772
|
-
if (ids &&
|
|
1773
|
-
(!ids.length ||
|
|
1774
|
-
rows.length !== ids.length ||
|
|
1775
|
-
!rows.every((row, i) => ids[i] === undefined || row.source_finding_id === ids[i])))
|
|
1776
|
-
return false;
|
|
1777
|
-
// An opaque serializer can add a report or replace every visible field.
|
|
1778
|
-
// Only scoped, independently known occurrences can rule out its old request.
|
|
1779
|
-
if (cannotCaptureOriginal || !projection)
|
|
1780
|
-
return true;
|
|
1781
|
-
if (projection.inputDigest === projection.savedEvidenceDigest &&
|
|
1782
|
-
parsed.report !== undefined)
|
|
1783
|
-
return false;
|
|
1784
|
-
if (potentialIds === undefined && (hasBoxedScalars || evidenceMatches))
|
|
1785
|
-
return false;
|
|
1786
|
-
return (!sameFindingSelection(rows, candidates) ||
|
|
1787
|
-
rows.every((row, i) => {
|
|
1788
|
-
const { source_data: savedData, ...savedFields } = row.evidence;
|
|
1789
|
-
const { source_data: selectedData, ...selectedFields } = candidates[i].evidence;
|
|
1790
|
-
if (wireJson(savedFields) !== wireJson(selectedFields))
|
|
1791
|
-
return false;
|
|
1792
|
-
// Once the original SDK discarded boxed positions, a plain JSON export
|
|
1793
|
-
// alone cannot attribute a new numeric spelling to that saved request.
|
|
1794
|
-
return sameLegacyJson(savedData, selectedData, (value) => typeof value === "number");
|
|
1795
|
-
}));
|
|
1796
|
-
}
|
|
1797
|
-
catch {
|
|
1798
|
-
return false;
|
|
1799
|
-
}
|
|
821
|
+
async function readCompletedPublication(requests) {
|
|
822
|
+
const bytes = await readOptionalFile(join(state, key + ".result.json"));
|
|
823
|
+
if (bytes === undefined)
|
|
824
|
+
return;
|
|
825
|
+
const result = JSON.parse(bytes);
|
|
826
|
+
if ((result.status === "complete" || result.status === "partial") &&
|
|
827
|
+
result.receipts.length === requests.length &&
|
|
828
|
+
result.receipts.every((r, i) => r.id === requests[i].request_id))
|
|
829
|
+
return {
|
|
830
|
+
receipts: result.receipts.map((r, i) => validatePublicationReceipt(r, requests[i])),
|
|
831
|
+
verified: result.verified,
|
|
832
|
+
};
|
|
1800
833
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
(preparing && fileKey === key ? capturedPending : undefined);
|
|
1817
|
-
if (serialized === undefined) {
|
|
1818
|
-
if (!known.has(fileKey))
|
|
1819
|
-
incomplete = true;
|
|
1820
|
-
return selected;
|
|
1821
|
-
}
|
|
1822
|
-
if (fileKey === stagingKey)
|
|
1823
|
-
stagingPathOccupied = true;
|
|
1824
|
-
let record;
|
|
1825
|
-
try {
|
|
1826
|
-
record = JSON.parse(serialized);
|
|
1827
|
-
}
|
|
1828
|
-
catch (error) {
|
|
1829
|
-
if (known.has(fileKey))
|
|
1830
|
-
throw error;
|
|
1831
|
-
incomplete = true;
|
|
1832
|
-
return selected;
|
|
1833
|
-
}
|
|
1834
|
-
// A migrated checkpoint records the wire identity it belongs to even
|
|
1835
|
-
// when a separate input hashes to its historical filename.
|
|
1836
|
-
const tag = record?.wireKey;
|
|
1837
|
-
const tagged = tag !== undefined;
|
|
1838
|
-
const ownerKey = tagged ? tag : fileKey;
|
|
1839
|
-
const historical = !tagged && fileKey === originalKey && fileKey !== key;
|
|
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
|
-
}
|
|
1860
|
-
if (record &&
|
|
1861
|
-
(!tagged || cannotCaptureOriginal || possibleBufferExport) &&
|
|
1862
|
-
potentialOriginal(record, fileKey))
|
|
1863
|
-
unprovenOriginal = true;
|
|
1864
|
-
// Some early locale filenames carry no deployment identity. Never guess their target.
|
|
1865
|
-
if (!tagged &&
|
|
1866
|
-
record &&
|
|
1867
|
-
!record.inputProjection &&
|
|
1868
|
-
!legacyKeys.has(fileKey)) {
|
|
1869
|
-
try {
|
|
1870
|
-
// A different locale cannot authorize replay, even when the
|
|
1871
|
-
// original native capture proves these rows were selected.
|
|
1872
|
-
if (!original ||
|
|
1873
|
-
wireJson(submissionFindings(readSaved(record).requests)) !==
|
|
1874
|
-
wireJson(original.parsed.findings.map(wireFinding)))
|
|
1875
|
-
validateSaved(record, true);
|
|
1876
|
-
unidentified = true;
|
|
1877
|
-
}
|
|
1878
|
-
catch {
|
|
1879
|
-
/* Unrelated input. */
|
|
1880
|
-
}
|
|
834
|
+
await validatePreparedOutputDir(state, undefined, true).catch(nullIfMissingFile);
|
|
835
|
+
const saved = await readPending();
|
|
836
|
+
if (saved && wasReset(saved)) {
|
|
837
|
+
await underPublishLock(async () => {
|
|
838
|
+
const current = await readPending();
|
|
839
|
+
if (current && sameSubmission(current, saved)) {
|
|
840
|
+
await confirmReset();
|
|
841
|
+
if (record && current.receipts?.length) {
|
|
842
|
+
await record({
|
|
843
|
+
cloudApiUrl,
|
|
844
|
+
accountId: credentials.account_id,
|
|
845
|
+
destination,
|
|
846
|
+
requests: current.requests,
|
|
847
|
+
findings: [],
|
|
848
|
+
}, acknowledgedReceipts(current));
|
|
1881
849
|
}
|
|
1882
|
-
|
|
1883
|
-
}
|
|
1884
|
-
const content = historical
|
|
1885
|
-
? readPreviousNumbers(record)
|
|
1886
|
-
: validateSaved(record);
|
|
1887
|
-
if (content === "different-wire") {
|
|
1888
|
-
// Another spelling may already have a verified checkpoint for this wire value.
|
|
1889
|
-
unprovenOriginal = true;
|
|
1890
|
-
return selected;
|
|
1891
|
-
}
|
|
1892
|
-
if (!content)
|
|
1893
|
-
return selected;
|
|
1894
|
-
if (selected) {
|
|
1895
|
-
const conflict = new CodexSecurityError("Two saved imports match this input. Their original requests and receipts were preserved without uploading.");
|
|
1896
|
-
if (!preparing)
|
|
1897
|
-
throw conflict;
|
|
1898
|
-
// The two unlocked reads may have straddled completion of the first request.
|
|
1899
|
-
return await underLocks([key, selected.fileKey, fileKey], async () => {
|
|
1900
|
-
const first = await readCandidate(selected.fileKey);
|
|
1901
|
-
if (first) {
|
|
1902
|
-
if (await readCandidate(fileKey))
|
|
1903
|
-
throw conflict;
|
|
1904
|
-
if (sameSubmission(first.content, selected.content))
|
|
1905
|
-
return first;
|
|
1906
|
-
}
|
|
1907
|
-
return completedCheckpoint(selected);
|
|
1908
|
-
});
|
|
1909
|
-
}
|
|
1910
|
-
return { fileKey, content, historical };
|
|
1911
|
-
}
|
|
1912
|
-
let selected;
|
|
1913
|
-
for (const fileKey of known)
|
|
1914
|
-
selected = await readCandidate(fileKey, selected);
|
|
1915
|
-
// A known file that disappeared can be checked against its completed receipt.
|
|
1916
|
-
if (!selected && knownFileKey !== undefined && !hosted)
|
|
1917
|
-
return undefined;
|
|
1918
|
-
const hint = await lookupFileKey();
|
|
1919
|
-
if (hint && !known.has(hint)) {
|
|
1920
|
-
const contents = await readOptionalRegularFile(pendingFile(hint));
|
|
1921
|
-
if (contents !== undefined) {
|
|
1922
|
-
selected = await readCandidate(hint, selected, contents);
|
|
1923
|
-
known.add(hint);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
// A released publisher could stage the canonical request while another SDK
|
|
1927
|
-
// tagged its old filename but had not yet written the optional lookup.
|
|
1928
|
-
if (selected &&
|
|
1929
|
-
!cannotCaptureOriginal &&
|
|
1930
|
-
!selected.historical &&
|
|
1931
|
-
(selected.fileKey !== key ||
|
|
1932
|
-
selected.content.canonicalChecked ||
|
|
1933
|
-
selected.content.inputProjection?.identityFormat === 2))
|
|
1934
|
-
return selected;
|
|
1935
|
-
const entries = (await readdir(state, { withFileTypes: true }).catch(nullIfMissingFile)) ?? [];
|
|
1936
|
-
for (const entry of entries) {
|
|
1937
|
-
if (!entry.isFile() || !/^[a-f0-9]{64}\.pending\.json$/u.test(entry.name))
|
|
1938
|
-
continue;
|
|
1939
|
-
const fileKey = entry.name.slice(0, -".pending.json".length);
|
|
1940
|
-
if (!known.has(fileKey))
|
|
1941
|
-
selected = await readCandidate(fileKey, selected);
|
|
1942
|
-
}
|
|
1943
|
-
if (unprovenOriginal && (!selected || cannotCaptureOriginal))
|
|
1944
|
-
throw unmatchedPreviousNumbers();
|
|
1945
|
-
if (!selected && stagingPathOccupied)
|
|
1946
|
-
throw occupiedCheckpoint();
|
|
1947
|
-
if (!selected && unidentified)
|
|
1948
|
-
throw new CodexSecurityError("An older pending import matches this input, but its checkpoint identity could not be established. Resume it using the original deployment and locale before publishing this selection. The saved request was preserved without uploading.");
|
|
1949
|
-
if (selected?.fileKey === key && !preparing && !incomplete)
|
|
1950
|
-
selected.checkedCanonical = true;
|
|
1951
|
-
return selected;
|
|
1952
|
-
}
|
|
1953
|
-
async function readCompletedPublication(requests, observedKey) {
|
|
1954
|
-
for (const resultKey of new Set([key, observedKey])) {
|
|
1955
|
-
const serialized = await readOptionalFile(join(state, `${resultKey}.result.json`));
|
|
1956
|
-
if (serialized === undefined)
|
|
1957
|
-
continue;
|
|
1958
|
-
const completed = JSON.parse(serialized);
|
|
1959
|
-
if ((completed?.status === "complete" || completed?.status === "partial") &&
|
|
1960
|
-
Array.isArray(completed.receipts) &&
|
|
1961
|
-
completed.receipts.length === requests.length &&
|
|
1962
|
-
completed.receipts.every((receipt, i) => receipt?.id === requests[i].request_id))
|
|
1963
|
-
return {
|
|
1964
|
-
receipts: completed.receipts.map((receipt, i) => validatePublicationReceipt(receipt, requests[i])),
|
|
1965
|
-
verified: completed.verified,
|
|
1966
|
-
};
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
async function completedCheckpoint(observed) {
|
|
1970
|
-
if (await readCompletedPublication(observed.content.requests, observed.fileKey))
|
|
1971
|
-
return observed;
|
|
1972
|
-
throw new CodexSecurityError("The saved publication changed while preparing this input. Review it again.");
|
|
1973
|
-
}
|
|
1974
|
-
function occupiedCheckpoint() {
|
|
1975
|
-
return new CodexSecurityError("Finish the other pending import at this checkpoint first, then review this input again.");
|
|
1976
|
-
}
|
|
1977
|
-
let selected = await selectedCheckpoint(recovered ? key : undefined, true);
|
|
1978
|
-
const fileKey = selected?.fileKey ?? (recovered ? key : stagingKey);
|
|
1979
|
-
const pendingPath = pendingFile(fileKey);
|
|
1980
|
-
async function rememberFile() {
|
|
1981
|
-
if (fileKey !== key && (await lookupFileKey()) !== fileKey)
|
|
1982
|
-
await writeAtomicJson(lookupPath, fileKey).catch(() => undefined);
|
|
1983
|
-
}
|
|
1984
|
-
async function removePending() {
|
|
1985
|
-
await rm(pendingPath, { force: true });
|
|
1986
|
-
if (fileKey !== key && (await lookupFileKey()) === fileKey)
|
|
1987
|
-
await rm(lookupPath, { force: true }).catch(() => undefined);
|
|
1988
|
-
}
|
|
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
|
-
}
|
|
2003
|
-
if (selected?.historical) {
|
|
2004
|
-
const observed = selected;
|
|
2005
|
-
selected = await underLocks(lockKeys, async () => {
|
|
2006
|
-
const current = await selectedCheckpoint(fileKey);
|
|
2007
|
-
if (!current ||
|
|
2008
|
-
current.fileKey !== fileKey ||
|
|
2009
|
-
!sameSubmission(current.content, observed.content))
|
|
2010
|
-
return completedCheckpoint(observed);
|
|
2011
|
-
if (current.historical) {
|
|
2012
|
-
current.content.wireKey = key;
|
|
2013
|
-
await writeAtomicJson(pendingPath, current.content);
|
|
2014
|
-
await rememberFile();
|
|
850
|
+
await removePending();
|
|
2015
851
|
}
|
|
2016
|
-
return current;
|
|
2017
852
|
});
|
|
853
|
+
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.");
|
|
2018
854
|
}
|
|
2019
|
-
const saved = selected?.content ?? recovered;
|
|
2020
|
-
if (historicalOnly && !saved)
|
|
2021
|
-
throw unmatchedPreviousNumbers();
|
|
2022
|
-
if (!parsed.findings.length)
|
|
2023
|
-
throw new NoPublishableFindingsError(parsed);
|
|
2024
|
-
if (saved)
|
|
2025
|
-
await retirePendingIfReset(saved, lockKeys, pendingPath, removePending);
|
|
2026
855
|
if (saved?.inspectorProjectMapRequired && !inspectorProjectMap)
|
|
2027
856
|
throw new CodexSecurityError("Supply the verified Inspector project binding again to resume.");
|
|
2028
857
|
// Existing repository submissions keep their original request bodies and receipts.
|
|
2029
858
|
const privatePath = join(state, `${key}.private-import.json`);
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
throw new CodexSecurityError("The saved publication changed. Run the command again to preview this report.");
|
|
859
|
+
const readPrivate = async () => parsePrivateCheckpoint(await readOptionalFile(privatePath));
|
|
860
|
+
const privateSaved = await readPrivate();
|
|
2033
861
|
const usePrivateImport = !saved && (canStartJob || privateSaved !== undefined);
|
|
2034
862
|
async function preparePrivateAttempt() {
|
|
2035
|
-
const context =
|
|
863
|
+
const context = await privateClient.context();
|
|
2036
864
|
if (source.source_key.trim() !== source.source_key)
|
|
2037
865
|
throw new CodexSecurityError("A private source key cannot have leading or trailing whitespace.");
|
|
2038
|
-
const report =
|
|
866
|
+
const report = selectPrivateReport(parsed.findings, source.provider, context, privateSaved?.contextVersion === context.context_version
|
|
867
|
+
? privateSaved.format
|
|
868
|
+
: undefined);
|
|
2039
869
|
const binding = {
|
|
2040
870
|
format: report.format,
|
|
2041
871
|
apiBaseUrl,
|
|
@@ -2055,15 +885,15 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2055
885
|
}
|
|
2056
886
|
// Use an earlier catalog URL only after the account, connector, repository,
|
|
2057
887
|
// inbox context and exact upload digest all match the immutable checkpoint.
|
|
2058
|
-
const
|
|
888
|
+
const privateAttempt = usePrivateImport
|
|
2059
889
|
? await preparePrivateAttempt()
|
|
2060
890
|
: undefined;
|
|
2061
|
-
const previous =
|
|
2062
|
-
readPrivateCheckpoint(privateSaved,
|
|
891
|
+
const previous = privateAttempt &&
|
|
892
|
+
readPrivateCheckpoint(privateSaved, privateAttempt.binding);
|
|
2063
893
|
const retryOfJobId = unsuccessfulJob(previous?.receipt) &&
|
|
2064
894
|
canStartJob &&
|
|
2065
|
-
|
|
2066
|
-
acceptsJob(
|
|
895
|
+
privateAttempt?.context.can_upload &&
|
|
896
|
+
acceptsJob(privateAttempt.context, privateAttempt.report.format)
|
|
2067
897
|
? previous?.jobId
|
|
2068
898
|
: undefined;
|
|
2069
899
|
const resumed = previous !== undefined && retryOfJobId === undefined;
|
|
@@ -2073,63 +903,19 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2073
903
|
privateApproval?.approvedRepositoryPlatform;
|
|
2074
904
|
// The findings-only checkpoint key lets projected and native callers resume one immutable
|
|
2075
905
|
// request. Supplemental report claims are outside that digest and must still match its source.
|
|
2076
|
-
const
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
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
|
-
}))
|
|
906
|
+
const approvedUrl = saved?.approvedRepositoryUrl ??
|
|
907
|
+
saved?.trivyRepositoryUrl ??
|
|
908
|
+
privateUrl ??
|
|
909
|
+
destination.url;
|
|
910
|
+
const sourceFor = (url, platform) => hostedRepositoryMatcher(platform ? { ...report, sourceRepositoryPlatform: platform } : report, options.provider, declaredUrl, { url }, readerSources);
|
|
911
|
+
if (readerSources.some(({ platform, url }) => {
|
|
912
|
+
const source = normalizeHostedGitRepositoryUrl(url, approvedUrl, platform !== undefined);
|
|
913
|
+
return (cloudSourceKey(source, platform) !==
|
|
914
|
+
cloudSourceKey(approvedUrl, platform));
|
|
915
|
+
}))
|
|
2130
916
|
throw new CodexSecurityError("The reader's source repository does not match the selected Cloud repository.");
|
|
2131
|
-
await recheckFileRepository?.(approvedUrl, approvedPlatform);
|
|
2132
|
-
const hostedSource = hosted
|
|
917
|
+
await resolved.recheckFileRepository?.(approvedUrl, approvedPlatform);
|
|
918
|
+
const hostedSource = hosted
|
|
2133
919
|
? sourceFor(approvedUrl, approvedPlatform)
|
|
2134
920
|
: undefined;
|
|
2135
921
|
const matchesHostedRepository = hostedSource?.matches;
|
|
@@ -2141,8 +927,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2141
927
|
throw new CodexSecurityError("The source project does not match the selected Cloud repository.");
|
|
2142
928
|
}
|
|
2143
929
|
requireApprovedSource(approvedUrl);
|
|
2144
|
-
if (legacyTypedUrl)
|
|
2145
|
-
requireApprovedSource(legacyTypedUrl);
|
|
2146
930
|
const trivyTarget = saved?.trivyRepositoryUrl ?? privateUrl ?? destination.url;
|
|
2147
931
|
function requireTrivyRemote(url, id) {
|
|
2148
932
|
if (trivyRemoteKey(url, trivyTarget) !== catalogKey(trivyTarget)) {
|
|
@@ -2150,13 +934,8 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2150
934
|
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
935
|
}
|
|
2152
936
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
requireTrivyRemote(url);
|
|
2156
|
-
if (parsed !== resolved.current)
|
|
2157
|
-
for (const url of trivyBatchSourceUrls(parsed, true))
|
|
2158
|
-
requireTrivyRemote(url);
|
|
2159
|
-
}
|
|
937
|
+
for (const url of trivyReportUrls ?? [])
|
|
938
|
+
requireTrivyRemote(url);
|
|
2160
939
|
function checkRepositories({ findings, report }, historical = Boolean(saved)) {
|
|
2161
940
|
const { provider } = options;
|
|
2162
941
|
checkTrivyReportProvider(provider, report);
|
|
@@ -2183,6 +962,8 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2183
962
|
: key(url) !== key(comparisonUrl)))
|
|
2184
963
|
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.`);
|
|
2185
964
|
}
|
|
965
|
+
if (provider === "armorcode")
|
|
966
|
+
requireDestination("ArmorCode source", declaredUrl);
|
|
2186
967
|
if (report?.["format"] === guardianSelectionFormat)
|
|
2187
968
|
requireDestination("Guardian source", declaredScannerRepositoryUrl(report["repositoryUrl"], "Guardian"));
|
|
2188
969
|
// An immutable retry may refer to an earlier repository name. Additional
|
|
@@ -2221,7 +1002,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2221
1002
|
if (binding)
|
|
2222
1003
|
requireDestination(binding.findingId, binding.url);
|
|
2223
1004
|
}
|
|
2224
|
-
const checkOnlyProjected = !checkNative("blackduck", "inspector", "veracode", "checkmarx", "continuum", "sonar");
|
|
1005
|
+
const checkOnlyProjected = !checkNative("armorcode", "blackduck", "inspector", "veracode", "checkmarx", "continuum", "sonar");
|
|
2225
1006
|
for (const finding of findings) {
|
|
2226
1007
|
const { source_finding_id: id, evidence } = finding;
|
|
2227
1008
|
const guardian = guardianFindingRepository(finding, "cloud");
|
|
@@ -2246,7 +1027,10 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2246
1027
|
checkmarxRepository(finding)?.url,
|
|
2247
1028
|
evidence.details?.repository?.url,
|
|
2248
1029
|
];
|
|
2249
|
-
if (provider === "
|
|
1030
|
+
if (provider === "armorcode") {
|
|
1031
|
+
urls.push(armorCodeRepositoryUrl(evidence.source_data, "cloud"));
|
|
1032
|
+
}
|
|
1033
|
+
else if (provider === "wiz") {
|
|
2250
1034
|
const native = hasProjection ||
|
|
2251
1035
|
(!historical && isWizPackageFinding(evidence.source_data));
|
|
2252
1036
|
urls.push(native
|
|
@@ -2279,46 +1063,11 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2279
1063
|
throw new CodexSecurityError("Snyk REST evidence requires the snyk provider.");
|
|
2280
1064
|
}
|
|
2281
1065
|
}
|
|
2282
|
-
if (!
|
|
1066
|
+
if (!privateAttempt)
|
|
2283
1067
|
checkRepositories(parsed);
|
|
2284
|
-
|
|
2285
|
-
if (saved) {
|
|
2286
|
-
// Only use the report associated with the input digest in the saved checkpoint.
|
|
2287
|
-
const report = saved.inputProjection?.inputDigest === inputDigest
|
|
2288
|
-
? parsed.report
|
|
2289
|
-
: undefined;
|
|
2290
|
-
checkRepositories({ findings: submissionFindings(saved.requests), report });
|
|
2291
|
-
}
|
|
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) {
|
|
1068
|
+
if (privateAttempt) {
|
|
2320
1069
|
const client = privateClient;
|
|
2321
|
-
const { context, report, binding } =
|
|
1070
|
+
const { context, report, binding } = privateAttempt;
|
|
2322
1071
|
function requireAccess(value, saved) {
|
|
2323
1072
|
if (!value.can_read ||
|
|
2324
1073
|
(!saved && !canStartJob) ||
|
|
@@ -2346,41 +1095,32 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2346
1095
|
requests: [],
|
|
2347
1096
|
privateImport,
|
|
2348
1097
|
};
|
|
2349
|
-
return {
|
|
1098
|
+
return withReceipts(preview, {
|
|
2350
1099
|
preview: structuredClone(preview),
|
|
2351
|
-
publish: () =>
|
|
1100
|
+
publish: () => underPublishLock(async () => {
|
|
2352
1101
|
const current = await client.context();
|
|
2353
1102
|
if (current.context_version !== binding.contextVersion)
|
|
2354
1103
|
throw new CodexSecurityError("The private inbox changed. Run the command again to review the new destination.");
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
if (!stored &&
|
|
2358
|
-
(resumingPreviousReader ||
|
|
2359
|
-
(privateUrl && privateUrl !== destination.url)))
|
|
1104
|
+
const stored = readPrivateCheckpoint(await readPrivate(), binding);
|
|
1105
|
+
if (previous && !stored)
|
|
2360
1106
|
throw new CodexSecurityError("The saved private import changed. Run the command again to preview this report.");
|
|
2361
1107
|
// Only a preview of this terminal job can start a new attempt.
|
|
2362
1108
|
const retrying = retryOfJobId !== undefined && stored?.receipt?.id === retryOfJobId;
|
|
2363
1109
|
const active = retrying ? undefined : stored;
|
|
2364
|
-
if (resumed && !active)
|
|
2365
|
-
checkRepositories(parsed);
|
|
2366
1110
|
requireAccess(current, active);
|
|
2367
|
-
if (await
|
|
1111
|
+
if (await readPending())
|
|
2368
1112
|
throw new CodexSecurityError("A repository submission is pending. Review its saved request before continuing.");
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
receipt: undefined,
|
|
2381
|
-
previousReceipt: retrying ? stored?.receipt : undefined,
|
|
2382
|
-
}),
|
|
2383
|
-
jobApiVersion: stored?.jobApiVersion ?? jobApiVersion,
|
|
1113
|
+
const checkpoint = active ?? {
|
|
1114
|
+
...binding,
|
|
1115
|
+
approvedRepositoryUrl: destination.url,
|
|
1116
|
+
approvedRepositoryPlatform: hostedSource?.github === false ? "other" : undefined,
|
|
1117
|
+
uploadRequestId: randomUUID(),
|
|
1118
|
+
jobRequestId: randomUUID(),
|
|
1119
|
+
jobApiVersion: retrying ? stored?.jobApiVersion : jobApiVersion,
|
|
1120
|
+
fileId: undefined,
|
|
1121
|
+
jobId: undefined,
|
|
1122
|
+
receipt: undefined,
|
|
1123
|
+
previousReceipt: retrying ? stored?.receipt : undefined,
|
|
2384
1124
|
};
|
|
2385
1125
|
const result = {
|
|
2386
1126
|
cloudApiUrl: preview.cloudApiUrl,
|
|
@@ -2420,7 +1160,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2420
1160
|
const savedReceipt = checkpoint.receipt ?? checkpoint.previousReceipt;
|
|
2421
1161
|
if (savedReceipt)
|
|
2422
1162
|
acknowledge(savedReceipt);
|
|
2423
|
-
if (!active
|
|
1163
|
+
if (!active)
|
|
2424
1164
|
await writeAtomicJson(privatePath, checkpoint);
|
|
2425
1165
|
if (!checkpoint.fileId) {
|
|
2426
1166
|
progress({ phase: "uploading", completed: 0 });
|
|
@@ -2460,13 +1200,11 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2460
1200
|
throw new ExternalPublicationError(result.error, result, error);
|
|
2461
1201
|
}
|
|
2462
1202
|
}),
|
|
2463
|
-
};
|
|
1203
|
+
});
|
|
2464
1204
|
}
|
|
2465
1205
|
// The original selection and request bytes govern a retry even if discovery changes.
|
|
2466
|
-
const severities = saved
|
|
2467
|
-
|
|
2468
|
-
: repositorySeverities;
|
|
2469
|
-
const direct = repositorySelection(parsed, severities, input.sourcePositions);
|
|
1206
|
+
const severities = saved ? saved.repositorySeverities : repositorySeverities;
|
|
1207
|
+
const direct = repositorySelection(parsed, severities, resolved.sourcePositions);
|
|
2470
1208
|
if (!direct.findings.length)
|
|
2471
1209
|
throw new NoPublishableFindingsError(direct);
|
|
2472
1210
|
let requests = saved?.requests;
|
|
@@ -2557,23 +1295,12 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2557
1295
|
...(trivyReportUrls && { trivyRepositoryUrl: trivyTarget }),
|
|
2558
1296
|
requests,
|
|
2559
1297
|
receipts: saved?.receipts,
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
...(scopedSemgrepReport && { retainedHostedSelection: true }),
|
|
2566
|
-
...(bindSemgrepScope && {
|
|
2567
|
-
semgrepPartialScopeDigest: suppliedSemgrepScopeDigest(),
|
|
2568
|
-
}),
|
|
2569
|
-
inputDigest,
|
|
2570
|
-
savedEvidenceDigest: jsonDigest(submissionFindings(requests)),
|
|
2571
|
-
},
|
|
1298
|
+
repositorySeverities: severities,
|
|
1299
|
+
semgrepPartialScopeDigest: bindSemgrepScope
|
|
1300
|
+
? suppliedSemgrepScopeDigest()
|
|
1301
|
+
: saved?.semgrepPartialScopeDigest,
|
|
1302
|
+
approvedRepositoryUrl: hosted ? approvedUrl : undefined,
|
|
2572
1303
|
};
|
|
2573
|
-
if (hosted &&
|
|
2574
|
-
(!saved || saved.approvedRepositoryUrl || matchesHostedRepository))
|
|
2575
|
-
submission.approvedRepositoryUrl =
|
|
2576
|
-
saved?.approvedRepositoryUrl ?? approvedUrl;
|
|
2577
1304
|
if (saved?.approvedRepositoryPlatform ||
|
|
2578
1305
|
(hostedSource && !hostedSource.github))
|
|
2579
1306
|
submission.approvedRepositoryPlatform = "other";
|
|
@@ -2590,9 +1317,9 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2590
1317
|
resumed: saved !== undefined,
|
|
2591
1318
|
requests,
|
|
2592
1319
|
};
|
|
2593
|
-
return {
|
|
1320
|
+
return withReceipts(preview, {
|
|
2594
1321
|
preview: cloneImportPreview(preview),
|
|
2595
|
-
async publish() {
|
|
1322
|
+
async publish(beforeRetire) {
|
|
2596
1323
|
progress({ phase: "waiting", completed: 0 });
|
|
2597
1324
|
const result = (acknowledged, verified) => {
|
|
2598
1325
|
const counts = { created: 0, updated: 0, unchanged: 0, error: 0 };
|
|
@@ -2632,28 +1359,22 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2632
1359
|
function interruptedPreview(message, cause, savedSubmission) {
|
|
2633
1360
|
// The expected file is gone or another publisher owns the lock. Use only
|
|
2634
1361
|
// the acknowledgements this caller saw when it prepared the request.
|
|
2635
|
-
const known = submission.receipts ?? [];
|
|
2636
|
-
if (known.length > submission.requests.length)
|
|
2637
|
-
throw new CodexSecurityError("Saved publication has more receipts than requests.");
|
|
2638
|
-
const acknowledged = known.map((receipt, index) => validatePublicationReceipt(receipt, submission.requests[index]));
|
|
2639
1362
|
return new ExternalPublicationError(message, {
|
|
2640
|
-
...result(
|
|
1363
|
+
...result(acknowledgedReceipts(submission), 0),
|
|
2641
1364
|
status: "interrupted",
|
|
2642
1365
|
error: message,
|
|
2643
1366
|
...(savedSubmission === undefined ? {} : { savedSubmission }),
|
|
2644
1367
|
}, cause);
|
|
2645
1368
|
}
|
|
2646
1369
|
let acquired = false;
|
|
2647
|
-
return await
|
|
1370
|
+
return await underPublishLock(async () => {
|
|
2648
1371
|
acquired = true;
|
|
2649
|
-
await assertNoAlternateCheckpoint();
|
|
2650
1372
|
// Re-read under the lock to keep checkpoints from another publisher.
|
|
2651
|
-
|
|
1373
|
+
let pending = await readPending().catch((error) => {
|
|
2652
1374
|
if (!submission.receipts?.length)
|
|
2653
1375
|
throw error;
|
|
2654
1376
|
throw interruptedPreview(errorMessage(error), error);
|
|
2655
1377
|
});
|
|
2656
|
-
let pending = selected?.content;
|
|
2657
1378
|
const current = pending ?? submission;
|
|
2658
1379
|
const adoptProjectMap = submission.inspectorProjectMapRequired &&
|
|
2659
1380
|
current.inspectorProjectMapRequired === undefined;
|
|
@@ -2661,25 +1382,20 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2661
1382
|
current.inspectorProjectMapRequired = true;
|
|
2662
1383
|
if (current.approvedRepositoryUrl)
|
|
2663
1384
|
requireApprovedSource(current.approvedRepositoryUrl, current.approvedRepositoryPlatform);
|
|
2664
|
-
if (!
|
|
2665
|
-
|
|
2666
|
-
selected.historical ||
|
|
2667
|
-
!sameSubmission(current, submission)) {
|
|
2668
|
-
const message = selected
|
|
1385
|
+
if (!pending || !sameSubmission(current, submission)) {
|
|
1386
|
+
const message = pending
|
|
2669
1387
|
? "Another publication prepared this input. Run the command again to review and resume that saved request."
|
|
2670
1388
|
: "The saved publication changed after preview. Review its result before publishing again.";
|
|
2671
1389
|
if (saved) {
|
|
2672
|
-
const completed = await readCompletedPublication(requests
|
|
1390
|
+
const completed = await readCompletedPublication(requests);
|
|
2673
1391
|
if (completed)
|
|
2674
1392
|
return result(completed.receipts, completed.verified);
|
|
2675
1393
|
throw interruptedPreview(message);
|
|
2676
1394
|
}
|
|
2677
|
-
if (
|
|
1395
|
+
if (pending)
|
|
2678
1396
|
throw new CodexSecurityError(message);
|
|
2679
1397
|
if ((await readOptionalFile(privatePath)) !== undefined)
|
|
2680
1398
|
throw new CodexSecurityError("A private import already owns this selection. Review its saved job before continuing.");
|
|
2681
|
-
if ((await readOptionalFile(pendingPath)) !== undefined)
|
|
2682
|
-
throw occupiedCheckpoint();
|
|
2683
1399
|
}
|
|
2684
1400
|
// A preview can pin the catalog URL. Tighten its SCM comparison only
|
|
2685
1401
|
// once the caller confirms publication, including when resuming a request.
|
|
@@ -2693,36 +1409,10 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2693
1409
|
const acknowledged = [];
|
|
2694
1410
|
let verified = 0;
|
|
2695
1411
|
try {
|
|
2696
|
-
if (
|
|
2697
|
-
current.canonicalChecked = true;
|
|
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) {
|
|
1412
|
+
if (!pending || adoptProjectMap || adoptStrictRepository) {
|
|
2719
1413
|
await writeAtomicJson(pendingPath, current);
|
|
1414
|
+
pending = current;
|
|
2720
1415
|
}
|
|
2721
|
-
else if (selected?.checkedCanonical) {
|
|
2722
|
-
// The existing approval and receipts are usable if caching the scan fails.
|
|
2723
|
-
await writeAtomicJson(pendingPath, current).catch(() => undefined);
|
|
2724
|
-
}
|
|
2725
|
-
await rememberFile();
|
|
2726
1416
|
progress({
|
|
2727
1417
|
phase: "uploading",
|
|
2728
1418
|
completed: 0,
|
|
@@ -2743,8 +1433,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2743
1433
|
// Acknowledged batches must not consume another POST quota on retry.
|
|
2744
1434
|
// Readback can still resume after this checkpoint without replaying writes.
|
|
2745
1435
|
await writeAtomicJson(pendingPath, {
|
|
2746
|
-
...
|
|
2747
|
-
canonicalChecked: current.canonicalChecked,
|
|
1436
|
+
...current,
|
|
2748
1437
|
receipts: acknowledged,
|
|
2749
1438
|
});
|
|
2750
1439
|
}
|
|
@@ -2779,7 +1468,7 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2779
1468
|
report.repo_id !== destination.id ||
|
|
2780
1469
|
report.repo_connector_id !== destination.repo_connector_id ||
|
|
2781
1470
|
report.environment_id !== batch.repository.environment_id ||
|
|
2782
|
-
|
|
1471
|
+
canonicalJson(report.source) !== canonicalJson(source))
|
|
2783
1472
|
throw new CodexSecurityError("Cloud readback did not match the saved finding identity.");
|
|
2784
1473
|
progress({
|
|
2785
1474
|
phase: "verifying",
|
|
@@ -2792,13 +1481,21 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2792
1481
|
...completed,
|
|
2793
1482
|
report: reportForJson(completed.report),
|
|
2794
1483
|
});
|
|
1484
|
+
await beforeRetire?.(completed);
|
|
2795
1485
|
await removePending();
|
|
2796
1486
|
return completed;
|
|
2797
1487
|
}
|
|
2798
1488
|
catch (error) {
|
|
2799
1489
|
if (error instanceof CloudImportError && error.status === 409) {
|
|
2800
|
-
|
|
2801
|
-
|
|
1490
|
+
try {
|
|
1491
|
+
await beforeRetire?.(result(acknowledged, verified));
|
|
1492
|
+
await removePending();
|
|
1493
|
+
pending = undefined;
|
|
1494
|
+
}
|
|
1495
|
+
catch (recordError) {
|
|
1496
|
+
// Keep acknowledged batches resumable when their receipts are not durable.
|
|
1497
|
+
error = recordError;
|
|
1498
|
+
}
|
|
2802
1499
|
}
|
|
2803
1500
|
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."}`;
|
|
2804
1501
|
throw new ExternalPublicationError(message, {
|
|
@@ -2817,6 +1514,6 @@ async function preparePublicationInput(supplied, options, dependencies, readerSo
|
|
|
2817
1514
|
throw interruptedPreview(message, error, saved ? pendingPath : undefined);
|
|
2818
1515
|
});
|
|
2819
1516
|
},
|
|
2820
|
-
};
|
|
1517
|
+
});
|
|
2821
1518
|
}
|
|
2822
1519
|
//# sourceMappingURL=external-findings-publish.js.map
|