@openai/codex-security 0.8.3 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -151
- package/_bundled_plugin/.mcp.json +5 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +71 -7
- package/_bundled_plugin/scripts/workbench_cli.py +30 -12
- package/_bundled_plugin/scripts/workbench_constants.py +10 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +369 -137
- package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
- package/_bundled_plugin/scripts/workbench_progress.py +10 -1
- package/_bundled_plugin/scripts/workbench_publication.py +14 -10
- package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
- package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
- package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +13 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +127 -56
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
- package/_bundled_plugin/shared/workbench-migrations.json +34 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/dist/api.d.ts +39 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +774 -292
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -6
- package/dist/auth.js.map +1 -1
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +35 -20
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +2 -4
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +11 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1734 -1238
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +27 -2
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +100 -66
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +80 -12
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +483 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +2 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +25 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +3 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +1 -1
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +28 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +103 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +7 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +7 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +337 -89
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +8 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1318 -258
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +20 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +148 -66
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +42 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +5 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +23 -9
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +15 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +55 -30
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/hosted-scanner-v1.d.ts +6 -0
- package/dist/hosted-scanner-v1.d.ts.map +1 -0
- package/dist/hosted-scanner-v1.js +60 -0
- package/dist/hosted-scanner-v1.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +47 -65
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +68 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +1 -1
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +1 -2
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +138 -65
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +1 -0
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +17 -13
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +97 -2
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +58 -34
- package/dist/private-finding-import.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +8 -1
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/reader-selection.d.ts +2 -0
- package/dist/reader-selection.d.ts.map +1 -1
- package/dist/reader-selection.js +8 -0
- package/dist/reader-selection.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -7
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +313 -110
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +18 -15
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +60 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +6 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +75 -42
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +22 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +9 -19
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +106 -77
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +20 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +200 -8
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +107 -43
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +207 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +983 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/semgrep-platform-v1.d.ts +6 -0
- package/dist/semgrep-platform-v1.d.ts.map +1 -0
- package/dist/semgrep-platform-v1.js +83 -0
- package/dist/semgrep-platform-v1.js.map +1 -0
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +7 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +93 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +76 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +1051 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-rest-v1.d.ts +28 -0
- package/dist/snyk-rest-v1.d.ts.map +1 -0
- package/dist/snyk-rest-v1.js +132 -0
- package/dist/snyk-rest-v1.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +2 -4
- package/dist/sonar-import.js.map +1 -1
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +2 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +56 -20
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +9 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +435 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +2 -0
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +49 -11
- package/dist/veracode-findings.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +4 -0
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +57 -3
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +497 -550
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +66 -39
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +50 -42
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +18 -15
- package/schemas/external-findings.schema.json +3 -1
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
|
@@ -55,7 +55,12 @@ from finalize_scan_contract import (
|
|
|
55
55
|
)
|
|
56
56
|
from finding_preview import bounded_finding_details
|
|
57
57
|
from workbench import handoff
|
|
58
|
-
from workbench.storage import
|
|
58
|
+
from workbench.storage import (
|
|
59
|
+
create_private_directory,
|
|
60
|
+
resolve_scan_root,
|
|
61
|
+
saved_deep_workers,
|
|
62
|
+
state_dir,
|
|
63
|
+
)
|
|
59
64
|
from workbench_cli import parse_args
|
|
60
65
|
from workbench_constants import (
|
|
61
66
|
ARTIFACTS,
|
|
@@ -63,13 +68,13 @@ from workbench_constants import (
|
|
|
63
68
|
DELIVERED_ACTION_LEASE_SECONDS,
|
|
64
69
|
FINDING_ABSOLUTE_PATH_BYTES,
|
|
65
70
|
FINDING_LEVEL_BYTES,
|
|
71
|
+
FINDING_LOCATION_ORDER_SQL,
|
|
66
72
|
FINDING_LOCATION_PATH_BYTES,
|
|
67
73
|
FINDING_LOCATION_ROLE_BYTES,
|
|
68
74
|
FINDING_LOCATIONS_LIMIT,
|
|
69
75
|
FINDING_REMEDIATION_BYTES,
|
|
70
76
|
FINDING_SUMMARY_BYTES,
|
|
71
77
|
FINDING_TITLE_BYTES,
|
|
72
|
-
FINDINGS_PAGE_MAX,
|
|
73
78
|
FINDINGS_RESULT_LIMIT,
|
|
74
79
|
PATCH_PREVIEW_BYTES,
|
|
75
80
|
SQLITE_RETRY_ATTEMPTS,
|
|
@@ -80,6 +85,7 @@ from workbench_finding_workflows import finding_workflow, register_workflow_scan
|
|
|
80
85
|
from workbench_scan_start import (
|
|
81
86
|
archive_scan,
|
|
82
87
|
insert_running_scan,
|
|
88
|
+
loaded_plugin_version,
|
|
83
89
|
safe_segment,
|
|
84
90
|
scan_diff_identity,
|
|
85
91
|
scan_target_identity,
|
|
@@ -139,6 +145,7 @@ from workbench_validation import (
|
|
|
139
145
|
optional_text,
|
|
140
146
|
parse_scan_cost,
|
|
141
147
|
path_within_scope,
|
|
148
|
+
read_json_object,
|
|
142
149
|
reject_non_finite_json,
|
|
143
150
|
require_close_note,
|
|
144
151
|
require_occurrence,
|
|
@@ -168,6 +175,7 @@ def database_path() -> Path:
|
|
|
168
175
|
|
|
169
176
|
@contextmanager
|
|
170
177
|
def scan_completion_lock(scan_id: str) -> Any:
|
|
178
|
+
"""Hold the cross-process lock for a scan ID until the context exits."""
|
|
171
179
|
lock_dir = state_dir() / "completion-locks"
|
|
172
180
|
create_private_directory(lock_dir)
|
|
173
181
|
lock_path = lock_dir / f"{require_uuid(scan_id, 'scan-id')}.lock"
|
|
@@ -231,6 +239,20 @@ def release_completion_file_lock(descriptor: int) -> None:
|
|
|
231
239
|
|
|
232
240
|
|
|
233
241
|
def connect(*, deferred: bool = False) -> sqlite3.Connection:
|
|
242
|
+
"""Open the workbench SQLite database and bring its schema up to date.
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
deferred (bool): Let the first migration attempt defer its write lock.
|
|
246
|
+
Retries after lock contention use an immediate transaction.
|
|
247
|
+
|
|
248
|
+
Returns:
|
|
249
|
+
sqlite3.Connection: A caller-owned connection with named rows, foreign
|
|
250
|
+
keys enabled, and write-ahead logging.
|
|
251
|
+
|
|
252
|
+
Raises:
|
|
253
|
+
sqlite3.OperationalError: Opening or configuring the database fails, or
|
|
254
|
+
lock contention persists after retries.
|
|
255
|
+
"""
|
|
234
256
|
path = database_path()
|
|
235
257
|
guidance = (
|
|
236
258
|
f"Workbench database: {path}. Ensure the state directory and SQLite journal files "
|
|
@@ -282,11 +304,13 @@ def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
|
|
|
282
304
|
|
|
283
305
|
|
|
284
306
|
def requested_finding_scope(scan: sqlite3.Row) -> list[tuple[str, bool]]:
|
|
307
|
+
"""Return requested paths paired with whether the stored recipe identified each one as a file."""
|
|
285
308
|
files = {PurePosixPath(path) for path in requested_scan_file_paths(scan)}
|
|
286
309
|
return [(path, PurePosixPath(path) in files) for path in requested_scan_paths(scan)]
|
|
287
310
|
|
|
288
311
|
|
|
289
312
|
def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
|
|
313
|
+
"""Return the target identity, scope requirements, and diff target recorded for this scan."""
|
|
290
314
|
target = Path(scan["target_path"])
|
|
291
315
|
target_contract = {
|
|
292
316
|
"allowedKinds": expected_target_kinds(scan),
|
|
@@ -319,6 +343,7 @@ def scan_contract(scan: sqlite3.Row) -> dict[str, Any]:
|
|
|
319
343
|
|
|
320
344
|
|
|
321
345
|
def expected_coverage_mode(scan: sqlite3.Row) -> str:
|
|
346
|
+
"""Return the coverage mode implied by the recorded scope, scan mode, and diff target kind."""
|
|
322
347
|
if scan["mode"] == "diff":
|
|
323
348
|
mode = {
|
|
324
349
|
"commit": "commit",
|
|
@@ -340,14 +365,10 @@ def expected_coverage_mode(scan: sqlite3.Row) -> str:
|
|
|
340
365
|
def workbench_completion_binding(
|
|
341
366
|
scan: sqlite3.Row, completed_at: str, manifest: dict[str, Any] | None = None
|
|
342
367
|
) -> dict[str, Any]:
|
|
368
|
+
"""Build the scan ID, timestamps, producer, target, and scope used to bind output artifacts at completion."""
|
|
343
369
|
contract = scan_contract(scan)
|
|
344
370
|
target_contract = contract["target"]
|
|
345
|
-
|
|
346
|
-
Path(__file__).resolve().parent.parent / ".codex-plugin" / "plugin.json"
|
|
347
|
-
)
|
|
348
|
-
plugin_version = plugin_manifest.get("version")
|
|
349
|
-
if not isinstance(plugin_version, str) or not plugin_version:
|
|
350
|
-
raise SystemExit("plugin.json: expected a nonempty Codex Security plugin version.")
|
|
371
|
+
plugin_version = loaded_plugin_version()
|
|
351
372
|
target: dict[str, Any] = {
|
|
352
373
|
"targetId": target_contract["targetId"],
|
|
353
374
|
"displayName": target_contract["displayName"],
|
|
@@ -382,6 +403,7 @@ def workbench_completion_binding(
|
|
|
382
403
|
|
|
383
404
|
|
|
384
405
|
def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None:
|
|
406
|
+
"""Raise SystemExit if the supplied manifest does not match the registered scan, target, or scope."""
|
|
385
407
|
manifest_scan = manifest.get("scan")
|
|
386
408
|
if not isinstance(manifest_scan, dict):
|
|
387
409
|
raise SystemExit("scan-manifest.json scan must be an object.")
|
|
@@ -469,6 +491,10 @@ def require_scan(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Row:
|
|
|
469
491
|
|
|
470
492
|
|
|
471
493
|
def resolve_scan_id(connection: sqlite3.Connection, scan_id: str) -> str:
|
|
494
|
+
"""Return a canonical UUID or resolve a unique scan ID prefix of at least eight characters.
|
|
495
|
+
|
|
496
|
+
Raise SystemExit for a prefix that is too short, ambiguous, or absent from the database.
|
|
497
|
+
"""
|
|
472
498
|
try:
|
|
473
499
|
return str(uuid.UUID(scan_id))
|
|
474
500
|
except ValueError:
|
|
@@ -614,7 +640,9 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
614
640
|
|
|
615
641
|
def scan_target_root(scan_root: str | None, target: Path) -> Path:
|
|
616
642
|
root = resolve_scan_root(scan_root)
|
|
617
|
-
target_root =
|
|
643
|
+
target_root = root / safe_segment(target.name)
|
|
644
|
+
if os.name != "nt":
|
|
645
|
+
target_root = target_root.resolve()
|
|
618
646
|
if target_root == target or target in target_root.parents:
|
|
619
647
|
raise SystemExit("The scan artifact directory must be outside the selected target.")
|
|
620
648
|
return target_root
|
|
@@ -659,7 +687,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
659
687
|
(workspace["id"],),
|
|
660
688
|
).fetchone()
|
|
661
689
|
if active is not None:
|
|
662
|
-
return workspace_state(connection, workspace["id"])
|
|
690
|
+
return workspace_state(connection, workspace["id"], result_scan_id=active["id"])
|
|
663
691
|
workspace_version = workspace["updated_at"]
|
|
664
692
|
scan_id = str(uuid.uuid4())
|
|
665
693
|
timestamp = now()
|
|
@@ -694,7 +722,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
694
722
|
diff_target_kind=diff_target["kind"] if diff_target is not None else None,
|
|
695
723
|
)
|
|
696
724
|
target_root = scan_target_root(args.scan_root, target)
|
|
697
|
-
create_private_directory(target_root)
|
|
725
|
+
create_private_directory(target_root, scan_output=True)
|
|
698
726
|
require_working_tree_unchanged(target, diff_target)
|
|
699
727
|
if manages_transaction:
|
|
700
728
|
connection.execute("BEGIN IMMEDIATE")
|
|
@@ -710,7 +738,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
710
738
|
if active is not None:
|
|
711
739
|
if manages_transaction:
|
|
712
740
|
connection.commit()
|
|
713
|
-
return workspace_state(connection, workspace["id"])
|
|
741
|
+
return workspace_state(connection, workspace["id"], result_scan_id=active["id"])
|
|
714
742
|
if workspace["updated_at"] != workspace_version:
|
|
715
743
|
raise SystemExit("Codex Security setup changed while the scan was starting. Try again.")
|
|
716
744
|
current_target = require_remediation_target(str(target))
|
|
@@ -756,7 +784,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
756
784
|
if manages_transaction:
|
|
757
785
|
connection.rollback()
|
|
758
786
|
raise
|
|
759
|
-
return workspace_state(connection, workspace["id"])
|
|
787
|
+
return workspace_state(connection, workspace["id"], result_scan_id=scan_id)
|
|
760
788
|
|
|
761
789
|
|
|
762
790
|
def _start_prompt_driven_scan(
|
|
@@ -828,7 +856,8 @@ def _start_prompt_driven_scan(
|
|
|
828
856
|
"""
|
|
829
857
|
SELECT scans.* FROM scans
|
|
830
858
|
JOIN workspaces ON workspaces.active_scan_id = scans.id
|
|
831
|
-
WHERE
|
|
859
|
+
WHERE COALESCE(scans.continuation_thread_id, workspaces.thread_id) = ?
|
|
860
|
+
AND scans.recipe_json IS NULL AND workspaces.target_path = ?
|
|
832
861
|
AND workspaces.default_scope = ? AND workspaces.default_mode = ?
|
|
833
862
|
AND workspaces.user_context IS ? AND workspaces.target_summary IS ?
|
|
834
863
|
AND workspaces.diff_target_kind IS ? AND workspaces.diff_base_revision IS ?
|
|
@@ -841,7 +870,7 @@ def _start_prompt_driven_scan(
|
|
|
841
870
|
(? = 0 AND scans.handoff_claim_token IS NULL)
|
|
842
871
|
OR (
|
|
843
872
|
? = 1 AND scans.handoff_claim_token IS NOT NULL
|
|
844
|
-
AND scans.continuation_thread_id =
|
|
873
|
+
AND scans.continuation_thread_id = workspaces.thread_id
|
|
845
874
|
)
|
|
846
875
|
)
|
|
847
876
|
ORDER BY scans.updated_at DESC, scans.started_at DESC, scans.id LIMIT 1
|
|
@@ -857,16 +886,15 @@ def _start_prompt_driven_scan(
|
|
|
857
886
|
*target_identity,
|
|
858
887
|
int(headless_standard),
|
|
859
888
|
int(headless_standard),
|
|
860
|
-
thread_id,
|
|
861
889
|
),
|
|
862
890
|
).fetchone()
|
|
863
891
|
if existing is not None:
|
|
864
892
|
connection.commit()
|
|
865
893
|
return {
|
|
866
|
-
**scan_context(connection, existing["id"]),
|
|
894
|
+
**scan_context(connection, existing["id"], model_thread_id=thread_id),
|
|
867
895
|
"startDisposition": "joined",
|
|
868
896
|
}
|
|
869
|
-
create_private_directory(target_root)
|
|
897
|
+
create_private_directory(target_root, scan_output=True)
|
|
870
898
|
workspace_id = str(uuid.uuid4())
|
|
871
899
|
scan_id = str(uuid.uuid4())
|
|
872
900
|
timestamp = now()
|
|
@@ -940,6 +968,7 @@ def _start_prompt_driven_scan(
|
|
|
940
968
|
|
|
941
969
|
|
|
942
970
|
def scan_local_file_digest(scan_dir: Path, relative_path: str) -> str:
|
|
971
|
+
"""Return the SHA-256 of the scan-local file contents, prefixed with sha256:."""
|
|
943
972
|
digest = hashlib.sha256()
|
|
944
973
|
with open_scan_local_file(scan_dir, relative_path) as source:
|
|
945
974
|
for chunk in iter(lambda: source.read(1024 * 1024), b""):
|
|
@@ -948,6 +977,7 @@ def scan_local_file_digest(scan_dir: Path, relative_path: str) -> str:
|
|
|
948
977
|
|
|
949
978
|
|
|
950
979
|
def published_manifest_digest(scan_dir: Path, manifest: dict[str, Any]) -> str:
|
|
980
|
+
"""Return the canonical manifest digest or raise SystemExit if the published bytes differ."""
|
|
951
981
|
canonical = (json.dumps(manifest, allow_nan=False, indent=2, sort_keys=True) + "\n").encode()
|
|
952
982
|
expected = f"sha256:{hashlib.sha256(canonical).hexdigest()}"
|
|
953
983
|
actual = scan_local_file_digest(scan_dir, ARTIFACTS["manifest"])
|
|
@@ -957,6 +987,7 @@ def published_manifest_digest(scan_dir: Path, manifest: dict[str, Any]) -> str:
|
|
|
957
987
|
|
|
958
988
|
|
|
959
989
|
def require_recorded_manifest_digest(scan: sqlite3.Row, scan_dir: Path) -> None:
|
|
990
|
+
"""Raise SystemExit if the saved manifest differs from the digest recorded when the scan was sealed."""
|
|
960
991
|
expected = scan["seal_manifest_digest"]
|
|
961
992
|
if expected is None:
|
|
962
993
|
return
|
|
@@ -967,6 +998,7 @@ def require_recorded_manifest_digest(scan: sqlite3.Row, scan_dir: Path) -> None:
|
|
|
967
998
|
def pin_legacy_manifest_digest(
|
|
968
999
|
connection: sqlite3.Connection, scan_id: str, manifest_digest: str
|
|
969
1000
|
) -> None:
|
|
1001
|
+
"""Record a previously missing digest in a write transaction, rejecting a conflict with an existing digest."""
|
|
970
1002
|
connection.execute("BEGIN IMMEDIATE")
|
|
971
1003
|
with connection:
|
|
972
1004
|
scan = require_scan(connection, scan_id)
|
|
@@ -997,9 +1029,24 @@ def complete_scan(
|
|
|
997
1029
|
prepare_only=prepare_only,
|
|
998
1030
|
thread_id=getattr(args, "thread_id", None),
|
|
999
1031
|
turn_id=getattr(args, "turn_id", None),
|
|
1032
|
+
model_thread_id=getattr(args, "model_thread_id", None),
|
|
1000
1033
|
)
|
|
1001
1034
|
|
|
1002
1035
|
|
|
1036
|
+
def read_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1037
|
+
# Validation can finish after the scan's recorded completion timestamp.
|
|
1038
|
+
usage = scan_usage.collect_scan_usage(
|
|
1039
|
+
connection,
|
|
1040
|
+
require_scan(connection, args.scan_id),
|
|
1041
|
+
thread_id=args.thread_id,
|
|
1042
|
+
validation_thread_id=args.validation_thread_id,
|
|
1043
|
+
completed_at=now(),
|
|
1044
|
+
)
|
|
1045
|
+
if "cacheWriteInputTokens" in usage:
|
|
1046
|
+
usage.setdefault("cacheWriteInputTokensReported", True)
|
|
1047
|
+
return usage
|
|
1048
|
+
|
|
1049
|
+
|
|
1003
1050
|
def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1004
1051
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1005
1052
|
with scan_completion_lock(scan_id):
|
|
@@ -1012,7 +1059,7 @@ def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace
|
|
|
1012
1059
|
if completion["threadId"] != args.thread_id or completion["turnId"] != args.turn_id:
|
|
1013
1060
|
raise SystemExit("The scan usage belongs to a different completion turn.")
|
|
1014
1061
|
if not completion["finalized"]:
|
|
1015
|
-
usage = scan_usage.
|
|
1062
|
+
usage = scan_usage.collect_scan_usage_safely(
|
|
1016
1063
|
connection,
|
|
1017
1064
|
scan,
|
|
1018
1065
|
thread_id=args.thread_id,
|
|
@@ -1031,7 +1078,9 @@ def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace
|
|
|
1031
1078
|
f"scan_turn_{args.turn_status}",
|
|
1032
1079
|
]
|
|
1033
1080
|
usage["completion"] = {**completion, "finalized": True}
|
|
1034
|
-
|
|
1081
|
+
fields = scan_usage.merge_scan_usage_fields(stored, {"usage": usage})
|
|
1082
|
+
fields["usage"]["completion"] = usage["completion"]
|
|
1083
|
+
cost_json = parse_scan_cost(json.dumps(fields))
|
|
1035
1084
|
with connection:
|
|
1036
1085
|
connection.execute(
|
|
1037
1086
|
"UPDATE scans SET cost_json = ? WHERE id = ?", (cost_json, scan_id)
|
|
@@ -1042,6 +1091,7 @@ def finalize_scan_usage(connection: sqlite3.Connection, args: argparse.Namespace
|
|
|
1042
1091
|
def complete_budget_exhausted_scan(
|
|
1043
1092
|
connection: sqlite3.Connection, args: argparse.Namespace
|
|
1044
1093
|
) -> dict[str, Any]:
|
|
1094
|
+
"""Complete a running CLI Deep Scan using the measured cost and saved results after its budget is exhausted."""
|
|
1045
1095
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
1046
1096
|
cost_json = parse_scan_cost(args.cost_json)
|
|
1047
1097
|
if cost_json is None:
|
|
@@ -1187,19 +1237,21 @@ def complete_scan_locked(
|
|
|
1187
1237
|
prepare_only: bool = False,
|
|
1188
1238
|
thread_id: str | None = None,
|
|
1189
1239
|
turn_id: str | None = None,
|
|
1240
|
+
model_thread_id: str | None = None,
|
|
1190
1241
|
) -> dict[str, Any]:
|
|
1191
1242
|
scan = require_scan(connection, scan_id)
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
_WORKBENCH_DB_CONTEXT, connection, scan, cost_json
|
|
1195
|
-
)
|
|
1196
|
-
if scan["status"] != "running":
|
|
1243
|
+
handoff.require_tokenless_scan_owner(connection, scan, model_thread_id)
|
|
1244
|
+
if scan["status"] not in {"running", "complete"}:
|
|
1197
1245
|
raise SystemExit("Only a running scan can be completed.")
|
|
1198
1246
|
handoff.require_current_continuation(
|
|
1199
1247
|
scan,
|
|
1200
1248
|
claim_token,
|
|
1201
1249
|
error_message="Scan completion is owned by another continuation.",
|
|
1202
1250
|
)
|
|
1251
|
+
if scan["status"] == "complete":
|
|
1252
|
+
return saved_results.refresh_completed_scan(
|
|
1253
|
+
_WORKBENCH_DB_CONTEXT, connection, scan, cost_json
|
|
1254
|
+
)
|
|
1203
1255
|
deep_scan.require_deep_scan_ready_for_parent_completion(connection, scan)
|
|
1204
1256
|
warnings = json.loads(scan["completion_warnings_json"])
|
|
1205
1257
|
target_warnings: list[str] = []
|
|
@@ -1256,10 +1308,7 @@ def complete_scan_locked(
|
|
|
1256
1308
|
scan_dir,
|
|
1257
1309
|
scan["id"],
|
|
1258
1310
|
completion_binding,
|
|
1259
|
-
connection
|
|
1260
|
-
"SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",
|
|
1261
|
-
(scan["id"],),
|
|
1262
|
-
).fetchall(),
|
|
1311
|
+
saved_deep_workers(connection, scan),
|
|
1263
1312
|
warnings,
|
|
1264
1313
|
stopped=False,
|
|
1265
1314
|
scan_mode=scan["mode"],
|
|
@@ -1343,42 +1392,44 @@ def complete_scan_locked(
|
|
|
1343
1392
|
context["targetWarnings"] = target_warnings
|
|
1344
1393
|
return context
|
|
1345
1394
|
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1395
|
+
measured_usage = scan_usage.collect_scan_usage_safely(
|
|
1396
|
+
connection,
|
|
1397
|
+
scan,
|
|
1398
|
+
thread_id=thread_id,
|
|
1399
|
+
completed_at=completion_timestamp,
|
|
1400
|
+
)
|
|
1401
|
+
cost_fields = scan_usage.merge_scan_usage_fields(
|
|
1402
|
+
scan_usage.stored_scan_cost_fields(cost_json), {"usage": measured_usage}
|
|
1403
|
+
)
|
|
1404
|
+
measured_usage = cost_fields["usage"]
|
|
1405
|
+
if thread_id is not None and turn_id is not None:
|
|
1406
|
+
measured_usage["completion"] = {
|
|
1407
|
+
"threadId": thread_id,
|
|
1408
|
+
"turnId": turn_id,
|
|
1409
|
+
"finalized": False,
|
|
1410
|
+
}
|
|
1411
|
+
if measured_usage["coverage"] == "complete":
|
|
1412
|
+
measured_usage["coverage"] = "partial"
|
|
1413
|
+
measured_usage["warnings"] = sorted(
|
|
1414
|
+
{*measured_usage.get("warnings", []), "turn_in_progress"}
|
|
1353
1415
|
)
|
|
1354
|
-
measured_usage = cost_fields["usage"]
|
|
1355
|
-
if thread_id is not None and turn_id is not None:
|
|
1356
|
-
measured_usage["completion"] = {
|
|
1357
|
-
"threadId": thread_id,
|
|
1358
|
-
"turnId": turn_id,
|
|
1359
|
-
"finalized": False,
|
|
1360
|
-
}
|
|
1361
|
-
if measured_usage["coverage"] == "complete":
|
|
1362
|
-
measured_usage["coverage"] = "partial"
|
|
1363
|
-
measured_usage["warnings"] = sorted(
|
|
1364
|
-
{*measured_usage.get("warnings", []), "turn_in_progress"}
|
|
1365
|
-
)
|
|
1366
1416
|
cost_json = parse_scan_cost(json.dumps(cost_fields))
|
|
1367
1417
|
connection.execute("BEGIN IMMEDIATE")
|
|
1368
1418
|
with connection:
|
|
1369
1419
|
timestamp = manifest["scan"]["completedAt"]
|
|
1370
1420
|
scan = require_scan(connection, scan["id"])
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
return scan_context(connection, scan["id"])
|
|
1374
|
-
if scan["status"] != "running":
|
|
1421
|
+
handoff.require_tokenless_scan_owner(connection, scan, model_thread_id)
|
|
1422
|
+
if scan["status"] not in {"running", "complete"}:
|
|
1375
1423
|
raise SystemExit("Only a running scan can be completed.")
|
|
1376
|
-
deep_scan.require_deep_scan_ready_for_parent_completion(connection, scan)
|
|
1377
1424
|
handoff.require_current_continuation(
|
|
1378
1425
|
scan,
|
|
1379
1426
|
claim_token,
|
|
1380
1427
|
error_message="Scan completion is owned by another continuation.",
|
|
1381
1428
|
)
|
|
1429
|
+
if scan["status"] == "complete":
|
|
1430
|
+
connection.commit()
|
|
1431
|
+
return scan_context(connection, scan["id"])
|
|
1432
|
+
deep_scan.require_deep_scan_ready_for_parent_completion(connection, scan)
|
|
1382
1433
|
connection.execute("DELETE FROM scan_artifacts WHERE scan_id = ?", (scan["id"],))
|
|
1383
1434
|
for kind, path in artifacts.items():
|
|
1384
1435
|
if path is not None:
|
|
@@ -1403,12 +1454,14 @@ def complete_scan_locked(
|
|
|
1403
1454
|
"""
|
|
1404
1455
|
UPDATE scans
|
|
1405
1456
|
SET status = 'complete', phase = 'reporting', completed_at = ?, updated_at = ?,
|
|
1406
|
-
|
|
1457
|
+
log_completed_at = ?, seal_manifest_digest = ?, cost_json = ?,
|
|
1458
|
+
completion_warnings_json = ?
|
|
1407
1459
|
WHERE id = ? AND status = 'running'
|
|
1408
1460
|
""",
|
|
1409
1461
|
(
|
|
1410
1462
|
timestamp,
|
|
1411
1463
|
timestamp,
|
|
1464
|
+
now(),
|
|
1412
1465
|
manifest_digest,
|
|
1413
1466
|
cost_json,
|
|
1414
1467
|
json.dumps(warnings),
|
|
@@ -1423,7 +1476,11 @@ def complete_scan_locked(
|
|
|
1423
1476
|
|
|
1424
1477
|
|
|
1425
1478
|
def require_cli_scan_directory(repository: Path, args: argparse.Namespace) -> Path:
|
|
1426
|
-
|
|
1479
|
+
# Registration uses an empty output, including the replacement created with
|
|
1480
|
+
# the original DACL after archival. Check that ACL before moving any results.
|
|
1481
|
+
scan_dir = require_canonical_scan_directory(
|
|
1482
|
+
Path(args.scan_dir).expanduser(), writable_output=True
|
|
1483
|
+
)
|
|
1427
1484
|
if scan_dir == repository or repository in scan_dir.parents or scan_dir in repository.parents:
|
|
1428
1485
|
raise SystemExit(
|
|
1429
1486
|
"The scan artifact directory must be outside and not contain the selected target."
|
|
@@ -1441,6 +1498,12 @@ def register_cli_scan(
|
|
|
1441
1498
|
*,
|
|
1442
1499
|
before_archive: Callable[[], None] | None = None,
|
|
1443
1500
|
) -> dict[str, Any]:
|
|
1501
|
+
"""Register a CLI scan and its selected target before execution begins.
|
|
1502
|
+
|
|
1503
|
+
Record the launch recipe and target identity with the new scan. When reusing
|
|
1504
|
+
an output directory, coordinate archiving with registration so previous results
|
|
1505
|
+
can still be located. Return the scan ID, contract, and target metadata.
|
|
1506
|
+
"""
|
|
1444
1507
|
repository = require_target(args.repository)
|
|
1445
1508
|
require_scannable_target(repository)
|
|
1446
1509
|
scan_dir = None
|
|
@@ -1449,14 +1512,25 @@ def register_cli_scan(
|
|
|
1449
1512
|
scan_dir = require_cli_scan_directory(repository, args)
|
|
1450
1513
|
user_context = None
|
|
1451
1514
|
workflow_id = None
|
|
1515
|
+
surface = None
|
|
1516
|
+
package_version = None
|
|
1452
1517
|
if args.registration_json_stdin:
|
|
1453
1518
|
registration = json.load(sys.stdin)
|
|
1454
1519
|
recipe_json = json.dumps(registration["recipe"], ensure_ascii=False, separators=(",", ":"))
|
|
1455
1520
|
user_context = registration.get("userContext")
|
|
1456
1521
|
workflow_id = registration.get("workflowId")
|
|
1522
|
+
if registration.get("surface") in ("cli", "sdk"):
|
|
1523
|
+
surface = registration["surface"]
|
|
1524
|
+
if isinstance(registration.get("packageVersion"), str):
|
|
1525
|
+
package_version = registration["packageVersion"] or None
|
|
1457
1526
|
else:
|
|
1458
1527
|
recipe_json = sys.stdin.read() if args.recipe_json_stdin else args.recipe_json
|
|
1459
1528
|
recipe = parse_scan_recipe(recipe_json, repository)
|
|
1529
|
+
launch_kind = "scan"
|
|
1530
|
+
if isinstance(recipe.get("import"), dict):
|
|
1531
|
+
launch_kind = "import"
|
|
1532
|
+
elif recipe.get("mock") is True:
|
|
1533
|
+
launch_kind = "mock"
|
|
1460
1534
|
requested_target = recipe["target"]
|
|
1461
1535
|
paths = requested_target["paths"]
|
|
1462
1536
|
recipe.pop("_codexSecurityFileScopes", None)
|
|
@@ -1581,6 +1655,9 @@ def register_cli_scan(
|
|
|
1581
1655
|
timestamp=timestamp,
|
|
1582
1656
|
handoff_status="delivered",
|
|
1583
1657
|
scan_dir=scan_dir,
|
|
1658
|
+
surface=surface,
|
|
1659
|
+
package_version=package_version,
|
|
1660
|
+
launch_kind=launch_kind,
|
|
1584
1661
|
)
|
|
1585
1662
|
connection.execute(
|
|
1586
1663
|
"UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
|
|
@@ -1593,14 +1670,19 @@ def register_cli_scan(
|
|
|
1593
1670
|
)
|
|
1594
1671
|
if workflow_id is not None:
|
|
1595
1672
|
register_workflow_scan(connection, workflow_id, scan_id, str(scan_dir), timestamp)
|
|
1673
|
+
scan = connection.execute(
|
|
1674
|
+
"SELECT scans.*, snapshot AS lifecycle_json FROM scans "
|
|
1675
|
+
"JOIN scan_lifecycles ON scan_id = scans.id WHERE scans.id = ?",
|
|
1676
|
+
(scan_id,),
|
|
1677
|
+
).fetchone()
|
|
1596
1678
|
connection.commit()
|
|
1597
1679
|
except BaseException:
|
|
1598
1680
|
connection.rollback()
|
|
1599
1681
|
raise
|
|
1600
|
-
scan = require_scan(connection, scan_id)
|
|
1601
1682
|
return {
|
|
1602
1683
|
**({"archivedScanDir": str(archived_scan_dir)} if archived_scan_dir is not None else {}),
|
|
1603
1684
|
"contract": scan_contract(scan),
|
|
1685
|
+
"lifecycle": json.loads(scan["lifecycle_json"]),
|
|
1604
1686
|
"scanDir": str(scan_dir),
|
|
1605
1687
|
"scanId": scan_id,
|
|
1606
1688
|
"scopeFileCount": scope_file_count,
|
|
@@ -2195,9 +2277,62 @@ def set_finding_remediation(
|
|
|
2195
2277
|
)
|
|
2196
2278
|
except (ContractError, OSError, SystemExit) as exc:
|
|
2197
2279
|
raise SystemExit(f"Could not save the remediation patch: {exc}") from exc
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2280
|
+
if getattr(args, "assigned_finding", False):
|
|
2281
|
+
return assigned_remediation_context(
|
|
2282
|
+
connection,
|
|
2283
|
+
occurrence["scan_id"],
|
|
2284
|
+
occurrence["id"],
|
|
2285
|
+
request_id,
|
|
2286
|
+
action_token,
|
|
2287
|
+
written_version=args.expected_version + 1,
|
|
2288
|
+
)
|
|
2289
|
+
return scan_context(connection, occurrence["scan_id"], occurrence["id"])
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
def assigned_remediation_context(
|
|
2293
|
+
connection: sqlite3.Connection,
|
|
2294
|
+
scan_id: str,
|
|
2295
|
+
occurrence_id: str,
|
|
2296
|
+
request_id: str,
|
|
2297
|
+
action_token: str,
|
|
2298
|
+
*,
|
|
2299
|
+
written_version: int | None = None,
|
|
2300
|
+
) -> dict[str, Any]:
|
|
2301
|
+
"""After authorization, project only the assigned finding and check the returned action state."""
|
|
2302
|
+
occurrence = require_occurrence(connection, occurrence_id)
|
|
2303
|
+
if occurrence["details_json"] == "{}":
|
|
2304
|
+
backfill_legacy_finding_details(connection, require_scan(connection, scan_id))
|
|
2305
|
+
occurrence = require_occurrence(connection, occurrence_id)
|
|
2306
|
+
if occurrence["scan_id"] != scan_id:
|
|
2307
|
+
raise SystemExit("This finding does not belong to the selected scan.")
|
|
2308
|
+
scan = require_scan(connection, scan_id)
|
|
2309
|
+
finding = finding_result(connection, scan, occurrence, related=None)
|
|
2310
|
+
state = finding["remediationState"]
|
|
2311
|
+
if written_version is None:
|
|
2312
|
+
if not (
|
|
2313
|
+
state.get("requestId") == request_id
|
|
2314
|
+
and state.get("actionClaimToken") == action_token
|
|
2315
|
+
and state.get("pendingAction")
|
|
2316
|
+
):
|
|
2317
|
+
raise SystemExit(
|
|
2318
|
+
"This remediation action is no longer owned by the supplied request and action token."
|
|
2319
|
+
)
|
|
2320
|
+
elif (
|
|
2321
|
+
state.get("requestId") != request_id
|
|
2322
|
+
or state.get("version") != written_version
|
|
2323
|
+
or state.get("actionClaimToken") not in (None, action_token)
|
|
2324
|
+
):
|
|
2325
|
+
# The next action may already have started since this write committed.
|
|
2326
|
+
return {"occurrenceId": occurrence_id, "requestId": request_id, "version": written_version}
|
|
2327
|
+
return {
|
|
2328
|
+
"scan": {
|
|
2329
|
+
"scanId": scan["id"],
|
|
2330
|
+
"targetPath": scan["target_path"],
|
|
2331
|
+
"targetRevision": scan["target_revision"],
|
|
2332
|
+
"scanDir": scan["scan_dir"],
|
|
2333
|
+
"findings": [finding],
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2201
2336
|
|
|
2202
2337
|
|
|
2203
2338
|
def require_reviewed_patch_applied(
|
|
@@ -2385,11 +2520,10 @@ def workspace_state(
|
|
|
2385
2520
|
}
|
|
2386
2521
|
selected_scan_id = result_scan_id or workspace["active_scan_id"]
|
|
2387
2522
|
if selected_scan_id:
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
result["
|
|
2391
|
-
|
|
2392
|
-
)
|
|
2523
|
+
if result_scan is None:
|
|
2524
|
+
result_scan = scan_result(connection, require_scan(connection, selected_scan_id))
|
|
2525
|
+
result["userContext"] = result_scan["userContext"]
|
|
2526
|
+
result["results"] = result_scan
|
|
2393
2527
|
return result
|
|
2394
2528
|
|
|
2395
2529
|
target_metadata = None
|
|
@@ -2430,9 +2564,15 @@ def scan_context(
|
|
|
2430
2564
|
connection: sqlite3.Connection,
|
|
2431
2565
|
scan_id: str,
|
|
2432
2566
|
occurrence_id: str | None = None,
|
|
2567
|
+
*,
|
|
2568
|
+
model_thread_id: str | None = None,
|
|
2433
2569
|
) -> dict[str, Any]:
|
|
2434
2570
|
scan = require_scan(connection, scan_id)
|
|
2435
|
-
|
|
2571
|
+
# Legacy backfill may write before scan_result reloads the row for its response.
|
|
2572
|
+
handoff.require_tokenless_scan_owner(connection, scan, model_thread_id)
|
|
2573
|
+
result = scan_result(
|
|
2574
|
+
connection, scan, occurrence_id=occurrence_id, model_thread_id=model_thread_id
|
|
2575
|
+
)
|
|
2436
2576
|
workspace_result = result
|
|
2437
2577
|
if len(result["findings"]) > FINDINGS_RESULT_LIMIT:
|
|
2438
2578
|
workspace_result = dict(
|
|
@@ -2456,7 +2596,77 @@ def scan_context(
|
|
|
2456
2596
|
|
|
2457
2597
|
|
|
2458
2598
|
def get_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2459
|
-
|
|
2599
|
+
if getattr(args, "progress_only", False):
|
|
2600
|
+
scan = connection.execute(
|
|
2601
|
+
"""
|
|
2602
|
+
SELECT scans.id, scans.mode, scans.phase, scans.status, scans.canceled_at,
|
|
2603
|
+
progress.*, progress.updated_at AS progress_updated_at
|
|
2604
|
+
FROM scans JOIN scan_progress AS progress ON progress.scan_id = scans.id
|
|
2605
|
+
WHERE scans.id = ?
|
|
2606
|
+
""",
|
|
2607
|
+
(resolve_scan_id(connection, args.scan_id),),
|
|
2608
|
+
).fetchone()
|
|
2609
|
+
if scan is None:
|
|
2610
|
+
raise SystemExit("Codex Security scan not found.")
|
|
2611
|
+
progress, _ = scan_progress_result(connection, scan)
|
|
2612
|
+
return {"scan": {"progress": progress}}
|
|
2613
|
+
request_id = getattr(args, "request_id", None)
|
|
2614
|
+
action_token = getattr(args, "action_token", None)
|
|
2615
|
+
if request_id is not None or action_token is not None:
|
|
2616
|
+
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
2617
|
+
request_id = require_uuid(request_id or "", "request-id")
|
|
2618
|
+
action_token = require_uuid(action_token or "", "action-token")
|
|
2619
|
+
authorized = connection.execute(
|
|
2620
|
+
"""
|
|
2621
|
+
SELECT 1 FROM finding_remediation_attempts AS action
|
|
2622
|
+
JOIN finding_occurrences AS finding ON finding.id = action.occurrence_id
|
|
2623
|
+
WHERE finding.scan_id = ? AND finding.id = ? AND action.request_id = ?
|
|
2624
|
+
AND action.pending_action_claim_token = ? AND action.pending_action IS NOT NULL
|
|
2625
|
+
""",
|
|
2626
|
+
(scan_id, args.occurrence_id, request_id, action_token),
|
|
2627
|
+
).fetchone()
|
|
2628
|
+
if authorized is None:
|
|
2629
|
+
raise SystemExit(
|
|
2630
|
+
"This remediation action is no longer owned by the supplied request and action token."
|
|
2631
|
+
)
|
|
2632
|
+
return assigned_remediation_context(
|
|
2633
|
+
connection, scan_id, args.occurrence_id, request_id, action_token
|
|
2634
|
+
)
|
|
2635
|
+
context_claim = getattr(args, "context_claim_token", None)
|
|
2636
|
+
model_thread = getattr(args, "model_thread_id", None)
|
|
2637
|
+
if context_claim is not None:
|
|
2638
|
+
scan = require_scan(connection, args.scan_id)
|
|
2639
|
+
handoff.require_tokenless_scan_owner(connection, scan, model_thread)
|
|
2640
|
+
if scan["handoff_status"] == "pending":
|
|
2641
|
+
detail = (
|
|
2642
|
+
"Pass the handoffClaimToken returned by the Codex Security scan launcher."
|
|
2643
|
+
if scan["handoff_claim_token"]
|
|
2644
|
+
else "Claim the pending Codex Security scan handoff before loading its context."
|
|
2645
|
+
)
|
|
2646
|
+
raise SystemExit(f"This Codex Security scan handoff has not been delivered. {detail}")
|
|
2647
|
+
if context_claim:
|
|
2648
|
+
context_claim = handoff.require_handoff_claim_token(context_claim)
|
|
2649
|
+
if scan["handoff_claim_token"] and scan["handoff_claim_token"] != context_claim:
|
|
2650
|
+
if not model_thread:
|
|
2651
|
+
raise SystemExit("Scan context requires its current continuation claim.")
|
|
2652
|
+
owner = (
|
|
2653
|
+
scan["continuation_thread_id"]
|
|
2654
|
+
or require_workspace(connection, scan["workspace_id"])["thread_id"]
|
|
2655
|
+
)
|
|
2656
|
+
if model_thread != owner:
|
|
2657
|
+
raise SystemExit("Scan context is owned by another continuation.")
|
|
2658
|
+
if (
|
|
2659
|
+
args.occurrence_id is not None
|
|
2660
|
+
and connection.execute(
|
|
2661
|
+
"SELECT 1 FROM finding_occurrences WHERE scan_id = ? AND id = ?",
|
|
2662
|
+
(scan["id"], args.occurrence_id),
|
|
2663
|
+
).fetchone()
|
|
2664
|
+
is None
|
|
2665
|
+
):
|
|
2666
|
+
raise SystemExit("This finding was not found in the selected scan.")
|
|
2667
|
+
result = scan_context(
|
|
2668
|
+
connection, args.scan_id, args.occurrence_id, model_thread_id=model_thread
|
|
2669
|
+
)
|
|
2460
2670
|
if result["scan"]["progress"]["status"] != "running":
|
|
2461
2671
|
scan = require_scan(connection, args.scan_id)
|
|
2462
2672
|
try:
|
|
@@ -2469,7 +2679,7 @@ def get_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[s
|
|
|
2469
2679
|
def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
2470
2680
|
scan = require_scan(connection, args.scan_id)
|
|
2471
2681
|
backfill_legacy_finding_details(connection, scan)
|
|
2472
|
-
limit =
|
|
2682
|
+
limit = args.limit
|
|
2473
2683
|
rows = scan_history.finding_occurrence_rows(
|
|
2474
2684
|
connection,
|
|
2475
2685
|
scan["id"],
|
|
@@ -2508,16 +2718,60 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d
|
|
|
2508
2718
|
}
|
|
2509
2719
|
|
|
2510
2720
|
|
|
2721
|
+
def scan_progress_result(
|
|
2722
|
+
connection: sqlite3.Connection, scan: sqlite3.Row
|
|
2723
|
+
) -> tuple[dict[str, Any], str]:
|
|
2724
|
+
independent_reviews = (
|
|
2725
|
+
deep_scan.independent_review_progress(
|
|
2726
|
+
connection, scan["id"], parent_running=scan["status"] == "running"
|
|
2727
|
+
)
|
|
2728
|
+
if scan["mode"] == "deep"
|
|
2729
|
+
else None
|
|
2730
|
+
)
|
|
2731
|
+
progress_result = {
|
|
2732
|
+
"candidates": {"reportable": scan["reportable_findings_count"]},
|
|
2733
|
+
"coverage": {
|
|
2734
|
+
"closedRows": scan["review_items_completed"],
|
|
2735
|
+
"filesTotal": scan["scope_file_count"],
|
|
2736
|
+
"worklistRows": scan["review_items_total"],
|
|
2737
|
+
},
|
|
2738
|
+
"phase": scan["phase"],
|
|
2739
|
+
"phaseProgress": {
|
|
2740
|
+
"completed": scan["phase_items_completed"],
|
|
2741
|
+
"total": scan["phase_items_total"],
|
|
2742
|
+
"unit": scan["phase_progress_unit"],
|
|
2743
|
+
},
|
|
2744
|
+
"preflightProgress": {
|
|
2745
|
+
"completed": scan["preflight_checks_completed"],
|
|
2746
|
+
"total": scan["preflight_checks_total"],
|
|
2747
|
+
},
|
|
2748
|
+
"preflightIssues": json.loads(scan["preflight_issues_json"]),
|
|
2749
|
+
"reviewPass": scan["deep_review_pass"],
|
|
2750
|
+
"status": "canceled" if scan["canceled_at"] else scan["status"],
|
|
2751
|
+
"updatedAt": scan["progress_updated_at"],
|
|
2752
|
+
}
|
|
2753
|
+
review_updated_at = ""
|
|
2754
|
+
if independent_reviews is not None:
|
|
2755
|
+
review_updated_at = str(independent_reviews.pop("updatedAt"))
|
|
2756
|
+
progress_result["independentReviews"] = independent_reviews
|
|
2757
|
+
return progress_result, review_updated_at
|
|
2758
|
+
|
|
2759
|
+
|
|
2511
2760
|
def scan_result(
|
|
2512
2761
|
connection: sqlite3.Connection,
|
|
2513
2762
|
scan: sqlite3.Row,
|
|
2514
2763
|
*,
|
|
2515
2764
|
occurrence_id: str | None = None,
|
|
2765
|
+
model_thread_id: str | None = None,
|
|
2516
2766
|
) -> dict[str, Any]:
|
|
2767
|
+
"""Assemble the workbench view of a saved scan, backfilling older finding details as needed.
|
|
2768
|
+
|
|
2769
|
+
An occurrence ID selects one finding from that scan. An occurrence belonging
|
|
2770
|
+
to a different scan raises SystemExit.
|
|
2771
|
+
"""
|
|
2517
2772
|
backfill_legacy_finding_details(connection, scan)
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
).fetchone()
|
|
2773
|
+
scan = scan_history.scan_with_progress(connection, scan["id"])
|
|
2774
|
+
handoff.require_tokenless_scan_owner(connection, scan, model_thread_id)
|
|
2521
2775
|
artifact_rows = connection.execute(
|
|
2522
2776
|
"SELECT kind, path FROM scan_artifacts WHERE scan_id = ?", (scan["id"],)
|
|
2523
2777
|
)
|
|
@@ -2545,9 +2799,6 @@ def scan_result(
|
|
|
2545
2799
|
raise SystemExit("This finding does not belong to the selected scan.")
|
|
2546
2800
|
if all(row["id"] != occurrence["id"] for row in occurrence_rows):
|
|
2547
2801
|
occurrence_rows.append(occurrence)
|
|
2548
|
-
finding_count = connection.execute(
|
|
2549
|
-
"SELECT COUNT(*) FROM finding_occurrences WHERE scan_id = ?", (scan["id"],)
|
|
2550
|
-
).fetchone()[0]
|
|
2551
2802
|
severity_counts = {
|
|
2552
2803
|
row["severity"]: row["count"]
|
|
2553
2804
|
for row in connection.execute(
|
|
@@ -2560,38 +2811,9 @@ def scan_result(
|
|
|
2560
2811
|
(scan["id"],),
|
|
2561
2812
|
)
|
|
2562
2813
|
}
|
|
2814
|
+
finding_count = sum(severity_counts.values())
|
|
2563
2815
|
remediation_available, remediation_unavailable_reason = remediation_availability(scan)
|
|
2564
|
-
|
|
2565
|
-
deep_scan.independent_review_progress(connection, scan["id"])
|
|
2566
|
-
if scan["mode"] == "deep"
|
|
2567
|
-
else None
|
|
2568
|
-
)
|
|
2569
|
-
progress_result = {
|
|
2570
|
-
"candidates": {"reportable": progress["reportable_findings_count"]},
|
|
2571
|
-
"coverage": {
|
|
2572
|
-
"closedRows": progress["review_items_completed"],
|
|
2573
|
-
"filesTotal": progress["scope_file_count"],
|
|
2574
|
-
"worklistRows": progress["review_items_total"],
|
|
2575
|
-
},
|
|
2576
|
-
"phase": scan["phase"],
|
|
2577
|
-
"phaseProgress": {
|
|
2578
|
-
"completed": progress["phase_items_completed"],
|
|
2579
|
-
"total": progress["phase_items_total"],
|
|
2580
|
-
"unit": progress["phase_progress_unit"],
|
|
2581
|
-
},
|
|
2582
|
-
"preflightProgress": {
|
|
2583
|
-
"completed": progress["preflight_checks_completed"],
|
|
2584
|
-
"total": progress["preflight_checks_total"],
|
|
2585
|
-
},
|
|
2586
|
-
"preflightIssues": json.loads(progress["preflight_issues_json"]),
|
|
2587
|
-
"reviewPass": progress["deep_review_pass"],
|
|
2588
|
-
"status": "canceled" if scan["canceled_at"] else scan["status"],
|
|
2589
|
-
"updatedAt": progress["updated_at"],
|
|
2590
|
-
}
|
|
2591
|
-
review_updated_at = ""
|
|
2592
|
-
if independent_reviews is not None:
|
|
2593
|
-
review_updated_at = str(independent_reviews.pop("updatedAt"))
|
|
2594
|
-
progress_result["independentReviews"] = independent_reviews
|
|
2816
|
+
progress_result, review_updated_at = scan_progress_result(connection, scan)
|
|
2595
2817
|
relations = scan_history.finding_relations(
|
|
2596
2818
|
connection, scan["id"], (row["id"] for row in occurrence_rows)
|
|
2597
2819
|
)
|
|
@@ -2599,12 +2821,14 @@ def scan_result(
|
|
|
2599
2821
|
"artifacts": artifacts,
|
|
2600
2822
|
**model_fields,
|
|
2601
2823
|
"canceledAt": scan["canceled_at"],
|
|
2824
|
+
"logCompletedAt": scan["log_completed_at"],
|
|
2602
2825
|
**scan_usage.stored_scan_cost_fields(scan["cost_json"]),
|
|
2603
2826
|
"contract": scan_contract(scan),
|
|
2604
2827
|
"continuationThreadId": scan["continuation_thread_id"],
|
|
2605
2828
|
"threadIds": scan_usage._scan_root_thread_ids(connection, scan, None),
|
|
2606
2829
|
"executionThreadIds": scan_usage._scan_execution_thread_ids(connection, scan),
|
|
2607
2830
|
"failureMessage": scan["failure_message"],
|
|
2831
|
+
"lifecycle": json.loads(scan["lifecycle_json"]),
|
|
2608
2832
|
"findings": [
|
|
2609
2833
|
finding_result(connection, scan, row, related=relations.get(row["id"], []))
|
|
2610
2834
|
for row in occurrence_rows
|
|
@@ -2635,7 +2859,7 @@ def scan_result(
|
|
|
2635
2859
|
"targetSummary": scan["target_summary"],
|
|
2636
2860
|
"updatedAt": max(
|
|
2637
2861
|
scan["updated_at"],
|
|
2638
|
-
|
|
2862
|
+
scan["progress_updated_at"],
|
|
2639
2863
|
review_updated_at,
|
|
2640
2864
|
finding_management_updated_at(connection, scan["id"]) or "",
|
|
2641
2865
|
),
|
|
@@ -2753,7 +2977,7 @@ def finding_result(
|
|
|
2753
2977
|
scan: sqlite3.Row,
|
|
2754
2978
|
occurrence: sqlite3.Row,
|
|
2755
2979
|
*,
|
|
2756
|
-
related: list[dict[str, Any]],
|
|
2980
|
+
related: list[dict[str, Any]] | None,
|
|
2757
2981
|
) -> dict[str, Any]:
|
|
2758
2982
|
details = bounded_finding_details(read_finding_details(occurrence["details_json"]))
|
|
2759
2983
|
confidence = details.get("confidence")
|
|
@@ -2767,11 +2991,11 @@ def finding_result(
|
|
|
2767
2991
|
except SystemExit:
|
|
2768
2992
|
target = None
|
|
2769
2993
|
for row in connection.execute(
|
|
2770
|
-
"""
|
|
2994
|
+
f"""
|
|
2771
2995
|
SELECT relative_path, start_line, end_line, role
|
|
2772
2996
|
FROM finding_locations
|
|
2773
2997
|
WHERE occurrence_id = ?
|
|
2774
|
-
ORDER BY
|
|
2998
|
+
ORDER BY {FINDING_LOCATION_ORDER_SQL}
|
|
2775
2999
|
LIMIT ?
|
|
2776
3000
|
""",
|
|
2777
3001
|
(occurrence["id"], FINDING_LOCATIONS_LIMIT),
|
|
@@ -2822,15 +3046,16 @@ def finding_result(
|
|
|
2822
3046
|
"title": bounded_output_text(occurrence["title"], FINDING_TITLE_BYTES),
|
|
2823
3047
|
"triage": finding_triage_result(connection, occurrence["id"]),
|
|
2824
3048
|
}
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
3049
|
+
if related is not None:
|
|
3050
|
+
matches, known_since, known_scan_ids = scan_history.finding_matches(
|
|
3051
|
+
connection, occurrence["id"], scan["id"], scan["started_at"]
|
|
3052
|
+
)
|
|
3053
|
+
if matches:
|
|
3054
|
+
result["matches"] = matches
|
|
3055
|
+
result["knownSince"] = known_since
|
|
3056
|
+
result["knownScanIds"] = known_scan_ids
|
|
3057
|
+
if related:
|
|
3058
|
+
result["related"] = related
|
|
2834
3059
|
source_excerpt = finding_source_excerpt(
|
|
2835
3060
|
scan, target, excerpt_locations, requested_scan_paths(scan)
|
|
2836
3061
|
)
|
|
@@ -3067,7 +3292,7 @@ def artifact_path(scan_dir: Path, file_name: str, *, required: bool) -> Path | N
|
|
|
3067
3292
|
return resolved
|
|
3068
3293
|
|
|
3069
3294
|
|
|
3070
|
-
def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
3295
|
+
def require_canonical_scan_directory(scan_dir: Path, *, writable_output: bool = False) -> Path:
|
|
3071
3296
|
scan_dir = scan_dir.absolute()
|
|
3072
3297
|
try:
|
|
3073
3298
|
metadata = scan_dir.lstat()
|
|
@@ -3081,7 +3306,14 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3081
3306
|
):
|
|
3082
3307
|
raise SystemExit("Scan directory must be an existing canonical non-symlink directory.")
|
|
3083
3308
|
# Re-check ownership and parents so the scan directory cannot be substituted.
|
|
3084
|
-
if os.name
|
|
3309
|
+
if os.name == "nt":
|
|
3310
|
+
from windows_scan_local_files import require_windows_output_path
|
|
3311
|
+
|
|
3312
|
+
try:
|
|
3313
|
+
require_windows_output_path(scan_dir, writable_output=writable_output)
|
|
3314
|
+
except OSError as exc:
|
|
3315
|
+
raise SystemExit(str(exc)) from exc
|
|
3316
|
+
else:
|
|
3085
3317
|
geteuid = getattr(os, "geteuid", None)
|
|
3086
3318
|
effective_uid = geteuid() if geteuid is not None else None
|
|
3087
3319
|
if effective_uid is not None and metadata.st_uid != effective_uid:
|
|
@@ -3108,19 +3340,6 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3108
3340
|
return scan_dir
|
|
3109
3341
|
|
|
3110
3342
|
|
|
3111
|
-
def read_json_object(path: Path) -> dict[str, Any]:
|
|
3112
|
-
try:
|
|
3113
|
-
payload = json.loads(
|
|
3114
|
-
path.read_text(encoding="utf-8"),
|
|
3115
|
-
parse_constant=reject_non_finite_json,
|
|
3116
|
-
)
|
|
3117
|
-
except (OSError, ValueError) as exc:
|
|
3118
|
-
raise SystemExit(f"{path.name}: invalid JSON: {exc}") from exc
|
|
3119
|
-
if not isinstance(payload, dict):
|
|
3120
|
-
raise SystemExit(f"{path.name}: expected a JSON object.")
|
|
3121
|
-
return payload
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
3343
|
_WORKBENCH_PUBLICATION_CONTEXT = _WORKBENCH_DB_CONTEXT = SimpleNamespace(**globals())
|
|
3125
3344
|
|
|
3126
3345
|
|
|
@@ -3143,11 +3362,21 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3143
3362
|
print(json.dumps(saved_results.read_or_save_artifact(args)))
|
|
3144
3363
|
return
|
|
3145
3364
|
if args.command == "finding-issues":
|
|
3146
|
-
|
|
3365
|
+
try:
|
|
3366
|
+
result = publication.finding_issues(
|
|
3367
|
+
_WORKBENCH_PUBLICATION_CONTEXT, json.load(sys.stdin)
|
|
3368
|
+
)
|
|
3369
|
+
except sqlite3.OperationalError as exc:
|
|
3370
|
+
if not getattr(exc, "_codex_security_state_unavailable", False):
|
|
3371
|
+
raise
|
|
3372
|
+
print(f"sqlite3.OperationalError: {exc}", file=sys.stderr)
|
|
3373
|
+
raise SystemExit(73) from None
|
|
3147
3374
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3148
3375
|
return
|
|
3149
3376
|
with closing(
|
|
3150
|
-
connect(
|
|
3377
|
+
connect(
|
|
3378
|
+
deferred=args.command in {"get-scan", "read-scan-usage", "list-scans", "database-info"}
|
|
3379
|
+
)
|
|
3151
3380
|
) as connection:
|
|
3152
3381
|
remediation_state.require_available(connection, args, require_scan)
|
|
3153
3382
|
handlers = {
|
|
@@ -3159,8 +3388,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3159
3388
|
"get-deep-scan": deep_scan.get_deep_scan,
|
|
3160
3389
|
"claim-deep-scan-coordinator": deep_scan.claim_deep_scan_coordinator,
|
|
3161
3390
|
"upsert-deep-scan-worker": deep_scan.upsert_deep_scan_worker,
|
|
3162
|
-
"
|
|
3163
|
-
"commit-deep-scan-dedup": deep_scan.commit_deep_scan_dedup,
|
|
3391
|
+
"record-deep-scan-iteration": deep_scan.record_deep_scan_iteration,
|
|
3164
3392
|
"finish-deep-scan": deep_scan.finish_deep_scan,
|
|
3165
3393
|
"fail-deep-scan": deep_scan.fail_deep_scan,
|
|
3166
3394
|
"record-deep-scan-publication-failure": deep_scan.record_deep_scan_publication_failure,
|
|
@@ -3168,6 +3396,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3168
3396
|
"register-cli-scan": partial(register_cli_scan, before_archive=before_archive),
|
|
3169
3397
|
"set-scan-thread": set_scan_thread,
|
|
3170
3398
|
"set-scan-cost-limit": set_scan_cost_limit,
|
|
3399
|
+
"read-scan-usage": read_scan_usage,
|
|
3171
3400
|
"finalize-scan-usage": finalize_scan_usage,
|
|
3172
3401
|
"list-global-findings": native_indexes.list_global_findings,
|
|
3173
3402
|
"list-repositories": native_indexes.list_repositories,
|
|
@@ -3281,4 +3510,7 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3281
3510
|
|
|
3282
3511
|
|
|
3283
3512
|
if __name__ == "__main__":
|
|
3284
|
-
|
|
3513
|
+
try:
|
|
3514
|
+
main()
|
|
3515
|
+
except ContractError as exc:
|
|
3516
|
+
raise SystemExit(str(exc)) from None
|