@openai/codex-security 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -788
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/baseline-auditor.md +18 -0
- package/_bundled_plugin/references/core-scan.md +5 -42
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/focused-investigator.md +13 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -2
- package/_bundled_plugin/references/scan-runtime.md +4 -2
- package/_bundled_plugin/references/security-guidance.md +14 -1
- package/_bundled_plugin/references/validate-scan-findings.md +3 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +29 -12
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -3
- package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
- package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
- package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
- package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
- package/_bundled_plugin/scripts/workbench/storage.py +25 -5
- package/_bundled_plugin/scripts/workbench_cli.py +24 -2
- package/_bundled_plugin/scripts/workbench_constants.py +2 -0
- package/_bundled_plugin/scripts/workbench_db.py +244 -217
- package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
- package/_bundled_plugin/scripts/workbench_progress.py +159 -3
- package/_bundled_plugin/scripts/workbench_publication.py +2 -3
- package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
- package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
- package/_bundled_plugin/scripts/workbench_scan_history.py +281 -119
- package/_bundled_plugin/scripts/workbench_scan_start.py +143 -9
- package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
- package/_bundled_plugin/scripts/workbench_schema.py +220 -14
- package/_bundled_plugin/scripts/workbench_setup.py +1 -1
- package/_bundled_plugin/scripts/workbench_target.py +471 -84
- package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
- package/_bundled_plugin/shared/workbench-history-repairs.json +60 -14
- package/_bundled_plugin/shared/workbench-migrations.json +66 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
- package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -160
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
- package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
- package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
- package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
- package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
- package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
- package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
- package/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +437 -154
- package/dist/api.js.map +1 -1
- package/dist/armorcode-findings.d.ts +9 -0
- package/dist/armorcode-findings.d.ts.map +1 -0
- package/dist/armorcode-findings.js +145 -0
- package/dist/armorcode-findings.js.map +1 -0
- package/dist/artifact-export.d.ts +2 -0
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +29 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +6 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +33 -12
- package/dist/auth.js.map +1 -1
- package/dist/batch-cost.d.ts +18 -0
- package/dist/batch-cost.d.ts.map +1 -0
- package/dist/batch-cost.js +41 -0
- package/dist/batch-cost.js.map +1 -0
- package/dist/blackduck-findings.d.ts +1 -1
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +5 -18
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bundled-plugin.d.ts +4 -0
- package/dist/bundled-plugin.d.ts.map +1 -0
- package/dist/bundled-plugin.js +23 -0
- package/dist/bundled-plugin.js.map +1 -0
- package/dist/classify-scan-severity.d.ts +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +11 -3
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +9 -6
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-argument.d.ts +4 -0
- package/dist/cli-argument.d.ts.map +1 -0
- package/dist/cli-argument.js +17 -0
- package/dist/cli-argument.js.map +1 -0
- package/dist/cli-help.d.ts +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +71 -29
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-hook.d.ts +3 -0
- package/dist/cli-hook.d.ts.map +1 -0
- package/dist/cli-hook.js +87 -0
- package/dist/cli-hook.js.map +1 -0
- package/dist/cli-integrations.d.ts +13 -0
- package/dist/cli-integrations.d.ts.map +1 -0
- package/dist/cli-integrations.js +333 -0
- package/dist/cli-integrations.js.map +1 -0
- package/dist/cli-mcp.d.ts +15 -0
- package/dist/cli-mcp.d.ts.map +1 -0
- package/dist/cli-mcp.js +178 -0
- package/dist/cli-mcp.js.map +1 -0
- package/dist/cli-token-view.d.ts +10 -0
- package/dist/cli-token-view.d.ts.map +1 -0
- package/dist/cli-token-view.js +41 -0
- package/dist/cli-token-view.js.map +1 -0
- package/dist/cli.d.ts +5 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1763 -894
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +33 -31
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +6 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +19 -0
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/command-words.d.ts +3 -0
- package/dist/command-words.d.ts.map +1 -0
- package/dist/command-words.js +46 -0
- package/dist/command-words.js.map +1 -0
- package/dist/component-scan.d.ts +3 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +40 -7
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +30 -1
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +93 -31
- package/dist/continuum-findings.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +1 -45
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +29 -19
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/local.d.ts +3 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +8 -1
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +2 -1
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +16 -15
- package/dist/deep-scan.js.map +1 -1
- package/dist/endor-findings.d.ts +2 -2
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +6 -23
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -3
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +3 -0
- package/dist/executable-path.d.ts.map +1 -1
- package/dist/executable-path.js +26 -0
- package/dist/executable-path.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +12 -1
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +66 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +234 -53
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +6 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +326 -1633
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +1 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +31 -51
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +1 -1
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +12 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +3 -11
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +29 -176
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-prompt.d.ts.map +1 -1
- package/dist/finding-prompt.js +2 -2
- package/dist/finding-prompt.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +3 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +19 -287
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-remediation.d.ts +1 -0
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +23 -3
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +19 -35
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +34 -27
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts +11 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -2
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +8 -4
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +4 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +79 -37
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts +4 -2
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +39 -22
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/private-finding-import.d.ts +8 -13
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +69 -129
- package/dist/private-finding-import.js.map +1 -1
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +53 -13
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +7 -2
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +42 -20
- package/dist/prompt-files.js.map +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +4 -9
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.d.ts +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js.map +1 -1
- package/dist/record.d.ts +1 -5
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +3 -51
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -1
- package/dist/remediation.js.map +1 -1
- package/dist/runtime.d.ts +35 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +778 -153
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +6 -1
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +267 -115
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-archive-path.d.ts +2 -0
- package/dist/scan-archive-path.d.ts.map +1 -0
- package/dist/scan-archive-path.js +5 -0
- package/dist/scan-archive-path.js.map +1 -0
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +6 -2
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +18 -2
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +4 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +25 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +28 -4
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +5 -11
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +16 -89
- package/dist/scanner-import.js.map +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +26 -6
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +14 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +20 -70
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +116 -333
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/snyk-findings.d.ts +2 -0
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +5 -8
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +3 -20
- package/dist/snyk-rest-findings.d.ts.map +1 -1
- package/dist/snyk-rest-findings.js +45 -217
- package/dist/snyk-rest-findings.js.map +1 -1
- package/dist/sonar-findings.d.ts +1 -1
- package/dist/sonar-findings.d.ts.map +1 -1
- package/dist/sonar-findings.js +2 -4
- package/dist/sonar-findings.js.map +1 -1
- package/dist/sonar-import.d.ts +3 -0
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +28 -30
- package/dist/sonar-import.js.map +1 -1
- package/dist/stored-finding-projection.d.ts +6 -0
- package/dist/stored-finding-projection.d.ts.map +1 -0
- package/dist/stored-finding-projection.js +104 -0
- package/dist/stored-finding-projection.js.map +1 -0
- package/dist/stored-findings-publication.d.ts +23 -0
- package/dist/stored-findings-publication.d.ts.map +1 -0
- package/dist/stored-findings-publication.js +169 -0
- package/dist/stored-findings-publication.js.map +1 -0
- package/dist/targets.d.ts +6 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +76 -23
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +1 -4
- package/dist/tenable-findings.d.ts.map +1 -1
- package/dist/tenable-findings.js.map +1 -1
- package/dist/trivy-findings.d.ts.map +1 -1
- package/dist/trivy-findings.js +0 -11
- package/dist/trivy-findings.js.map +1 -1
- package/dist/trusted-executable.d.ts +6 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +140 -37
- package/dist/trusted-executable.js.map +1 -1
- package/dist/veracode-findings.d.ts +1 -3
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +13 -38
- package/dist/veracode-findings.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +184 -32
- package/dist/version.js.map +1 -1
- package/dist/wiz-findings.d.ts +2 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +14 -92
- package/dist/wiz-findings.js.map +1 -1
- package/docs/cli.md +373 -106
- package/docs/findings-service.md +22 -9
- package/docs/hosted-remediation.md +13 -4
- package/docs/sdk.md +903 -0
- package/package.json +10 -6
- package/schemas/external-findings.schema.json +2 -1
- package/dist/hosted-scanner-v1.d.ts +0 -6
- package/dist/hosted-scanner-v1.d.ts.map +0 -1
- package/dist/hosted-scanner-v1.js +0 -60
- package/dist/hosted-scanner-v1.js.map +0 -1
- package/dist/reader-selection.d.ts +0 -15
- package/dist/reader-selection.d.ts.map +0 -1
- package/dist/reader-selection.js +0 -89
- package/dist/reader-selection.js.map +0 -1
- package/dist/semgrep-platform-v1.d.ts +0 -6
- package/dist/semgrep-platform-v1.d.ts.map +0 -1
- package/dist/semgrep-platform-v1.js +0 -83
- package/dist/semgrep-platform-v1.js.map +0 -1
- package/dist/snyk-rest-v1.d.ts +0 -28
- package/dist/snyk-rest-v1.d.ts.map +0 -1
- package/dist/snyk-rest-v1.js +0 -132
- package/dist/snyk-rest-v1.js.map +0 -1
|
@@ -8,11 +8,11 @@ import os
|
|
|
8
8
|
import sqlite3
|
|
9
9
|
import sys
|
|
10
10
|
from collections.abc import Iterable, Iterator
|
|
11
|
+
from fractions import Fraction
|
|
11
12
|
from functools import cache
|
|
12
13
|
from itertools import chain
|
|
13
14
|
from pathlib import Path, PurePosixPath
|
|
14
15
|
from typing import Any, Callable
|
|
15
|
-
from urllib.parse import urlsplit
|
|
16
16
|
|
|
17
17
|
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
18
18
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
@@ -26,13 +26,39 @@ from finalize_scan_contract import (
|
|
|
26
26
|
from report_projection import SEVERITY_ORDER
|
|
27
27
|
from review_state import review_state
|
|
28
28
|
from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX, PRIMARY_FINDING_LOCATION_SQL
|
|
29
|
-
from workbench_scan_start import scan_target_identity
|
|
30
29
|
from workbench_scan_usage import stored_scan_cost_fields
|
|
31
30
|
from workbench_source_scopes import public_scan_recipe
|
|
32
|
-
from workbench_target import
|
|
31
|
+
from workbench_target import (
|
|
32
|
+
require_remediation_target,
|
|
33
|
+
require_scan_target_identity,
|
|
34
|
+
verified_windows_checkout,
|
|
35
|
+
)
|
|
36
|
+
from workbench_target_state import (
|
|
37
|
+
RepositoryIdentityCache,
|
|
38
|
+
_timestamp_ns,
|
|
39
|
+
repository_relative_path,
|
|
40
|
+
same_repository_worktree,
|
|
41
|
+
scan_repository_generation,
|
|
42
|
+
)
|
|
33
43
|
from workbench_validation import timestamp_key
|
|
34
44
|
|
|
35
45
|
|
|
46
|
+
def reads_missing_history(args: argparse.Namespace, path: Path) -> bool:
|
|
47
|
+
"""Select an in-memory database only for history reads on a fresh profile."""
|
|
48
|
+
if args.command not in {"list-scans", "list-repositories", "list-global-findings"} and not (
|
|
49
|
+
args.command == "get-scan" and not (args.request_id or args.action_token)
|
|
50
|
+
):
|
|
51
|
+
return False
|
|
52
|
+
try:
|
|
53
|
+
path.lstat()
|
|
54
|
+
except FileNotFoundError:
|
|
55
|
+
return True
|
|
56
|
+
except OSError:
|
|
57
|
+
# The ordinary connection reports inaccessible storage.
|
|
58
|
+
pass
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
|
|
36
62
|
def rename_scan(connection: sqlite3.Connection, scan: sqlite3.Row, name: str) -> dict[str, Any]:
|
|
37
63
|
name = name.strip()
|
|
38
64
|
if not name:
|
|
@@ -53,6 +79,26 @@ def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
|
|
|
53
79
|
}
|
|
54
80
|
|
|
55
81
|
|
|
82
|
+
def expected_coverage_mode(scan: sqlite3.Row) -> str:
|
|
83
|
+
"""Return the coverage mode implied by the recorded scope, scan mode, and diff target kind."""
|
|
84
|
+
if scan["mode"] == "diff":
|
|
85
|
+
mode = {
|
|
86
|
+
"commit": "commit",
|
|
87
|
+
"range": "branch_diff",
|
|
88
|
+
"working_tree": "working_tree",
|
|
89
|
+
}.get(scan["diff_target_kind"])
|
|
90
|
+
if mode is None:
|
|
91
|
+
raise SystemExit("This migrated diff scan does not have a validated change set.")
|
|
92
|
+
return mode
|
|
93
|
+
if scan["scope"] != "." or (
|
|
94
|
+
"recipe_json" in scan.keys()
|
|
95
|
+
and scan["recipe_json"] is not None
|
|
96
|
+
and json.loads(scan["recipe_json"])["target"]["kind"] == "paths"
|
|
97
|
+
):
|
|
98
|
+
return "scoped_path"
|
|
99
|
+
return "deep_repository" if scan["mode"] == "deep" else "repository"
|
|
100
|
+
|
|
101
|
+
|
|
56
102
|
def preserve_sealed_completion(
|
|
57
103
|
binding: dict[str, Any], manifest: dict[str, Any] | None
|
|
58
104
|
) -> dict[str, Any]:
|
|
@@ -68,15 +114,34 @@ def preserve_sealed_completion(
|
|
|
68
114
|
return binding
|
|
69
115
|
|
|
70
116
|
|
|
117
|
+
def _windows_resume_checkout(scan: sqlite3.Row) -> Path:
|
|
118
|
+
from workbench_scan_start import scan_target_identity
|
|
119
|
+
|
|
120
|
+
replaced = "Cannot resume: the original checkout is missing or was replaced."
|
|
121
|
+
try:
|
|
122
|
+
repository = require_remediation_target(scan["target_path"])
|
|
123
|
+
except SystemExit as exc:
|
|
124
|
+
raise SystemExit(replaced) from exc
|
|
125
|
+
with verified_windows_checkout(scan, repository, replaced_message=replaced):
|
|
126
|
+
expected = (scan["target_revision"], scan["target_snapshot_digest"])
|
|
127
|
+
current = scan_target_identity(
|
|
128
|
+
repository, None, expected_digest=scan["target_snapshot_digest"]
|
|
129
|
+
)
|
|
130
|
+
if current[:2] != expected:
|
|
131
|
+
raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
|
|
132
|
+
return repository
|
|
133
|
+
|
|
134
|
+
|
|
71
135
|
def cli_scan_resume(
|
|
72
136
|
wb: Any,
|
|
73
137
|
connection: sqlite3.Connection,
|
|
74
138
|
scan: sqlite3.Row,
|
|
75
139
|
workspace: sqlite3.Row,
|
|
76
140
|
) -> dict[str, Any]:
|
|
141
|
+
|
|
77
142
|
scan = scan_with_progress(connection, scan["id"])
|
|
78
|
-
if scan["mode"]
|
|
79
|
-
raise SystemExit("Resume requires a Deep Scan with a saved CLI launch recipe.")
|
|
143
|
+
if scan["mode"] not in {"standard", "deep"} or scan["recipe_json"] is None:
|
|
144
|
+
raise SystemExit("Resume requires a Standard or Deep Scan with a saved CLI launch recipe.")
|
|
80
145
|
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
81
146
|
raise SystemExit(
|
|
82
147
|
"Resume requires a running scan; completed, failed, and canceled scans cannot resume."
|
|
@@ -97,21 +162,51 @@ def cli_scan_resume(
|
|
|
97
162
|
run["status"] not in {"running", "succeeded"} or run["cancel_requested"]
|
|
98
163
|
):
|
|
99
164
|
raise SystemExit("This Deep Scan has stopped and cannot resume.")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"Cannot
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
165
|
+
if os.name == "nt":
|
|
166
|
+
try:
|
|
167
|
+
repository = _windows_resume_checkout(scan)
|
|
168
|
+
except OSError as exc:
|
|
169
|
+
raise SystemExit(f"Cannot verify the original Windows checkout: {exc}") from exc
|
|
170
|
+
else:
|
|
171
|
+
from workbench_scan_start import scan_target_identity
|
|
172
|
+
|
|
173
|
+
try:
|
|
174
|
+
repository = require_scan_target_identity(scan)
|
|
175
|
+
except SystemExit as exc:
|
|
176
|
+
raise SystemExit(
|
|
177
|
+
"Cannot resume: the original checkout is missing or was replaced."
|
|
178
|
+
) from exc
|
|
179
|
+
if scan_target_identity(
|
|
180
|
+
repository, None, expected_digest=scan["target_snapshot_digest"]
|
|
181
|
+
) != (
|
|
182
|
+
scan["target_revision"],
|
|
183
|
+
scan["target_snapshot_digest"],
|
|
184
|
+
scan["target_device"],
|
|
185
|
+
scan["target_inode"],
|
|
186
|
+
):
|
|
187
|
+
raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
|
|
113
188
|
recipe = wb.parse_scan_recipe(scan["recipe_json"], repository)
|
|
114
189
|
scan_dir = wb.require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
190
|
+
if os.name == "nt":
|
|
191
|
+
from windows_scan_local_files import DEEP_RESUME_DIRECTORY, deep_resume_output_identity
|
|
192
|
+
|
|
193
|
+
identity = scan["windows_resume_output_identity"]
|
|
194
|
+
if identity is not None:
|
|
195
|
+
try:
|
|
196
|
+
current = deep_resume_output_identity(scan_dir)
|
|
197
|
+
except OSError as exc:
|
|
198
|
+
raise SystemExit(
|
|
199
|
+
f"Cannot verify the registered Windows resume output: {exc}"
|
|
200
|
+
) from exc
|
|
201
|
+
if current != json.loads(identity):
|
|
202
|
+
raise SystemExit(
|
|
203
|
+
"Cannot resume: the original Windows output directory was replaced."
|
|
204
|
+
)
|
|
205
|
+
elif not any(entry != scan_dir / DEEP_RESUME_DIRECTORY for entry in scan_dir.iterdir()):
|
|
206
|
+
raise SystemExit(
|
|
207
|
+
"Cannot resume this empty Windows output because its original directory identity "
|
|
208
|
+
f"was not saved. Start a new scan with 'codex-security scans rerun {scan['id']}'."
|
|
209
|
+
)
|
|
115
210
|
result = {
|
|
116
211
|
"contract": wb.scan_contract(scan),
|
|
117
212
|
"lifecycle": json.loads(scan["lifecycle_json"]),
|
|
@@ -215,59 +310,61 @@ def _windows_path_key(value: str) -> str:
|
|
|
215
310
|
|
|
216
311
|
|
|
217
312
|
def _same_repository(
|
|
313
|
+
connection: sqlite3.Connection,
|
|
218
314
|
before: sqlite3.Row,
|
|
219
315
|
after: sqlite3.Row,
|
|
220
316
|
*,
|
|
221
|
-
|
|
317
|
+
identities: RepositoryIdentityCache | None = None,
|
|
222
318
|
) -> bool:
|
|
223
|
-
|
|
319
|
+
before_stored = scan_repository_generation(before)
|
|
320
|
+
after_stored = scan_repository_generation(after)
|
|
321
|
+
if before_stored is not None and before_stored == after_stored:
|
|
224
322
|
return True
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
323
|
+
if before["target_id"] and before["target_id"] == after["target_id"]:
|
|
324
|
+
return before_stored is None or after_stored is None
|
|
325
|
+
identities = identities or RepositoryIdentityCache(connection)
|
|
326
|
+
before_state = identities.for_row(before)
|
|
327
|
+
after_state = identities.for_row(after)
|
|
328
|
+
if (
|
|
329
|
+
not before_state.ownership_matches
|
|
330
|
+
or not after_state.ownership_matches
|
|
331
|
+
or before_stored is not None
|
|
332
|
+
and before_stored != before_state.live_identity
|
|
333
|
+
or after_stored is not None
|
|
334
|
+
and after_stored != after_state.live_identity
|
|
335
|
+
):
|
|
336
|
+
return False
|
|
232
337
|
if (
|
|
233
|
-
|
|
234
|
-
and
|
|
235
|
-
and Path(before_git_dir).resolve() == Path(after_git_dir).resolve()
|
|
338
|
+
before_state.resolved_path is not None
|
|
339
|
+
and before_state.resolved_path == after_state.resolved_path
|
|
236
340
|
):
|
|
341
|
+
return before_stored is None or after_stored is None
|
|
342
|
+
if before_state.repository is None or after_state.repository is None:
|
|
343
|
+
if same_repository_worktree(Path(before_state.target_path), Path(after_state.target_path)):
|
|
344
|
+
return True
|
|
345
|
+
before_relative = repository_relative_path(Path(before_state.target_path))
|
|
346
|
+
after_relative = repository_relative_path(Path(after_state.target_path))
|
|
347
|
+
after_origin = identities.origin(after_state)
|
|
348
|
+
return (
|
|
349
|
+
before_relative is not None
|
|
350
|
+
and before_relative == after_relative
|
|
351
|
+
and after_origin is not None
|
|
352
|
+
and identities.origin(before_state) == after_origin
|
|
353
|
+
)
|
|
354
|
+
before_identity = before_state.live_identity
|
|
355
|
+
after_identity = after_state.live_identity
|
|
356
|
+
if before_identity is not None and before_identity == after_identity:
|
|
237
357
|
return True
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
358
|
+
if before_identity is None or after_identity is None:
|
|
359
|
+
return False
|
|
360
|
+
after_origin = identities.origin(after_state)
|
|
361
|
+
return (
|
|
362
|
+
after_origin is not None
|
|
363
|
+
and identities.origin(before_state) == after_origin
|
|
364
|
+
and before_state.repository.relative_path == after_state.repository.relative_path
|
|
242
365
|
)
|
|
243
366
|
|
|
244
367
|
|
|
245
|
-
def _repository_origin(remote: str | None) -> tuple[str, str] | None:
|
|
246
|
-
if remote is None:
|
|
247
|
-
return None
|
|
248
|
-
if "://" in remote:
|
|
249
|
-
try:
|
|
250
|
-
parsed = urlsplit(remote)
|
|
251
|
-
port = parsed.port
|
|
252
|
-
except ValueError:
|
|
253
|
-
return None
|
|
254
|
-
if parsed.scheme not in {"https", "ssh"} or parsed.hostname is None:
|
|
255
|
-
return None
|
|
256
|
-
if parsed.query or parsed.fragment:
|
|
257
|
-
return None
|
|
258
|
-
host = parsed.hostname
|
|
259
|
-
if port is not None and port != {"https": 443, "ssh": 22}[parsed.scheme]:
|
|
260
|
-
host = f"{host}:{port}"
|
|
261
|
-
path = parsed.path
|
|
262
|
-
else:
|
|
263
|
-
authority, separator, path = remote.partition(":")
|
|
264
|
-
if not separator or "?" in path or "#" in path:
|
|
265
|
-
return None
|
|
266
|
-
host = authority.rsplit("@", 1)[-1]
|
|
267
|
-
path = path.strip("/").removesuffix(".git")
|
|
268
|
-
return (host.lower(), path) if host and path else None
|
|
269
|
-
|
|
270
|
-
|
|
271
368
|
SCAN_SUMMARY_COLUMNS = """
|
|
272
369
|
scans.*,
|
|
273
370
|
lifecycle.snapshot AS lifecycle_json,
|
|
@@ -363,30 +460,27 @@ def list_scans(
|
|
|
363
460
|
connection.create_function("codex_security_path_key", 1, _windows_path_key)
|
|
364
461
|
clauses: list[str] = []
|
|
365
462
|
values: list[Any] = []
|
|
463
|
+
worktree_order = ""
|
|
366
464
|
if args is not None and args.repository:
|
|
367
|
-
repository = Path(args.repository).expanduser().
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
placeholders = ", ".join("?" for _ in related_target_ids)
|
|
387
|
-
repository_clauses.append(f"scans.target_id IN ({placeholders})")
|
|
388
|
-
values.extend(related_target_ids)
|
|
389
|
-
clauses.append(f"({' OR '.join(repository_clauses)})")
|
|
465
|
+
repository = Path(args.repository).expanduser().absolute()
|
|
466
|
+
identities = RepositoryIdentityCache(connection)
|
|
467
|
+
repository = Path(identities.history_path(str(repository)))
|
|
468
|
+
clause, scope_values = identities.scope_for_path(str(repository)).sql(
|
|
469
|
+
supports_generation=identities.supports_generation
|
|
470
|
+
)
|
|
471
|
+
clauses.append(clause)
|
|
472
|
+
values.extend(scope_values)
|
|
473
|
+
if getattr(args, "prefer_worktree", False):
|
|
474
|
+
|
|
475
|
+
@cache
|
|
476
|
+
def in_worktree(target_path: str) -> bool:
|
|
477
|
+
try:
|
|
478
|
+
return repository.samefile(target_path)
|
|
479
|
+
except OSError:
|
|
480
|
+
return False
|
|
481
|
+
|
|
482
|
+
connection.create_function("in_worktree", 1, in_worktree)
|
|
483
|
+
worktree_order = "in_worktree(scans.target_path) DESC,"
|
|
390
484
|
if args is not None and args.scan_root:
|
|
391
485
|
scan_root = str(Path(args.scan_root).expanduser().resolve())
|
|
392
486
|
prefix = scan_root.rstrip(os.sep) + os.sep
|
|
@@ -433,7 +527,7 @@ def list_scans(
|
|
|
433
527
|
f"""
|
|
434
528
|
{SCAN_SUMMARY_QUERY}
|
|
435
529
|
{where}
|
|
436
|
-
ORDER BY
|
|
530
|
+
ORDER BY {worktree_order}
|
|
437
531
|
CASE WHEN scans.status = 'running' AND scans.canceled_at IS NULL THEN 0 ELSE 1 END,
|
|
438
532
|
MAX(julianday(upper(scans.updated_at)), julianday(upper(progress.updated_at))) DESC,
|
|
439
533
|
julianday(upper(scans.started_at)) DESC,
|
|
@@ -442,7 +536,11 @@ def list_scans(
|
|
|
442
536
|
""",
|
|
443
537
|
values,
|
|
444
538
|
).fetchall()
|
|
445
|
-
|
|
539
|
+
scans = [scan_summary(row) for row in rows[:limit]]
|
|
540
|
+
if worktree_order:
|
|
541
|
+
for scan in scans:
|
|
542
|
+
scan["inCurrentWorktree"] = in_worktree(scan["targetPath"])
|
|
543
|
+
result = {"scans": scans}
|
|
446
544
|
if limit is not None:
|
|
447
545
|
result.update(
|
|
448
546
|
{
|
|
@@ -454,6 +552,17 @@ def list_scans(
|
|
|
454
552
|
return result
|
|
455
553
|
|
|
456
554
|
|
|
555
|
+
def _scan_completion_order(scan: sqlite3.Row) -> tuple[int, int | Fraction, str]:
|
|
556
|
+
sequence = scan["completion_sequence"] if "completion_sequence" in scan.keys() else None
|
|
557
|
+
if sequence is not None:
|
|
558
|
+
return (1, sequence, scan["id"])
|
|
559
|
+
completed_at = scan["completed_at"] if "completed_at" in scan.keys() else None
|
|
560
|
+
timestamp = _timestamp_ns(completed_at)
|
|
561
|
+
if timestamp is None:
|
|
562
|
+
timestamp = _timestamp_ns(scan["started_at"])
|
|
563
|
+
return (0, timestamp if timestamp is not None else 0, scan["id"])
|
|
564
|
+
|
|
565
|
+
|
|
457
566
|
_FindingSites = dict[tuple[str, str | None, PurePosixPath, int, int], dict[str, Any] | None]
|
|
458
567
|
# Match the first location shown by compactFinding in finding-catalogue.ts.
|
|
459
568
|
_COMPARISON_LOCATION_RANK = {"root_control": 0, "expected_control": 1, "concrete_implementation": 1}
|
|
@@ -516,50 +625,58 @@ def list_unmatched_scan_pairs(
|
|
|
516
625
|
backfill_finding_details: Callable[[sqlite3.Connection, sqlite3.Row], None],
|
|
517
626
|
read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
|
|
518
627
|
) -> dict[str, Any]:
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if target not in membership:
|
|
533
|
-
membership[target] = _same_repository(scan, requested, after_git=requested_git)
|
|
534
|
-
if membership[target]:
|
|
535
|
-
selected.append(scan)
|
|
628
|
+
requested_repository = Path(args.repository).expanduser().absolute()
|
|
629
|
+
repository = requested_repository.resolve()
|
|
630
|
+
identities = RepositoryIdentityCache(connection)
|
|
631
|
+
requested = identities.for_path(str(requested_repository))
|
|
632
|
+
if identities.supports_identity:
|
|
633
|
+
requested.require_owner()
|
|
634
|
+
clause, values = identities.scope_for_path(str(requested_repository)).sql(
|
|
635
|
+
supports_generation=identities.supports_generation
|
|
636
|
+
)
|
|
637
|
+
selected = connection.execute(
|
|
638
|
+
f"SELECT * FROM scans WHERE status = 'complete' AND {clause}",
|
|
639
|
+
values,
|
|
640
|
+
).fetchall()
|
|
536
641
|
|
|
537
642
|
selected.sort(key=lambda scan: (timestamp_key(scan["started_at"]), scan["id"]))
|
|
538
643
|
|
|
539
644
|
available = []
|
|
540
|
-
for
|
|
645
|
+
for scan in selected:
|
|
541
646
|
try:
|
|
542
647
|
read_coverage(scan)
|
|
543
648
|
except SystemExit:
|
|
544
649
|
continue
|
|
545
|
-
available.append(
|
|
650
|
+
available.append(scan)
|
|
546
651
|
|
|
547
652
|
saved_pairs = {
|
|
548
|
-
(row["before_scan_id"], row["after_scan_id"])
|
|
653
|
+
frozenset((row["before_scan_id"], row["after_scan_id"]))
|
|
549
654
|
for row in connection.execute("SELECT before_scan_id, after_scan_id FROM scan_comparisons")
|
|
550
655
|
}
|
|
656
|
+
focus_scan_id = getattr(args, "after_scan_id", None)
|
|
657
|
+
if focus_scan_id is not None and not any(scan["id"] == focus_scan_id for scan in selected):
|
|
658
|
+
raise SystemExit("The scan to match is not a completed scan in this repository.")
|
|
659
|
+
if focus_scan_id is not None:
|
|
660
|
+
available.sort(key=_scan_completion_order)
|
|
551
661
|
batches = []
|
|
552
662
|
skipped = 0
|
|
553
663
|
matching_findings: dict[str, list[dict[str, Any]]] = {}
|
|
554
664
|
sites: dict[str, _FindingSites] = {}
|
|
555
665
|
known_links: list[sqlite3.Row] | None = None
|
|
556
|
-
for index,
|
|
666
|
+
for index, after in enumerate(available):
|
|
667
|
+
if focus_scan_id is not None and after["id"] != focus_scan_id:
|
|
668
|
+
continue
|
|
669
|
+
candidates = [
|
|
670
|
+
before
|
|
671
|
+
for before in available[:index]
|
|
672
|
+
if _same_repository(connection, before, after, identities=identities)
|
|
673
|
+
]
|
|
557
674
|
previous = [
|
|
558
675
|
before
|
|
559
|
-
for
|
|
560
|
-
if args.force or (before["id"], after["id"]) not in saved_pairs
|
|
676
|
+
for before in candidates
|
|
677
|
+
if args.force or frozenset((before["id"], after["id"])) not in saved_pairs
|
|
561
678
|
]
|
|
562
|
-
skipped +=
|
|
679
|
+
skipped += len(candidates) - len(previous)
|
|
563
680
|
if not previous:
|
|
564
681
|
continue
|
|
565
682
|
if known_links is None:
|
|
@@ -576,7 +693,16 @@ def list_unmatched_scan_pairs(
|
|
|
576
693
|
]
|
|
577
694
|
known_groups = _known_finding_groups(
|
|
578
695
|
known_links,
|
|
579
|
-
{
|
|
696
|
+
{
|
|
697
|
+
scan["id"]
|
|
698
|
+
for scan in selected
|
|
699
|
+
if (
|
|
700
|
+
_scan_completion_order(scan) <= _scan_completion_order(after)
|
|
701
|
+
if focus_scan_id is not None
|
|
702
|
+
else (timestamp_key(scan["started_at"]), scan["id"])
|
|
703
|
+
<= (timestamp_key(after["started_at"]), after["id"])
|
|
704
|
+
)
|
|
705
|
+
},
|
|
580
706
|
)
|
|
581
707
|
batches.append(
|
|
582
708
|
{
|
|
@@ -666,7 +792,7 @@ def compare_scans(
|
|
|
666
792
|
raise SystemExit("Select two different scans to compare.")
|
|
667
793
|
if before["status"] != "complete" or after["status"] != "complete":
|
|
668
794
|
raise SystemExit("Only completed scans can be compared.")
|
|
669
|
-
if not _same_repository(before, after):
|
|
795
|
+
if not _same_repository(connection, before, after):
|
|
670
796
|
raise SystemExit("Semantic scan comparisons require the same repository target.")
|
|
671
797
|
cached = connection.execute(
|
|
672
798
|
"SELECT result_json FROM scan_comparisons WHERE before_scan_id = ? AND after_scan_id = ?",
|
|
@@ -683,7 +809,7 @@ def compare_scans(
|
|
|
683
809
|
f"'codex-security scans compare {after['id']} {before['id']}'."
|
|
684
810
|
)
|
|
685
811
|
raise SystemExit(
|
|
686
|
-
"No saved matches for these scans. Run 'codex-security scans
|
|
812
|
+
"No saved matches for these scans. Run 'codex-security scans compare BEFORE AFTER' first."
|
|
687
813
|
)
|
|
688
814
|
if include_matching_inputs and backfill_finding_details is not None:
|
|
689
815
|
backfill_finding_details(connection, before)
|
|
@@ -801,14 +927,13 @@ def compare_scans(
|
|
|
801
927
|
for pair in related
|
|
802
928
|
]
|
|
803
929
|
if include_matching_inputs:
|
|
930
|
+
identities = RepositoryIdentityCache(connection)
|
|
804
931
|
after_key = (timestamp_key(after["started_at"]), after["id"])
|
|
805
932
|
known_scan_ids = {
|
|
806
933
|
scan["id"]
|
|
807
|
-
for scan in connection.execute(
|
|
808
|
-
"SELECT id, started_at, target_id, target_path FROM scans WHERE status = 'complete'"
|
|
809
|
-
)
|
|
934
|
+
for scan in connection.execute("SELECT * FROM scans WHERE status = 'complete'")
|
|
810
935
|
if (timestamp_key(scan["started_at"]), scan["id"]) <= after_key
|
|
811
|
-
and _same_repository(scan, after)
|
|
936
|
+
and _same_repository(connection, scan, after, identities=identities)
|
|
812
937
|
}
|
|
813
938
|
excluded_pairs = {(before["id"], after["id"]), (after["id"], before["id"])}
|
|
814
939
|
known_groups = _known_finding_groups(
|
|
@@ -847,7 +972,7 @@ def save_scan_comparison(
|
|
|
847
972
|
raise SystemExit("Select two different scans to compare.")
|
|
848
973
|
if before["status"] != "complete" or after["status"] != "complete":
|
|
849
974
|
raise SystemExit("Only completed scans can be compared.")
|
|
850
|
-
if not _same_repository(before, after):
|
|
975
|
+
if not _same_repository(connection, before, after):
|
|
851
976
|
raise SystemExit("Semantic scan comparisons require the same repository target.")
|
|
852
977
|
read_coverage(after)
|
|
853
978
|
allowed = {
|
|
@@ -928,8 +1053,10 @@ def save_scan_comparison(
|
|
|
928
1053
|
with connection:
|
|
929
1054
|
connection.execute("BEGIN IMMEDIATE")
|
|
930
1055
|
connection.execute(
|
|
931
|
-
"DELETE FROM scan_comparisons
|
|
932
|
-
|
|
1056
|
+
"DELETE FROM scan_comparisons "
|
|
1057
|
+
"WHERE (before_scan_id = ? AND after_scan_id = ?) "
|
|
1058
|
+
"OR (before_scan_id = ? AND after_scan_id = ?)",
|
|
1059
|
+
(before["id"], after["id"], after["id"], before["id"]),
|
|
933
1060
|
)
|
|
934
1061
|
connection.execute(
|
|
935
1062
|
"""
|
|
@@ -1091,6 +1218,41 @@ def finding_relations(
|
|
|
1091
1218
|
return result
|
|
1092
1219
|
|
|
1093
1220
|
|
|
1221
|
+
def finding_management_updated_at(connection: sqlite3.Connection, scan_id: str) -> str | None:
|
|
1222
|
+
return connection.execute(
|
|
1223
|
+
"""
|
|
1224
|
+
SELECT MAX(updated_at)
|
|
1225
|
+
FROM (
|
|
1226
|
+
SELECT triage.updated_at
|
|
1227
|
+
FROM finding_triage AS triage
|
|
1228
|
+
JOIN finding_occurrences AS occurrences ON occurrences.id = triage.occurrence_id
|
|
1229
|
+
WHERE occurrences.scan_id = ?
|
|
1230
|
+
UNION ALL
|
|
1231
|
+
SELECT remediation.updated_at
|
|
1232
|
+
FROM finding_remediation_attempts AS remediation
|
|
1233
|
+
JOIN finding_occurrences AS occurrences ON occurrences.id = remediation.occurrence_id
|
|
1234
|
+
WHERE occurrences.scan_id = ?
|
|
1235
|
+
)
|
|
1236
|
+
""",
|
|
1237
|
+
(scan_id, scan_id),
|
|
1238
|
+
).fetchone()[0]
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
def finding_triage_result(connection: sqlite3.Connection, occurrence_id: str) -> dict[str, Any]:
|
|
1242
|
+
row = connection.execute(
|
|
1243
|
+
"SELECT status, close_reason, note, updated_at FROM finding_triage WHERE occurrence_id = ?",
|
|
1244
|
+
(occurrence_id,),
|
|
1245
|
+
).fetchone()
|
|
1246
|
+
if row is None:
|
|
1247
|
+
return {"status": "open"}
|
|
1248
|
+
return {
|
|
1249
|
+
"closeReason": row["close_reason"],
|
|
1250
|
+
"note": row["note"],
|
|
1251
|
+
"status": row["status"],
|
|
1252
|
+
"updatedAt": row["updated_at"],
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
|
|
1094
1256
|
def finding_matches(
|
|
1095
1257
|
connection: sqlite3.Connection, occurrence_id: str, scan_id: str, started_at: str
|
|
1096
1258
|
) -> tuple[list[dict[str, Any]], str, list[str]]:
|