@openai/codex-security 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -57
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +187 -363
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +120 -35
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +414 -163
- package/dist/api.js.map +1 -1
- package/dist/auth.js +7 -2
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +635 -266
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +6 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +12 -5
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +11 -3
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +48 -16
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +44 -89
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +11 -15
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +12 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +411 -184
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +15 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1238 -226
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +10 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +71 -51
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +13 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +124 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +7 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +512 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +94 -36
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +5 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +110 -57
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +37 -48
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +48 -3
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +214 -39
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +50 -88
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +97 -106
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +320 -481
- package/docs/dedupe-records.md +27 -4
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +9 -10
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -35
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -17,7 +17,7 @@ import tempfile
|
|
|
17
17
|
import time
|
|
18
18
|
import uuid
|
|
19
19
|
from collections.abc import Callable
|
|
20
|
-
from contextlib import closing, contextmanager, nullcontext
|
|
20
|
+
from contextlib import ExitStack, closing, contextmanager, nullcontext
|
|
21
21
|
from datetime import datetime, timedelta, timezone
|
|
22
22
|
from functools import partial
|
|
23
23
|
from pathlib import Path, PurePosixPath
|
|
@@ -43,7 +43,6 @@ import workbench_remediation as remediation_state
|
|
|
43
43
|
import workbench_saved_results as saved_results
|
|
44
44
|
import workbench_scan_history as scan_history
|
|
45
45
|
import workbench_scan_usage as scan_usage
|
|
46
|
-
from deep_scan_config import resolve_deep_scan_setup
|
|
47
46
|
from finalize_scan_contract import (
|
|
48
47
|
PRODUCER_NAME,
|
|
49
48
|
ContractError,
|
|
@@ -62,9 +61,6 @@ from workbench_constants import (
|
|
|
62
61
|
ARTIFACTS,
|
|
63
62
|
CLAIM_LEASE_SECONDS,
|
|
64
63
|
DELIVERED_ACTION_LEASE_SECONDS,
|
|
65
|
-
DIFF_TARGET_KINDS,
|
|
66
|
-
EMPTY_GIT_TREE,
|
|
67
|
-
EMPTY_GIT_TREES,
|
|
68
64
|
FINDING_ABSOLUTE_PATH_BYTES,
|
|
69
65
|
FINDING_LEVEL_BYTES,
|
|
70
66
|
FINDING_LOCATION_PATH_BYTES,
|
|
@@ -81,7 +77,6 @@ from workbench_constants import (
|
|
|
81
77
|
from workbench_feedback import get_scan_feedback
|
|
82
78
|
from workbench_finding_index import index_findings
|
|
83
79
|
from workbench_finding_workflows import finding_workflow, register_workflow_scan
|
|
84
|
-
from workbench_local_dedupe import local_dedupe
|
|
85
80
|
from workbench_scan_start import (
|
|
86
81
|
archive_scan,
|
|
87
82
|
insert_running_scan,
|
|
@@ -96,6 +91,17 @@ from workbench_schema import (
|
|
|
96
91
|
from workbench_schema import (
|
|
97
92
|
apply_migrations as apply_schema_migrations,
|
|
98
93
|
)
|
|
94
|
+
from workbench_setup import (
|
|
95
|
+
inspect_command,
|
|
96
|
+
inspect_selected_setup,
|
|
97
|
+
inspect_setup_values,
|
|
98
|
+
require_diff_target,
|
|
99
|
+
require_review_changes_target,
|
|
100
|
+
require_scannable_target,
|
|
101
|
+
require_scope,
|
|
102
|
+
require_target,
|
|
103
|
+
resolve_git_commit,
|
|
104
|
+
)
|
|
99
105
|
from workbench_source_excerpt import finding_source_excerpt
|
|
100
106
|
from workbench_source_scopes import (
|
|
101
107
|
capture_source_scopes,
|
|
@@ -108,10 +114,10 @@ from workbench_target import (
|
|
|
108
114
|
clean_worktree_content_digest,
|
|
109
115
|
copy_directory_excluding,
|
|
110
116
|
copy_git_worktree_files,
|
|
117
|
+
diff_scope_file_count,
|
|
111
118
|
diff_snapshot_digest,
|
|
112
119
|
directory_content_digest,
|
|
113
120
|
directory_snapshot_regular_file_count,
|
|
114
|
-
git_bytes,
|
|
115
121
|
git_command,
|
|
116
122
|
git_output,
|
|
117
123
|
git_revision,
|
|
@@ -119,7 +125,6 @@ from workbench_target import (
|
|
|
119
125
|
git_target_metadata,
|
|
120
126
|
git_worktree_context,
|
|
121
127
|
remediation_checkout_snapshot,
|
|
122
|
-
require_git_worktree_head,
|
|
123
128
|
require_remediation_target,
|
|
124
129
|
require_scan_target_identity,
|
|
125
130
|
require_scan_target_unchanged,
|
|
@@ -267,168 +272,6 @@ def apply_migrations(connection: sqlite3.Connection, *, immediate: bool = False)
|
|
|
267
272
|
)
|
|
268
273
|
|
|
269
274
|
|
|
270
|
-
def require_target(value: str) -> Path:
|
|
271
|
-
expanded = Path(value).expanduser()
|
|
272
|
-
if not expanded.is_absolute():
|
|
273
|
-
raise SystemExit("Scan target must be an absolute local directory path.")
|
|
274
|
-
target = expanded.resolve()
|
|
275
|
-
if not target.is_dir():
|
|
276
|
-
raise SystemExit(f"Scan target is not a readable local directory: {target}")
|
|
277
|
-
return target
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
def inspect_target(target_path: str) -> dict[str, Any]:
|
|
281
|
-
target = require_target(target_path)
|
|
282
|
-
return {
|
|
283
|
-
"displayName": target.name,
|
|
284
|
-
"targetMetadata": git_target_metadata(target),
|
|
285
|
-
"targetPath": str(target),
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
def resolve_git_commit(target: Path, revision: str, label: str) -> str:
|
|
290
|
-
value = optional_text(revision, maximum=512)
|
|
291
|
-
if not value:
|
|
292
|
-
raise SystemExit(f"{label} is required.")
|
|
293
|
-
resolved = git_output(
|
|
294
|
-
target,
|
|
295
|
-
"rev-parse",
|
|
296
|
-
"--verify",
|
|
297
|
-
"--end-of-options",
|
|
298
|
-
f"{value}^{{commit}}",
|
|
299
|
-
)
|
|
300
|
-
if resolved is None:
|
|
301
|
-
raise SystemExit(f"{label} does not resolve to a local Git commit: {value}")
|
|
302
|
-
return resolved
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def require_diff_target(
|
|
306
|
-
target: Path,
|
|
307
|
-
kind: str | None,
|
|
308
|
-
base_revision: str | None,
|
|
309
|
-
head_revision: str | None,
|
|
310
|
-
content_digest: str | None,
|
|
311
|
-
) -> dict[str, str]:
|
|
312
|
-
current_head = require_review_changes_target(target)
|
|
313
|
-
if kind not in DIFF_TARGET_KINDS:
|
|
314
|
-
raise SystemExit("Choose which Git changes to review before starting a diff scan.")
|
|
315
|
-
if kind == "working_tree":
|
|
316
|
-
base = resolve_git_commit(target, base_revision or "HEAD", "Working-tree base")
|
|
317
|
-
head = resolve_git_commit(target, head_revision or current_head, "Working-tree HEAD")
|
|
318
|
-
current_digest = worktree_content_digest(target)
|
|
319
|
-
if base != current_head or head != current_head:
|
|
320
|
-
raise SystemExit(
|
|
321
|
-
"Repository HEAD changed after these working-tree changes were selected. "
|
|
322
|
-
"Select Uncommitted changes again."
|
|
323
|
-
)
|
|
324
|
-
if content_digest and content_digest != current_digest:
|
|
325
|
-
raise SystemExit(
|
|
326
|
-
"Working-tree contents changed after they were selected. "
|
|
327
|
-
"Select Uncommitted changes again."
|
|
328
|
-
)
|
|
329
|
-
return {
|
|
330
|
-
"kind": kind,
|
|
331
|
-
"baseRevision": current_head,
|
|
332
|
-
"headRevision": current_head,
|
|
333
|
-
"contentDigest": current_digest,
|
|
334
|
-
}
|
|
335
|
-
if kind == "commit":
|
|
336
|
-
head = resolve_git_commit(target, head_revision or "", "Commit")
|
|
337
|
-
commit = git_bytes(target, "cat-file", "-p", head)
|
|
338
|
-
if commit is None:
|
|
339
|
-
raise SystemExit(f"Commit is not available in the local checkout: {head}")
|
|
340
|
-
parent_line = next(
|
|
341
|
-
(
|
|
342
|
-
line
|
|
343
|
-
for line in commit.split(b"\n\n", 1)[0].splitlines()
|
|
344
|
-
if line.startswith(b"parent ")
|
|
345
|
-
),
|
|
346
|
-
None,
|
|
347
|
-
)
|
|
348
|
-
if parent_line is None:
|
|
349
|
-
parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
|
|
350
|
-
else:
|
|
351
|
-
parent = resolve_git_commit(
|
|
352
|
-
target,
|
|
353
|
-
parent_line.removeprefix(b"parent ").decode("ascii").strip(),
|
|
354
|
-
"Commit parent",
|
|
355
|
-
)
|
|
356
|
-
if base_revision and base_revision != parent:
|
|
357
|
-
supplied_base = (
|
|
358
|
-
base_revision
|
|
359
|
-
if base_revision == EMPTY_GIT_TREE
|
|
360
|
-
else resolve_git_commit(target, base_revision, "Commit base")
|
|
361
|
-
)
|
|
362
|
-
if supplied_base != parent:
|
|
363
|
-
raise SystemExit("Commit base revision must match the selected commit's parent.")
|
|
364
|
-
return {"kind": kind, "baseRevision": parent, "headRevision": head}
|
|
365
|
-
base = resolve_git_commit(target, base_revision or "", "Base revision")
|
|
366
|
-
head = resolve_git_commit(target, head_revision or "", "Head revision")
|
|
367
|
-
if base == head:
|
|
368
|
-
raise SystemExit("Base and head revisions must identify different commits.")
|
|
369
|
-
return {"kind": kind, "baseRevision": base, "headRevision": head}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
def inspect_setup_values(
|
|
373
|
-
target_path: str,
|
|
374
|
-
scope: str,
|
|
375
|
-
mode: str,
|
|
376
|
-
diff_target_kind: str | None,
|
|
377
|
-
diff_base_revision: str | None,
|
|
378
|
-
diff_head_revision: str | None,
|
|
379
|
-
diff_content_digest: str | None,
|
|
380
|
-
) -> dict[str, Any]:
|
|
381
|
-
target = require_target(target_path)
|
|
382
|
-
require_scannable_target(target)
|
|
383
|
-
normalized_scope = require_scope(scope, mode, target)
|
|
384
|
-
if mode == "diff" and normalized_scope != ".":
|
|
385
|
-
raise SystemExit("Review changes requires the whole target; use scope '.'.")
|
|
386
|
-
if mode != "diff" and any(
|
|
387
|
-
value is not None
|
|
388
|
-
for value in (
|
|
389
|
-
diff_target_kind,
|
|
390
|
-
diff_base_revision,
|
|
391
|
-
diff_head_revision,
|
|
392
|
-
diff_content_digest,
|
|
393
|
-
)
|
|
394
|
-
):
|
|
395
|
-
raise SystemExit("A Git diff target requires Review changes mode.")
|
|
396
|
-
diff_target = (
|
|
397
|
-
require_diff_target(
|
|
398
|
-
target,
|
|
399
|
-
diff_target_kind,
|
|
400
|
-
diff_base_revision,
|
|
401
|
-
diff_head_revision,
|
|
402
|
-
diff_content_digest,
|
|
403
|
-
)
|
|
404
|
-
if mode == "diff"
|
|
405
|
-
else None
|
|
406
|
-
)
|
|
407
|
-
return {
|
|
408
|
-
"diffTarget": diff_target,
|
|
409
|
-
"scope": normalized_scope,
|
|
410
|
-
"target": inspect_target(str(target)),
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
def require_review_changes_target(target: Path) -> str:
|
|
415
|
-
revision = require_git_worktree_head(target)
|
|
416
|
-
repository_root = git_output(target, "rev-parse", "--show-toplevel")
|
|
417
|
-
if repository_root is None or not Path(repository_root).samefile(target):
|
|
418
|
-
raise SystemExit(
|
|
419
|
-
"Review changes requires the checked-out Git repository root as the target."
|
|
420
|
-
)
|
|
421
|
-
return revision
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
def require_scannable_target(target: Path) -> None:
|
|
425
|
-
metadata = git_target_metadata(target)
|
|
426
|
-
if metadata["isGit"] and not metadata["isWorktree"]:
|
|
427
|
-
raise SystemExit(
|
|
428
|
-
"Codex Security requires a checked-out worktree, not a bare Git repository."
|
|
429
|
-
)
|
|
430
|
-
|
|
431
|
-
|
|
432
275
|
def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
|
|
433
276
|
# Older scans did not record path kinds. Retain their lexical scope semantics
|
|
434
277
|
# rather than infer the original target from a possibly changed checkout.
|
|
@@ -609,30 +452,6 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
|
|
|
609
452
|
raise SystemExit("scan-manifest.json scope must stay inside the workbench scan scope.")
|
|
610
453
|
|
|
611
454
|
|
|
612
|
-
def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
613
|
-
value = scope if scope.strip() else "."
|
|
614
|
-
requested_scope = Path(value)
|
|
615
|
-
if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
|
|
616
|
-
raise SystemExit("Scan scope must use repository-relative POSIX paths.")
|
|
617
|
-
if ".." in requested_scope.parts:
|
|
618
|
-
raise SystemExit("Scan scope must stay inside the scanned target.")
|
|
619
|
-
try:
|
|
620
|
-
resolved_scope = (
|
|
621
|
-
requested_scope if requested_scope.is_absolute() else target / requested_scope
|
|
622
|
-
).resolve()
|
|
623
|
-
relative_scope = resolved_scope.relative_to(target)
|
|
624
|
-
except (RuntimeError, ValueError) as exc:
|
|
625
|
-
raise SystemExit("Scan scope must stay inside the scanned target.") from exc
|
|
626
|
-
normalized = relative_scope.as_posix() or "."
|
|
627
|
-
if not normalized.strip():
|
|
628
|
-
normalized = "./" + normalized
|
|
629
|
-
if mode == "deep" and normalized != ".":
|
|
630
|
-
raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
|
|
631
|
-
if not resolved_scope.is_dir():
|
|
632
|
-
raise SystemExit("Scan scope must reference an existing directory inside the target.")
|
|
633
|
-
return normalized
|
|
634
|
-
|
|
635
|
-
|
|
636
455
|
def require_workspace(connection: sqlite3.Connection, workspace_id: str) -> sqlite3.Row:
|
|
637
456
|
workspace_id = require_uuid(workspace_id, "workspace-id")
|
|
638
457
|
row = connection.execute("SELECT * FROM workspaces WHERE id = ?", (workspace_id,)).fetchone()
|
|
@@ -740,25 +559,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
740
559
|
return workspace_state(connection, workspace_id)
|
|
741
560
|
|
|
742
561
|
|
|
743
|
-
def inspect_selected_setup(args: argparse.Namespace) -> dict[str, Any]:
|
|
744
|
-
inspected = inspect_setup_values(
|
|
745
|
-
args.target_path,
|
|
746
|
-
args.scope,
|
|
747
|
-
args.mode,
|
|
748
|
-
args.diff_target_kind,
|
|
749
|
-
args.diff_base_revision,
|
|
750
|
-
args.diff_head_revision,
|
|
751
|
-
args.diff_content_digest,
|
|
752
|
-
)
|
|
753
|
-
if args.mode == "deep":
|
|
754
|
-
inspected["deepScanConfig"] = resolve_deep_scan_setup(
|
|
755
|
-
os.cpu_count() or 1, args.deep_scan_project_json
|
|
756
|
-
)
|
|
757
|
-
elif args.deep_scan_project_json is not None:
|
|
758
|
-
raise SystemExit("Project Deep Scan settings require Deep Scan mode.")
|
|
759
|
-
return inspected
|
|
760
|
-
|
|
761
|
-
|
|
762
562
|
def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
763
563
|
workspace = require_workspace(connection, args.workspace_id)
|
|
764
564
|
if workspace["active_scan_id"]:
|
|
@@ -820,6 +620,29 @@ def scan_target_root(scan_root: str | None, target: Path) -> Path:
|
|
|
820
620
|
return target_root
|
|
821
621
|
|
|
822
622
|
|
|
623
|
+
def scan_scope_file_count(
|
|
624
|
+
target: Path, paths: list[str], diff_target: dict[str, str] | None
|
|
625
|
+
) -> int | None:
|
|
626
|
+
if diff_target is not None:
|
|
627
|
+
return diff_scope_file_count(target, diff_target)
|
|
628
|
+
return sum(
|
|
629
|
+
1 if (target / path).is_file() else directory_snapshot_regular_file_count(target / path)
|
|
630
|
+
for path in paths
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def require_working_tree_unchanged(target: Path, diff_target: dict[str, str] | None) -> None:
|
|
635
|
+
if (
|
|
636
|
+
diff_target is not None
|
|
637
|
+
and diff_target["kind"] == "working_tree"
|
|
638
|
+
and (
|
|
639
|
+
git_revision(target) != diff_target["headRevision"]
|
|
640
|
+
or worktree_content_digest(target) != diff_target["contentDigest"]
|
|
641
|
+
)
|
|
642
|
+
):
|
|
643
|
+
raise SystemExit("The selected scan target changed while the scan was starting. Try again.")
|
|
644
|
+
|
|
645
|
+
|
|
823
646
|
def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
824
647
|
workspace_id = require_uuid(args.workspace_id, "workspace-id")
|
|
825
648
|
manages_transaction = not connection.in_transaction
|
|
@@ -858,9 +681,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
858
681
|
)
|
|
859
682
|
if diff_target is not None and not target_summary:
|
|
860
683
|
target_summary = diff_target_summary(diff_target)
|
|
861
|
-
scope_file_count =
|
|
862
|
-
target if scope == "." else target / scope
|
|
863
|
-
)
|
|
684
|
+
scope_file_count = scan_scope_file_count(target, [scope], diff_target)
|
|
864
685
|
target_identity = scan_target_identity(
|
|
865
686
|
target,
|
|
866
687
|
diff_target,
|
|
@@ -874,6 +695,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
|
|
|
874
695
|
)
|
|
875
696
|
target_root = scan_target_root(args.scan_root, target)
|
|
876
697
|
create_private_directory(target_root)
|
|
698
|
+
require_working_tree_unchanged(target, diff_target)
|
|
877
699
|
if manages_transaction:
|
|
878
700
|
connection.execute("BEGIN IMMEDIATE")
|
|
879
701
|
workspace = require_workspace(connection, workspace_id)
|
|
@@ -960,9 +782,7 @@ def _start_prompt_driven_scan(
|
|
|
960
782
|
target_summary = optional_text(args.target_summary, maximum=2400)
|
|
961
783
|
if diff_target is not None and not target_summary:
|
|
962
784
|
target_summary = diff_target_summary(diff_target)
|
|
963
|
-
scope_file_count =
|
|
964
|
-
target if scope == "." else target / scope
|
|
965
|
-
)
|
|
785
|
+
scope_file_count = scan_scope_file_count(target, [scope], diff_target)
|
|
966
786
|
diff_identity = scan_diff_identity(diff_target)
|
|
967
787
|
target_identity = scan_target_identity(target, diff_target)
|
|
968
788
|
source_scopes = capture_source_scopes(
|
|
@@ -1468,14 +1288,24 @@ def complete_scan_locked(
|
|
|
1468
1288
|
)
|
|
1469
1289
|
warnings.extend(warning for warning in prepared.warnings if warning not in warnings)
|
|
1470
1290
|
add_warning()
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
with connection:
|
|
1291
|
+
with connection:
|
|
1292
|
+
if warnings != json.loads(scan["completion_warnings_json"]):
|
|
1293
|
+
# Retain pre-publication diagnostics even if output writes fail.
|
|
1475
1294
|
connection.execute(
|
|
1476
1295
|
"UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
|
|
1477
1296
|
(json.dumps(warnings), scan_id),
|
|
1478
1297
|
)
|
|
1298
|
+
prepared_scan = prepared.manifest["scan"]
|
|
1299
|
+
if scan["mode"] == "deep" and (
|
|
1300
|
+
not prepared.was_sealed
|
|
1301
|
+
or "coverageRef" in prepared_scan
|
|
1302
|
+
or "surfaces" in prepared_scan.get("reviewState", {})
|
|
1303
|
+
):
|
|
1304
|
+
# A summary-only seal omits surfaces. Keep the count from its first preparation.
|
|
1305
|
+
connection.execute(
|
|
1306
|
+
"UPDATE deep_scan_runs SET terminal_reviewed_surface_count = ? WHERE scan_id = ?",
|
|
1307
|
+
(len(prepared.coverage["surfaces"]), scan_id),
|
|
1308
|
+
)
|
|
1479
1309
|
wrote = True
|
|
1480
1310
|
manifest, findings, _ = _write_prepared_scan_finalization(
|
|
1481
1311
|
prepared, projection_warnings=warnings
|
|
@@ -1657,16 +1487,8 @@ def register_cli_scan(
|
|
|
1657
1487
|
paths or ["."],
|
|
1658
1488
|
diff_target_kind=diff_target["kind"] if diff_target is not None else None,
|
|
1659
1489
|
)
|
|
1660
|
-
scope_file_count = (
|
|
1661
|
-
|
|
1662
|
-
if not paths
|
|
1663
|
-
else sum(
|
|
1664
|
-
1
|
|
1665
|
-
if (repository / path).is_file()
|
|
1666
|
-
else directory_snapshot_regular_file_count(repository / path)
|
|
1667
|
-
for path in paths
|
|
1668
|
-
)
|
|
1669
|
-
)
|
|
1490
|
+
scope_file_count = scan_scope_file_count(repository, paths or ["."], diff_target)
|
|
1491
|
+
require_working_tree_unchanged(repository, diff_target)
|
|
1670
1492
|
parent_scan_id = (
|
|
1671
1493
|
require_uuid(args.parent_scan_id, "parent-scan-id")
|
|
1672
1494
|
if args.parent_scan_id is not None
|
|
@@ -1678,18 +1500,43 @@ def register_cli_scan(
|
|
|
1678
1500
|
|
|
1679
1501
|
connection.execute("BEGIN IMMEDIATE")
|
|
1680
1502
|
try:
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1503
|
+
with ExitStack() as archive:
|
|
1504
|
+
deadline = None
|
|
1505
|
+
while True:
|
|
1506
|
+
if scan_dir is None:
|
|
1507
|
+
# Wait for any previous archive to finish before inspecting its replacement.
|
|
1508
|
+
scan_dir = require_cli_scan_directory(repository, args)
|
|
1509
|
+
try:
|
|
1510
|
+
archived_scan_dir = archive.enter_context(
|
|
1511
|
+
archive_scan(
|
|
1512
|
+
connection,
|
|
1513
|
+
args,
|
|
1514
|
+
scan_dir,
|
|
1515
|
+
timestamp,
|
|
1516
|
+
require_canonical_scan_directory,
|
|
1517
|
+
before_archive=before_archive,
|
|
1518
|
+
)
|
|
1519
|
+
)
|
|
1520
|
+
break
|
|
1521
|
+
except PermissionError as exc:
|
|
1522
|
+
# A Windows patch writer can temporarily pin the source of this rename.
|
|
1523
|
+
if (
|
|
1524
|
+
getattr(exc, "winerror", None) not in {5, 32}
|
|
1525
|
+
or exc.filename != str(scan_dir)
|
|
1526
|
+
or not exc.filename2
|
|
1527
|
+
):
|
|
1528
|
+
raise
|
|
1529
|
+
if deadline is None:
|
|
1530
|
+
timeout = connection.execute("PRAGMA busy_timeout").fetchone()[0]
|
|
1531
|
+
deadline = time.monotonic() + timeout / 1000
|
|
1532
|
+
remaining = deadline - time.monotonic()
|
|
1533
|
+
if remaining <= 0:
|
|
1534
|
+
raise
|
|
1535
|
+
connection.rollback()
|
|
1536
|
+
before_archive = None # The host already acknowledged this registration.
|
|
1537
|
+
scan_dir = None # Revalidate the directory and its owner under the next lock.
|
|
1538
|
+
time.sleep(min(0.05, remaining))
|
|
1539
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
1693
1540
|
target_id = ensure_security_target(connection, str(repository))
|
|
1694
1541
|
if parent_scan_id is not None:
|
|
1695
1542
|
parent = require_scan(connection, parent_scan_id)
|
|
@@ -1875,16 +1722,7 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1875
1722
|
timestamp = now()
|
|
1876
1723
|
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
1877
1724
|
if args.status == "closed":
|
|
1878
|
-
remediation =
|
|
1879
|
-
"""
|
|
1880
|
-
SELECT *
|
|
1881
|
-
FROM finding_remediation_attempts
|
|
1882
|
-
WHERE occurrence_id = ?
|
|
1883
|
-
ORDER BY created_at DESC, rowid DESC
|
|
1884
|
-
LIMIT 1
|
|
1885
|
-
""",
|
|
1886
|
-
(occurrence["id"],),
|
|
1887
|
-
).fetchone()
|
|
1725
|
+
remediation = remediation_state.latest_attempt(connection, occurrence["id"])
|
|
1888
1726
|
if (
|
|
1889
1727
|
remediation is not None
|
|
1890
1728
|
and remediation["pending_action"] is not None
|
|
@@ -1986,16 +1824,7 @@ def request_finding_remediation(
|
|
|
1986
1824
|
raise SystemExit("This remediation request belongs to a different finding.")
|
|
1987
1825
|
connection.commit()
|
|
1988
1826
|
return scan_context(connection, occurrence["scan_id"])
|
|
1989
|
-
latest =
|
|
1990
|
-
"""
|
|
1991
|
-
SELECT *
|
|
1992
|
-
FROM finding_remediation_attempts
|
|
1993
|
-
WHERE occurrence_id = ?
|
|
1994
|
-
ORDER BY created_at DESC, rowid DESC
|
|
1995
|
-
LIMIT 1
|
|
1996
|
-
""",
|
|
1997
|
-
(occurrence["id"],),
|
|
1998
|
-
).fetchone()
|
|
1827
|
+
latest = remediation_state.latest_attempt(connection, occurrence["id"])
|
|
1999
1828
|
if latest is not None:
|
|
2000
1829
|
active_operation = latest["pending_action"] is not None or latest["state"] in {
|
|
2001
1830
|
"requested",
|
|
@@ -2259,27 +2088,22 @@ def set_finding_remediation(
|
|
|
2259
2088
|
raise SystemExit("This remediation host request is owned by a different action token.")
|
|
2260
2089
|
remediation_state.require_transition(current["state"], args.state)
|
|
2261
2090
|
remediation_state.require_pending_action(current, args.state)
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
raise SystemExit("A remediation attempt cannot replace its reviewed patch path.")
|
|
2267
|
-
patch_path = requested_patch_path
|
|
2268
|
-
patch_digest = current["patch_digest"]
|
|
2269
|
-
if args.patch_digest is not None:
|
|
2270
|
-
requested_patch_digest = require_sha256_digest(args.patch_digest, "patch-digest")
|
|
2271
|
-
if patch_digest is not None and requested_patch_digest != patch_digest:
|
|
2272
|
-
raise SystemExit("A remediation attempt cannot replace its reviewed patch digest.")
|
|
2273
|
-
patch_digest = requested_patch_digest
|
|
2091
|
+
patch = sys.stdin.buffer.read() if args.patch_stdin else None
|
|
2092
|
+
patch_path, patch_digest = remediation_state.patch_metadata(
|
|
2093
|
+
current, args, patch, partial(require_scan_relative_file, scan)
|
|
2094
|
+
)
|
|
2274
2095
|
base_revision = optional_text(args.base_revision, maximum=512)
|
|
2275
2096
|
if args.state in {"generated", "applied", "verifying", "verified"}:
|
|
2276
2097
|
if patch_path is None or patch_digest is None:
|
|
2277
2098
|
raise SystemExit(
|
|
2278
2099
|
"Generated remediation states require a scan-local patch path and digest."
|
|
2279
2100
|
)
|
|
2280
|
-
|
|
2101
|
+
if patch is None:
|
|
2102
|
+
require_matching_patch_digest(scan, patch_path, patch_digest)
|
|
2281
2103
|
if args.state == "generated":
|
|
2282
2104
|
require_remediation_checkout_unchanged(scan, current, require_base_content=True)
|
|
2105
|
+
if patch is not None:
|
|
2106
|
+
remediation_state.require_valid_patch(Path(scan["target_path"]), patch)
|
|
2283
2107
|
if args.state in {"applied", "verifying", "verified"}:
|
|
2284
2108
|
if base_revision != current["base_revision"]:
|
|
2285
2109
|
raise SystemExit(
|
|
@@ -2300,59 +2124,80 @@ def set_finding_remediation(
|
|
|
2300
2124
|
current,
|
|
2301
2125
|
patch_path,
|
|
2302
2126
|
)
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
"""
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
raise SystemExit(
|
|
2353
|
-
"This remediation request changed. Refresh it before recording an update."
|
|
2127
|
+
|
|
2128
|
+
def record_update() -> None:
|
|
2129
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
2130
|
+
timestamp = now()
|
|
2131
|
+
occurrence = require_occurrence(connection, args.occurrence_id)
|
|
2132
|
+
require_finding_open(connection, occurrence["id"])
|
|
2133
|
+
replace_failure_summary = current["state"] == "failed" and args.state != "failed"
|
|
2134
|
+
updated = connection.execute(
|
|
2135
|
+
"""
|
|
2136
|
+
UPDATE finding_remediation_attempts
|
|
2137
|
+
SET state = ?, version = version + 1, patch_path = ?, patch_digest = ?,
|
|
2138
|
+
applied_content_digest = ?,
|
|
2139
|
+
pending_action = CASE
|
|
2140
|
+
WHEN ? IN ('verifying', 'failed') THEN pending_action ELSE NULL
|
|
2141
|
+
END,
|
|
2142
|
+
pending_action_claimed_at = CASE
|
|
2143
|
+
WHEN ? = 'verifying' THEN pending_action_claimed_at ELSE NULL
|
|
2144
|
+
END,
|
|
2145
|
+
pending_action_claim_token = CASE
|
|
2146
|
+
WHEN ? = 'verifying' THEN pending_action_claim_token ELSE NULL
|
|
2147
|
+
END,
|
|
2148
|
+
pending_action_delivered_at = CASE
|
|
2149
|
+
WHEN ? = 'verifying' THEN pending_action_delivered_at ELSE NULL
|
|
2150
|
+
END,
|
|
2151
|
+
summary = CASE WHEN ? THEN ? ELSE COALESCE(?, summary) END,
|
|
2152
|
+
verification_summary = COALESCE(?, verification_summary),
|
|
2153
|
+
updated_at = ?
|
|
2154
|
+
WHERE request_id = ? AND occurrence_id = ? AND version = ?
|
|
2155
|
+
AND pending_action_claim_token = ?
|
|
2156
|
+
""",
|
|
2157
|
+
(
|
|
2158
|
+
args.state,
|
|
2159
|
+
patch_path,
|
|
2160
|
+
patch_digest,
|
|
2161
|
+
applied_content_digest,
|
|
2162
|
+
args.state,
|
|
2163
|
+
args.state,
|
|
2164
|
+
args.state,
|
|
2165
|
+
args.state,
|
|
2166
|
+
replace_failure_summary,
|
|
2167
|
+
summary,
|
|
2168
|
+
summary,
|
|
2169
|
+
verification_summary,
|
|
2170
|
+
timestamp,
|
|
2171
|
+
request_id,
|
|
2172
|
+
occurrence["id"],
|
|
2173
|
+
args.expected_version,
|
|
2174
|
+
action_token,
|
|
2175
|
+
),
|
|
2354
2176
|
)
|
|
2355
|
-
|
|
2177
|
+
if updated.rowcount != 1:
|
|
2178
|
+
raise SystemExit(
|
|
2179
|
+
"This remediation request changed. Refresh it before recording an update."
|
|
2180
|
+
)
|
|
2181
|
+
|
|
2182
|
+
if patch is None:
|
|
2183
|
+
record_update()
|
|
2184
|
+
else:
|
|
2185
|
+
try:
|
|
2186
|
+
remediation_state.save_patch(
|
|
2187
|
+
_WORKBENCH_DB_CONTEXT,
|
|
2188
|
+
connection,
|
|
2189
|
+
scan["id"],
|
|
2190
|
+
current,
|
|
2191
|
+
patch_path,
|
|
2192
|
+
patch_digest,
|
|
2193
|
+
patch,
|
|
2194
|
+
record_update,
|
|
2195
|
+
)
|
|
2196
|
+
except (ContractError, OSError, SystemExit) as exc:
|
|
2197
|
+
raise SystemExit(f"Could not save the remediation patch: {exc}") from exc
|
|
2198
|
+
return scan_context(
|
|
2199
|
+
connection, occurrence["scan_id"], occurrence["id"] if patch is not None else None
|
|
2200
|
+
)
|
|
2356
2201
|
|
|
2357
2202
|
|
|
2358
2203
|
def require_reviewed_patch_applied(
|
|
@@ -2466,20 +2311,6 @@ def require_remediation_checkout_unchanged(
|
|
|
2466
2311
|
)
|
|
2467
2312
|
|
|
2468
2313
|
|
|
2469
|
-
def require_sha256_digest(value: str, label: str) -> str:
|
|
2470
|
-
normalized = optional_text(value, maximum=71)
|
|
2471
|
-
if (
|
|
2472
|
-
normalized is None
|
|
2473
|
-
or not normalized.startswith("sha256:")
|
|
2474
|
-
or len(normalized) != 71
|
|
2475
|
-
or any(
|
|
2476
|
-
character not in "0123456789abcdef" for character in normalized.removeprefix("sha256:")
|
|
2477
|
-
)
|
|
2478
|
-
):
|
|
2479
|
-
raise SystemExit(f"{label} must use sha256:<64 lowercase hex characters>.")
|
|
2480
|
-
return normalized
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
2314
|
def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
|
|
2484
2315
|
if len(value) > 4096:
|
|
2485
2316
|
raise SystemExit("Text value must be no longer than 4096 characters.")
|
|
@@ -2493,11 +2324,7 @@ def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
|
|
|
2493
2324
|
|
|
2494
2325
|
|
|
2495
2326
|
def require_matching_patch_digest(scan: sqlite3.Row, patch_path: str, patch_digest: str) -> None:
|
|
2496
|
-
|
|
2497
|
-
with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as patch:
|
|
2498
|
-
while chunk := patch.read(1024 * 1024):
|
|
2499
|
-
digest.update(chunk)
|
|
2500
|
-
if f"sha256:{digest.hexdigest()}" != patch_digest:
|
|
2327
|
+
if scan_local_file_digest(Path(scan["scan_dir"]), patch_path) != patch_digest:
|
|
2501
2328
|
raise SystemExit("Patch digest does not match the scan-local patch file.")
|
|
2502
2329
|
|
|
2503
2330
|
|
|
@@ -2606,7 +2433,11 @@ def scan_context(
|
|
|
2606
2433
|
) -> dict[str, Any]:
|
|
2607
2434
|
scan = require_scan(connection, scan_id)
|
|
2608
2435
|
result = scan_result(connection, scan, occurrence_id=occurrence_id)
|
|
2609
|
-
workspace_result = result
|
|
2436
|
+
workspace_result = result
|
|
2437
|
+
if len(result["findings"]) > FINDINGS_RESULT_LIMIT:
|
|
2438
|
+
workspace_result = dict(
|
|
2439
|
+
result, findings=result["findings"][:FINDINGS_RESULT_LIMIT], findingsTruncated=True
|
|
2440
|
+
)
|
|
2610
2441
|
workspace = workspace_state(
|
|
2611
2442
|
connection,
|
|
2612
2443
|
scan["workspace_id"],
|
|
@@ -2708,11 +2539,12 @@ def scan_result(
|
|
|
2708
2539
|
occurrence_rows = scan_history.finding_occurrence_rows(
|
|
2709
2540
|
connection, scan["id"], offset=0, limit=FINDINGS_RESULT_LIMIT
|
|
2710
2541
|
)
|
|
2711
|
-
if occurrence_id is not None
|
|
2542
|
+
if occurrence_id is not None:
|
|
2712
2543
|
occurrence = require_occurrence(connection, occurrence_id)
|
|
2713
2544
|
if occurrence["scan_id"] != scan["id"]:
|
|
2714
2545
|
raise SystemExit("This finding does not belong to the selected scan.")
|
|
2715
|
-
|
|
2546
|
+
if all(row["id"] != occurrence["id"] for row in occurrence_rows):
|
|
2547
|
+
occurrence_rows.append(occurrence)
|
|
2716
2548
|
finding_count = connection.execute(
|
|
2717
2549
|
"SELECT COUNT(*) FROM finding_occurrences WHERE scan_id = ?", (scan["id"],)
|
|
2718
2550
|
).fetchone()[0]
|
|
@@ -3248,10 +3080,8 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
|
|
|
3248
3080
|
scan_dir
|
|
3249
3081
|
):
|
|
3250
3082
|
raise SystemExit("Scan directory must be an existing canonical non-symlink directory.")
|
|
3251
|
-
# Re-check
|
|
3083
|
+
# Re-check ownership and parents so the scan directory cannot be substituted.
|
|
3252
3084
|
if os.name != "nt":
|
|
3253
|
-
if stat.S_IMODE(metadata.st_mode) & 0o077:
|
|
3254
|
-
raise SystemExit("Scan directory must not be accessible to other users (chmod 700).")
|
|
3255
3085
|
geteuid = getattr(os, "geteuid", None)
|
|
3256
3086
|
effective_uid = geteuid() if geteuid is not None else None
|
|
3257
3087
|
if effective_uid is not None and metadata.st_uid != effective_uid:
|
|
@@ -3306,12 +3136,8 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3306
3136
|
if args.command == "resolve-scan-root":
|
|
3307
3137
|
print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
|
|
3308
3138
|
return
|
|
3309
|
-
if args.command
|
|
3310
|
-
|
|
3311
|
-
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3312
|
-
return
|
|
3313
|
-
if args.command == "inspect-setup":
|
|
3314
|
-
print(json.dumps(inspect_selected_setup(args), allow_nan=False, sort_keys=True))
|
|
3139
|
+
if args.command in {"inspect-target", "inspect-setup"}:
|
|
3140
|
+
print(json.dumps(inspect_command(args), allow_nan=False, sort_keys=True))
|
|
3315
3141
|
return
|
|
3316
3142
|
if args.command in {"save-artifact", "read-artifact"}:
|
|
3317
3143
|
print(json.dumps(saved_results.read_or_save_artifact(args)))
|
|
@@ -3447,8 +3273,6 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
|
|
|
3447
3273
|
)
|
|
3448
3274
|
elif args.command == "database-info":
|
|
3449
3275
|
result = {"databasePath": str(database_path())}
|
|
3450
|
-
elif args.command == "local-dedupe":
|
|
3451
|
-
result = local_dedupe(connection, json.load(sys.stdin), now())
|
|
3452
3276
|
elif args.command == "finding-workflow":
|
|
3453
3277
|
result = finding_workflow(connection, json.load(sys.stdin), now())
|
|
3454
3278
|
else:
|