@openai/codex-security 0.1.26 → 0.1.28
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 +637 -74
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs +24 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/COPYRIGHT-library.html +5556 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +5989 -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/licenses/Apache-2.0.txt +73 -0
- package/_bundled_plugin/mcp/native/licenses/BSD-2-Clause.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/MIT.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/Unicode-3.0.txt +39 -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.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +56 -0
- package/_bundled_plugin/references/config-preflight.md +9 -1
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +2 -0
- package/_bundled_plugin/references/scan-artifacts.md +6 -14
- package/_bundled_plugin/references/scan-contract.md +35 -35
- package/_bundled_plugin/references/scan-prologue.md +2 -0
- package/_bundled_plugin/references/security-guidance.md +9 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +10 -8
- package/_bundled_plugin/scripts/deep_scan_defaults.json +8 -0
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -2
- package/_bundled_plugin/scripts/generate_rank_input.py +8 -1
- package/_bundled_plugin/scripts/launch_codex_security_mcp +6 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +43 -9
- package/_bundled_plugin/scripts/rank_preview.py +4 -1
- package/_bundled_plugin/scripts/reserved_artifact_paths.json +6 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +1 -3
- package/_bundled_plugin/scripts/workbench/storage.py +18 -0
- package/_bundled_plugin/scripts/workbench_cli.py +17 -0
- package/_bundled_plugin/scripts/workbench_db.py +46 -42
- package/_bundled_plugin/scripts/workbench_saved_results.py +72 -1
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +23 -10
- package/_bundled_plugin/scripts/workbench_validation.py +4 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +2 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +2 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +5 -1
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +3 -3
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +3 -1
- package/_bundled_plugin/skills/fix-finding/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +2 -0
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +5 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -0
- package/_bundled_plugin/skills/validation/SKILL.md +2 -0
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +2 -0
- package/dist/api.d.ts +14 -24
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +585 -168
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +10 -0
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +2 -2
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +24 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1577 -610
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +2 -207
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +116 -32
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +4 -2
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +7 -1
- package/dist/component-scan.js.map +1 -1
- package/dist/config-path.d.ts +6 -0
- package/dist/config-path.d.ts.map +1 -0
- package/dist/config-path.js +6 -0
- package/dist/config-path.js.map +1 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +30 -5
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -10
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +30 -0
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +123 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +18 -3
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.js.map +1 -1
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +6 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +72 -17
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts +2 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +99 -26
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/retry.d.ts +3 -0
- package/dist/deduplication/retry.d.ts.map +1 -0
- package/dist/deduplication/retry.js +15 -0
- package/dist/deduplication/retry.js.map +1 -0
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +4 -2
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +17 -0
- package/dist/deep-config.d.ts.map +1 -0
- package/dist/deep-config.js +145 -0
- package/dist/deep-config.js.map +1 -0
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-scan-defaults.d.ts +9 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -0
- package/dist/deep-scan-defaults.js +10 -0
- package/dist/deep-scan-defaults.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/feedback.d.ts +20 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +135 -0
- package/dist/feedback.js.map +1 -0
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-client.d.ts +7 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +55 -10
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-import.d.ts +44 -0
- package/dist/findings-import.d.ts.map +1 -0
- package/dist/findings-import.js +302 -0
- package/dist/findings-import.js.map +1 -0
- package/dist/github.d.ts +625 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js.map +1 -1
- package/dist/import-scan.d.ts +27 -0
- package/dist/import-scan.d.ts.map +1 -0
- package/dist/import-scan.js +236 -0
- package/dist/import-scan.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.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 +19 -8
- package/dist/knowledge-base.js.map +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts +7 -5
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +212 -55
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +191 -0
- package/dist/project-config-schema.d.ts.map +1 -0
- package/dist/project-config-schema.js +85 -0
- package/dist/project-config-schema.js.map +1 -0
- package/dist/project-config.d.ts +50 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +220 -0
- package/dist/project-config.js.map +1 -0
- package/dist/prompt-files.d.ts +13 -0
- package/dist/prompt-files.d.ts.map +1 -0
- package/dist/prompt-files.js +74 -0
- package/dist/prompt-files.js.map +1 -0
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +7 -2
- package/dist/publication-events.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +1 -1
- package/dist/publish.js.map +1 -1
- package/dist/result.d.ts +2 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +5 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +12 -6
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- 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 +45 -20
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +39 -3
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +77 -15
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-modes.d.ts +3 -0
- package/dist/scan-modes.d.ts.map +1 -0
- package/dist/scan-modes.js +2 -0
- package/dist/scan-modes.js.map +1 -0
- package/dist/scan-settings.d.ts +81 -0
- package/dist/scan-settings.d.ts.map +1 -0
- package/dist/scan-settings.js +123 -0
- package/dist/scan-settings.js.map +1 -0
- package/dist/security-policy-cli.d.ts +39 -0
- package/dist/security-policy-cli.d.ts.map +1 -0
- package/dist/security-policy-cli.js +193 -0
- package/dist/security-policy-cli.js.map +1 -0
- package/dist/security-policy.d.ts +80 -0
- package/dist/security-policy.d.ts.map +1 -0
- package/dist/security-policy.js +672 -0
- package/dist/security-policy.js.map +1 -0
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/server/dashboard/app.js +2 -2
- package/dist/server/dashboard.js.map +1 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/findings-service.d.ts.map +1 -1
- package/dist/server/findings-service.js.map +1 -1
- package/dist/server/serve.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js.map +1 -1
- package/dist/targets.d.ts +10 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +243 -14
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js.map +1 -1
- package/package.json +36 -29
- package/schemas/project-config.schema.json +211 -0
- package/_bundled_plugin/scripts/resolve_security_md.py +0 -158
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
setlocal DisableDelayedExpansion
|
|
3
3
|
|
|
4
4
|
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\server.mjs"
|
|
5
|
+
if "%~1"=="--helper" (
|
|
6
|
+
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\helpers.mjs"
|
|
7
|
+
goto launch
|
|
8
|
+
)
|
|
5
9
|
|
|
6
10
|
rem This process waits for Node and must not keep the installed plugin directory locked.
|
|
7
11
|
if "%~d0"=="" (cd /d "%SystemRoot%") else (cd /d "%~d0\")
|
|
@@ -10,18 +14,48 @@ if errorlevel 1 (
|
|
|
10
14
|
exit /b 1
|
|
11
15
|
)
|
|
12
16
|
|
|
17
|
+
:launch
|
|
13
18
|
rem WindowsApps can expose a Node path that exists but cannot be executed.
|
|
14
19
|
rem Prefer relocated user-writable runtimes before probing packaged paths.
|
|
15
|
-
if defined LOCALAPPDATA for /d %%D in ("%LOCALAPPDATA%\OpenAI\Codex\runtimes\cua_node\*") do if exist "%%~fD\bin\node.exe" (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if defined
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if defined LOCALAPPDATA for /d %%D in ("%LOCALAPPDATA%\OpenAI\Codex\runtimes\cua_node\*") do if exist "%%~fD\bin\node.exe" (
|
|
21
|
+
set "CODEX_SECURITY_MCP_NODE=%%~fD\bin\node.exe"
|
|
22
|
+
goto run
|
|
23
|
+
)
|
|
24
|
+
if defined XDG_CACHE_HOME if exist "%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" (
|
|
25
|
+
set "CODEX_SECURITY_MCP_NODE=%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe"
|
|
26
|
+
goto run
|
|
27
|
+
)
|
|
28
|
+
if defined USERPROFILE if exist "%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" (
|
|
29
|
+
set "CODEX_SECURITY_MCP_NODE=%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe"
|
|
30
|
+
goto run
|
|
31
|
+
)
|
|
32
|
+
if defined CODEX_MCP_NODE_PATH if exist "%CODEX_MCP_NODE_PATH%" (
|
|
33
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_MCP_NODE_PATH%"
|
|
34
|
+
goto run
|
|
35
|
+
)
|
|
36
|
+
if defined CODEX_BROWSER_USE_NODE_PATH if exist "%CODEX_BROWSER_USE_NODE_PATH%" (
|
|
37
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_BROWSER_USE_NODE_PATH%"
|
|
38
|
+
goto run
|
|
39
|
+
)
|
|
40
|
+
if defined CODEX_ELECTRON_RESOURCES_PATH if exist "%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" (
|
|
41
|
+
set "CODEX_SECURITY_MCP_NODE=%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe"
|
|
42
|
+
goto run
|
|
43
|
+
)
|
|
44
|
+
if defined CODEX_CLI_PATH for %%I in ("%CODEX_CLI_PATH%") do if exist "%%~dpIcua_node\bin\node.exe" (
|
|
45
|
+
set "CODEX_SECURITY_MCP_NODE=%%~dpIcua_node\bin\node.exe"
|
|
46
|
+
goto run
|
|
47
|
+
)
|
|
22
48
|
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
rem Resolve Node from PATH once and launch that exact executable.
|
|
50
|
+
set "CODEX_SECURITY_MCP_SEARCH_PATH=%PATH:"=%"
|
|
51
|
+
for %%I in (node.exe) do set "CODEX_SECURITY_MCP_NODE=%%~$CODEX_SECURITY_MCP_SEARCH_PATH:I"
|
|
52
|
+
if defined CODEX_SECURITY_MCP_NODE goto run
|
|
25
53
|
|
|
26
54
|
echo Codex Security could not find a Node runtime. Reinstall or update Codex, or set CODEX_MCP_NODE_PATH to an executable Node runtime. 1>&2
|
|
27
55
|
exit /b 127
|
|
56
|
+
|
|
57
|
+
:run
|
|
58
|
+
rem Direct invocation also chains batch shims without CALL reparsing paths.
|
|
59
|
+
"%CODEX_SECURITY_MCP_NODE%" "%CODEX_SECURITY_MCP_SCRIPT%" %*
|
|
60
|
+
if "%~1"=="--helper" exit /b %errorlevel%
|
|
61
|
+
exit
|
|
@@ -17,10 +17,12 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
17
17
|
".c",
|
|
18
18
|
".cc",
|
|
19
19
|
".cfg",
|
|
20
|
+
".cjs",
|
|
20
21
|
".clj",
|
|
21
22
|
".cpp",
|
|
22
23
|
".cs",
|
|
23
24
|
".css",
|
|
25
|
+
".cts",
|
|
24
26
|
".cue",
|
|
25
27
|
".cxx",
|
|
26
28
|
".dart",
|
|
@@ -41,6 +43,7 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
41
43
|
".lua",
|
|
42
44
|
".mjs",
|
|
43
45
|
".mm",
|
|
46
|
+
".mts",
|
|
44
47
|
".php",
|
|
45
48
|
".proto",
|
|
46
49
|
".ps1",
|
|
@@ -62,7 +65,7 @@ TEXT_CODE_EXTENSIONS = {
|
|
|
62
65
|
".yml",
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
JAVASCRIPT_EXTENSIONS = {".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"}
|
|
68
|
+
JAVASCRIPT_EXTENSIONS = {".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx", ".vue"}
|
|
66
69
|
JAVA_LIKE_EXTENSIONS = {".c", ".cc", ".cpp", ".cs", ".cxx", ".h", ".hpp", ".java", ".mm"}
|
|
67
70
|
BRACE_LANGUAGE_EXTENSIONS = {
|
|
68
71
|
*JAVASCRIPT_EXTENSIONS,
|
|
@@ -465,7 +465,7 @@ def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
|
|
|
465
465
|
flags=_FILE_FLAG_OPEN_REPARSE_POINT,
|
|
466
466
|
)
|
|
467
467
|
assert handle is not None and handle.value is not None
|
|
468
|
-
|
|
468
|
+
with handle:
|
|
469
469
|
_verify_regular_file(handle.value, path)
|
|
470
470
|
raw_handle = handle.detach()
|
|
471
471
|
try:
|
|
@@ -474,8 +474,6 @@ def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
|
|
|
474
474
|
except BaseException:
|
|
475
475
|
_close_handle(raw_handle)
|
|
476
476
|
raise
|
|
477
|
-
finally:
|
|
478
|
-
handle.close()
|
|
479
477
|
except WindowsScanLocalFileError as exc:
|
|
480
478
|
raise WindowsScanLocalFileError(
|
|
481
479
|
exc.errno,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Storage paths shared by workbench persistence and MCP artifact selection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def state_dir() -> Path:
|
|
10
|
+
state_dir = os.environ.get("CODEX_SECURITY_STATE_DIR")
|
|
11
|
+
if state_dir:
|
|
12
|
+
return Path(state_dir).expanduser().resolve()
|
|
13
|
+
codex_home = Path(os.environ.get("CODEX_HOME", "~/.codex")).expanduser()
|
|
14
|
+
return (codex_home / "state" / "plugins" / "codex-security").resolve()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def resolve_scan_root(scan_root: str | None) -> Path:
|
|
18
|
+
return Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"
|
|
@@ -34,6 +34,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
34
34
|
parser = argparse.ArgumentParser(description=description)
|
|
35
35
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
36
36
|
|
|
37
|
+
resolve_scan_root = subparsers.add_parser("resolve-scan-root")
|
|
38
|
+
resolve_scan_root.add_argument("--scan-root")
|
|
39
|
+
|
|
37
40
|
create_workspace = subparsers.add_parser("create-workspace")
|
|
38
41
|
create_workspace.add_argument("--workspace-id", required=True)
|
|
39
42
|
create_workspace.add_argument("--thread-id")
|
|
@@ -167,6 +170,10 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
167
170
|
get_scan_recipe = subparsers.add_parser("get-scan-recipe")
|
|
168
171
|
get_scan_recipe.add_argument("--scan-id", required=True)
|
|
169
172
|
|
|
173
|
+
get_cli_scan_resume = subparsers.add_parser("get-cli-scan-resume")
|
|
174
|
+
get_cli_scan_resume.add_argument("--scan-id", required=True)
|
|
175
|
+
get_cli_scan_resume.add_argument("--allow-unavailable", action="store_true")
|
|
176
|
+
|
|
170
177
|
compare_scans = subparsers.add_parser("compare-scans")
|
|
171
178
|
compare_scans.add_argument("--before-scan-id", required=True)
|
|
172
179
|
compare_scans.add_argument("--after-scan-id", required=True)
|
|
@@ -267,6 +274,16 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
267
274
|
write_scan_draft.add_argument("--expected-draft-digest")
|
|
268
275
|
write_scan_draft.add_argument("--claim-token")
|
|
269
276
|
|
|
277
|
+
save_scan_artifact = subparsers.add_parser("save-scan-artifact")
|
|
278
|
+
save_scan_artifact.add_argument("--scan-id", required=True)
|
|
279
|
+
save_scan_artifact.add_argument("--artifact-path", required=True)
|
|
280
|
+
save_scan_artifact.add_argument("--claim-token")
|
|
281
|
+
|
|
282
|
+
for command in ("save-artifact", "read-artifact"):
|
|
283
|
+
artifact = subparsers.add_parser(command)
|
|
284
|
+
artifact.add_argument("--artifact-root", required=True)
|
|
285
|
+
artifact.add_argument("--artifact-path", required=True)
|
|
286
|
+
|
|
270
287
|
mark_handoff_delivered = subparsers.add_parser("mark-handoff-delivered")
|
|
271
288
|
mark_handoff_delivered.add_argument("--scan-id", required=True)
|
|
272
289
|
mark_handoff_delivered.add_argument("--claim-token", required=True)
|
|
@@ -60,6 +60,7 @@ from finalize_scan_contract import (
|
|
|
60
60
|
)
|
|
61
61
|
from finding_preview import bounded_finding_details
|
|
62
62
|
from workbench import handoff
|
|
63
|
+
from workbench.storage import resolve_scan_root, state_dir
|
|
63
64
|
from workbench_cli import parse_args
|
|
64
65
|
from workbench_constants import (
|
|
65
66
|
ARTIFACTS,
|
|
@@ -138,6 +139,7 @@ from workbench_validation import (
|
|
|
138
139
|
optional_text,
|
|
139
140
|
parse_scan_cost,
|
|
140
141
|
path_within_scope,
|
|
142
|
+
reject_non_finite_json,
|
|
141
143
|
require_close_note,
|
|
142
144
|
require_occurrence,
|
|
143
145
|
require_uuid,
|
|
@@ -148,7 +150,6 @@ from workbench_validation import (
|
|
|
148
150
|
FINDING_ARTIFACT_DIRECTORIES_LIMIT = 80
|
|
149
151
|
FINDING_ARTIFACTS_LIMIT = 40
|
|
150
152
|
FINDING_WRITEUP_REPORT_PATH = re.compile(r"^findings/([a-z0-9][a-z0-9._-]*)/\1\.md$")
|
|
151
|
-
SCAN_RECIPE_MAX_BYTES = 256 * 1024
|
|
152
153
|
|
|
153
154
|
|
|
154
155
|
def now() -> str:
|
|
@@ -161,14 +162,6 @@ def stale_claim_before(seconds: int = CLAIM_LEASE_SECONDS) -> str:
|
|
|
161
162
|
)
|
|
162
163
|
|
|
163
164
|
|
|
164
|
-
def state_dir() -> Path:
|
|
165
|
-
state_dir = os.environ.get("CODEX_SECURITY_STATE_DIR")
|
|
166
|
-
if state_dir:
|
|
167
|
-
return Path(state_dir).expanduser().resolve()
|
|
168
|
-
codex_home = Path(os.environ.get("CODEX_HOME", "~/.codex")).expanduser()
|
|
169
|
-
return (codex_home / "state" / "plugins" / "codex-security").resolve()
|
|
170
|
-
|
|
171
|
-
|
|
172
165
|
def database_path() -> Path:
|
|
173
166
|
return state_dir() / "workbench.sqlite3"
|
|
174
167
|
|
|
@@ -503,7 +496,9 @@ def expected_coverage_mode(scan: sqlite3.Row) -> str:
|
|
|
503
496
|
return "deep_repository" if scan["mode"] == "deep" else "repository"
|
|
504
497
|
|
|
505
498
|
|
|
506
|
-
def workbench_completion_binding(
|
|
499
|
+
def workbench_completion_binding(
|
|
500
|
+
scan: sqlite3.Row, completed_at: str, manifest: dict[str, Any] | None = None
|
|
501
|
+
) -> dict[str, Any]:
|
|
507
502
|
contract = scan_contract(scan)
|
|
508
503
|
target_contract = contract["target"]
|
|
509
504
|
plugin_manifest = read_json_object(
|
|
@@ -532,7 +527,7 @@ def workbench_completion_binding(scan: sqlite3.Row, completed_at: str) -> dict[s
|
|
|
532
527
|
"excludePaths": contract["scope"]["requiredExcludePaths"],
|
|
533
528
|
}
|
|
534
529
|
|
|
535
|
-
|
|
530
|
+
binding: dict[str, Any] = {
|
|
536
531
|
"scanId": scan["id"],
|
|
537
532
|
"startedAt": scan["started_at"],
|
|
538
533
|
"completedAt": completed_at,
|
|
@@ -542,6 +537,7 @@ def workbench_completion_binding(scan: sqlite3.Row, completed_at: str) -> dict[s
|
|
|
542
537
|
"scope": scope,
|
|
543
538
|
"coverageMode": expected_coverage_mode(scan),
|
|
544
539
|
}
|
|
540
|
+
return scan_history.preserve_sealed_completion(binding, manifest)
|
|
545
541
|
|
|
546
542
|
|
|
547
543
|
def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None:
|
|
@@ -805,7 +801,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
805
801
|
|
|
806
802
|
|
|
807
803
|
def scan_target_root(scan_root: str | None, target: Path) -> Path:
|
|
808
|
-
root =
|
|
804
|
+
root = resolve_scan_root(scan_root)
|
|
809
805
|
target_root = (root / safe_segment(target.name)).resolve()
|
|
810
806
|
if target_root == target or target in target_root.parents:
|
|
811
807
|
raise SystemExit("The scan artifact directory must be outside the selected target.")
|
|
@@ -1484,8 +1480,8 @@ def complete_scan_locked(
|
|
|
1484
1480
|
add_warning()
|
|
1485
1481
|
scan_dir = require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
1486
1482
|
completion_timestamp = now()
|
|
1487
|
-
completion_binding = workbench_completion_binding(scan, completion_timestamp)
|
|
1488
1483
|
current_manifest_path = artifact_path(scan_dir, ARTIFACTS["manifest"], required=False)
|
|
1484
|
+
current_manifest = None
|
|
1489
1485
|
if current_manifest_path is not None:
|
|
1490
1486
|
current_manifest = read_json_object(current_manifest_path)
|
|
1491
1487
|
if (
|
|
@@ -1503,8 +1499,8 @@ def complete_scan_locked(
|
|
|
1503
1499
|
or current_manifest["scan"].get("artifacts") is not None
|
|
1504
1500
|
)
|
|
1505
1501
|
)
|
|
1502
|
+
completion_binding = workbench_completion_binding(scan, completion_timestamp, current_manifest)
|
|
1506
1503
|
if scan["recipe_json"] is not None:
|
|
1507
|
-
draft_artifacts: dict[str, Path] = {}
|
|
1508
1504
|
missing_drafts = []
|
|
1509
1505
|
for file_name in (
|
|
1510
1506
|
ARTIFACTS["manifest"],
|
|
@@ -1516,20 +1512,13 @@ def complete_scan_locked(
|
|
|
1516
1512
|
except FileNotFoundError:
|
|
1517
1513
|
missing_drafts.append(file_name)
|
|
1518
1514
|
continue
|
|
1519
|
-
|
|
1520
|
-
if draft_path is not None:
|
|
1521
|
-
draft_artifacts[file_name] = draft_path
|
|
1515
|
+
artifact_path(scan_dir, file_name, required=True)
|
|
1522
1516
|
if missing_drafts:
|
|
1523
1517
|
raise SystemExit(
|
|
1524
1518
|
"Scan agent did not create required draft artifacts: "
|
|
1525
1519
|
f"{', '.join(missing_drafts)}. Check that the scan agent can run shell "
|
|
1526
1520
|
"commands and write to the scan directory before retrying."
|
|
1527
1521
|
)
|
|
1528
|
-
manifest = read_json_object(draft_artifacts[ARTIFACTS["manifest"]])
|
|
1529
|
-
manifest_scan = manifest.get("scan")
|
|
1530
|
-
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
1531
|
-
completion_binding["startedAt"] = manifest_scan.get("startedAt")
|
|
1532
|
-
completion_binding["completedAt"] = manifest_scan.get("completedAt")
|
|
1533
1522
|
wrote = False
|
|
1534
1523
|
try:
|
|
1535
1524
|
prepared = _prepare_scan_finalization(
|
|
@@ -1558,7 +1547,11 @@ def complete_scan_locked(
|
|
|
1558
1547
|
wrote = True
|
|
1559
1548
|
manifest, findings, _ = _write_prepared_scan_finalization(prepared)
|
|
1560
1549
|
except ContractError as exc:
|
|
1561
|
-
if wrote or (
|
|
1550
|
+
if wrote or (
|
|
1551
|
+
scan["mode"] == "deep"
|
|
1552
|
+
and not already_sealed
|
|
1553
|
+
and not isinstance(exc, RecoverableContractError)
|
|
1554
|
+
):
|
|
1562
1555
|
args = argparse.Namespace(claim_token=claim_token, cost_json=cost_json)
|
|
1563
1556
|
args.message, args.scan_id = str(exc), scan_id
|
|
1564
1557
|
fail_scan_locked(connection, args)
|
|
@@ -1819,8 +1812,6 @@ def set_scan_cost_limit(connection: sqlite3.Connection, args: argparse.Namespace
|
|
|
1819
1812
|
|
|
1820
1813
|
|
|
1821
1814
|
def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
|
|
1822
|
-
if len(value.encode("utf-8")) > SCAN_RECIPE_MAX_BYTES:
|
|
1823
|
-
raise SystemExit("Scan launch recipe must be no larger than 256 KiB.")
|
|
1824
1815
|
try:
|
|
1825
1816
|
recipe = json.loads(value, parse_constant=reject_non_finite_json)
|
|
1826
1817
|
except (TypeError, UnicodeError, ValueError) as exc:
|
|
@@ -1869,17 +1860,6 @@ def parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:
|
|
|
1869
1860
|
return recipe
|
|
1870
1861
|
|
|
1871
1862
|
|
|
1872
|
-
def get_scan_recipe(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
|
|
1873
|
-
scan = require_scan(connection, args.scan_id)
|
|
1874
|
-
if scan["recipe_json"] is None:
|
|
1875
|
-
raise SystemExit("This scan does not have a saved launch recipe.")
|
|
1876
|
-
return {
|
|
1877
|
-
"parentScanId": scan["parent_scan_id"],
|
|
1878
|
-
"recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
|
|
1879
|
-
"scanId": scan["id"],
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
1863
|
_WORKBENCH_DB_CONTEXT: saved_results.WorkbenchDbContext
|
|
1884
1864
|
|
|
1885
1865
|
|
|
@@ -2506,7 +2486,7 @@ def require_reviewed_patch_applied(
|
|
|
2506
2486
|
checkout = checkout_root
|
|
2507
2487
|
copy_directory_excluding(target, checkout, excluded)
|
|
2508
2488
|
else:
|
|
2509
|
-
|
|
2489
|
+
copy_git_worktree_files(target, checkout_root, excluded)
|
|
2510
2490
|
arguments = ["apply", "--reverse", "--whitespace=nowarn"]
|
|
2511
2491
|
if unversioned:
|
|
2512
2492
|
arguments.append("--no-index")
|
|
@@ -2859,6 +2839,8 @@ def scan_result(
|
|
|
2859
2839
|
**scan_usage.stored_scan_cost_fields(scan["cost_json"]),
|
|
2860
2840
|
"contract": scan_contract(scan),
|
|
2861
2841
|
"continuationThreadId": scan["continuation_thread_id"],
|
|
2842
|
+
"threadIds": scan_usage._scan_root_thread_ids(connection, scan, None),
|
|
2843
|
+
"executionThreadIds": scan_usage._scan_execution_thread_ids(connection, scan),
|
|
2862
2844
|
"failureMessage": scan["failure_message"],
|
|
2863
2845
|
"findings": [
|
|
2864
2846
|
finding_result(connection, scan, row, related=relations.get(row["id"], []))
|
|
@@ -3376,10 +3358,6 @@ def read_json_object(path: Path) -> dict[str, Any]:
|
|
|
3376
3358
|
return payload
|
|
3377
3359
|
|
|
3378
3360
|
|
|
3379
|
-
def reject_non_finite_json(value: str) -> None:
|
|
3380
|
-
raise ValueError(f"non-finite JSON number {value!r} is not supported")
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
3361
|
_WORKBENCH_PUBLICATION_CONTEXT = publication.WorkbenchPublicationContext(
|
|
3384
3362
|
ARTIFACTS=ARTIFACTS,
|
|
3385
3363
|
artifact_path=artifact_path,
|
|
@@ -3446,6 +3424,9 @@ def main() -> None:
|
|
|
3446
3424
|
preserve_stopped_results=preserve_stopped_results_after_transition,
|
|
3447
3425
|
)
|
|
3448
3426
|
)
|
|
3427
|
+
if args.command == "resolve-scan-root":
|
|
3428
|
+
print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
|
|
3429
|
+
return
|
|
3449
3430
|
if args.command == "inspect-target":
|
|
3450
3431
|
result = inspect_target(args.target_path)
|
|
3451
3432
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
@@ -3454,6 +3435,9 @@ def main() -> None:
|
|
|
3454
3435
|
result = inspect_setup(args)
|
|
3455
3436
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
3456
3437
|
return
|
|
3438
|
+
if args.command in {"save-artifact", "read-artifact"}:
|
|
3439
|
+
print(json.dumps(saved_results.read_or_save_artifact(args)))
|
|
3440
|
+
return
|
|
3457
3441
|
if args.command == "read-severity-classification":
|
|
3458
3442
|
result = severity.read_classification(database_path(), args.scan_id)
|
|
3459
3443
|
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
@@ -3518,7 +3502,25 @@ def main() -> None:
|
|
|
3518
3502
|
elif args.command == "set-scan-cost-limit":
|
|
3519
3503
|
result = set_scan_cost_limit(connection, args)
|
|
3520
3504
|
elif args.command == "get-scan-recipe":
|
|
3521
|
-
result =
|
|
3505
|
+
result = scan_history.scan_recipe(require_scan(connection, args.scan_id))
|
|
3506
|
+
elif args.command == "get-cli-scan-resume":
|
|
3507
|
+
scan = require_scan(connection, args.scan_id)
|
|
3508
|
+
try:
|
|
3509
|
+
result = scan_history.cli_scan_resume(
|
|
3510
|
+
connection,
|
|
3511
|
+
scan,
|
|
3512
|
+
require_workspace(connection, scan["workspace_id"]),
|
|
3513
|
+
parse_scan_recipe=parse_scan_recipe,
|
|
3514
|
+
scan_contract=scan_contract,
|
|
3515
|
+
require_scan_directory=require_canonical_scan_directory,
|
|
3516
|
+
artifact_path=artifact_path,
|
|
3517
|
+
read_json_object=read_json_object,
|
|
3518
|
+
workbench_completion_binding=workbench_completion_binding,
|
|
3519
|
+
)
|
|
3520
|
+
except SystemExit as exc:
|
|
3521
|
+
if not args.allow_unavailable:
|
|
3522
|
+
raise
|
|
3523
|
+
result = {"unavailable": str(exc)}
|
|
3522
3524
|
elif args.command == "compare-scans":
|
|
3523
3525
|
result = scan_history.compare_scans(
|
|
3524
3526
|
connection,
|
|
@@ -3563,6 +3565,8 @@ def main() -> None:
|
|
|
3563
3565
|
result = recover_scan_results(connection, args)
|
|
3564
3566
|
elif args.command == "write-scan-draft":
|
|
3565
3567
|
result = write_scan_draft(connection, args)
|
|
3568
|
+
elif args.command == "save-scan-artifact":
|
|
3569
|
+
result = saved_results.save_scan_artifact(_WORKBENCH_DB_CONTEXT, connection, args)
|
|
3566
3570
|
elif args.command == "mark-handoff-delivered":
|
|
3567
3571
|
result = handoff.mark_handoff_delivered(
|
|
3568
3572
|
connection,
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
|
+
import base64
|
|
6
7
|
import copy
|
|
7
8
|
import hashlib
|
|
8
9
|
import json
|
|
9
10
|
import os
|
|
10
11
|
import re
|
|
12
|
+
import sqlite3
|
|
11
13
|
import stat
|
|
12
14
|
import sys
|
|
13
15
|
from collections.abc import Callable, Iterator
|
|
@@ -34,6 +36,7 @@ from finalize_scan_contract import (
|
|
|
34
36
|
open_scan_local_file_descriptor,
|
|
35
37
|
write_scan_local_bytes,
|
|
36
38
|
)
|
|
39
|
+
from workbench_constants import PHASES
|
|
37
40
|
from workbench_validation import path_within_scope
|
|
38
41
|
|
|
39
42
|
_PUBLISHED_OUTPUTS = (
|
|
@@ -47,6 +50,9 @@ _PUBLISHED_OUTPUTS = (
|
|
|
47
50
|
_PUBLICATION_FOLLOW_UP_WARNING = (
|
|
48
51
|
"Saved scan evidence remains on disk; result publication needs follow-up:"
|
|
49
52
|
)
|
|
53
|
+
_RESERVED_ARTIFACT_PATHS = json.loads(
|
|
54
|
+
Path(__file__).with_name("reserved_artifact_paths.json").read_text(encoding="utf-8")
|
|
55
|
+
)
|
|
50
56
|
|
|
51
57
|
|
|
52
58
|
@dataclass(frozen=True)
|
|
@@ -1254,7 +1260,6 @@ def preserve_scan_results_locked(
|
|
|
1254
1260
|
for relative, digest in retained_sources.items()
|
|
1255
1261
|
):
|
|
1256
1262
|
raise ContractError("Stopped scan source digests could not be frozen.")
|
|
1257
|
-
frozen_source_digests = retained_sources
|
|
1258
1263
|
with connection:
|
|
1259
1264
|
connection.execute(
|
|
1260
1265
|
"UPDATE scans SET retained_source_digests_json = ? "
|
|
@@ -1334,6 +1339,49 @@ def preserve_scan_results(db: Any, connection: Any, args: Any) -> dict[str, Any]
|
|
|
1334
1339
|
return db.scan_context(connection, scan_id)
|
|
1335
1340
|
|
|
1336
1341
|
|
|
1342
|
+
def read_or_save_artifact(args: Any) -> dict[str, Any]:
|
|
1343
|
+
"""Read or publish supplemental bytes through verified filesystem handles."""
|
|
1344
|
+
root = Path(args.artifact_root)
|
|
1345
|
+
if args.command == "read-artifact":
|
|
1346
|
+
descriptor = open_scan_local_file_descriptor(root, args.artifact_path, "Saved artifact")
|
|
1347
|
+
with os.fdopen(descriptor, "rb") as source:
|
|
1348
|
+
return {"content": base64.b64encode(source.read()).decode("ascii")}
|
|
1349
|
+
write_scan_local_bytes(root, args.artifact_path, sys.stdin.buffer.read())
|
|
1350
|
+
return {"path": str(root / args.artifact_path)}
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
def save_scan_artifact(db: Any, connection: Any, args: Any) -> dict[str, Any]:
|
|
1354
|
+
"""Publish supplemental bytes under the same lock as finalization and recovery."""
|
|
1355
|
+
scan_id = db.require_uuid(args.scan_id, "scan-id")
|
|
1356
|
+
with db.scan_completion_lock(scan_id):
|
|
1357
|
+
scan = db.require_scan(connection, scan_id)
|
|
1358
|
+
db.handoff.require_current_continuation(
|
|
1359
|
+
scan,
|
|
1360
|
+
args.claim_token,
|
|
1361
|
+
error_message="Scan artifacts are owned by another continuation.",
|
|
1362
|
+
)
|
|
1363
|
+
if scan["status"] != "running" or scan["seal_manifest_digest"] is not None:
|
|
1364
|
+
raise SystemExit("The scan stopped; its artifacts cannot be modified.")
|
|
1365
|
+
scan_dir = db.require_canonical_scan_directory(Path(scan["scan_dir"]))
|
|
1366
|
+
manifest_path = db.artifact_path(scan_dir, "scan-manifest.json", required=False)
|
|
1367
|
+
if manifest_path is not None:
|
|
1368
|
+
manifest = db.read_json_object(manifest_path).get("scan", {})
|
|
1369
|
+
if manifest.get("sealedAt") is not None or manifest.get("artifacts") is not None:
|
|
1370
|
+
raise SystemExit("The scan is sealed; its artifacts cannot be modified.")
|
|
1371
|
+
output = args.artifact_path
|
|
1372
|
+
key = output.lower()
|
|
1373
|
+
if not (
|
|
1374
|
+
key.startswith(("artifacts/", "findings/", "hardening/"))
|
|
1375
|
+
or key == "report_validation.md"
|
|
1376
|
+
) or any(
|
|
1377
|
+
key == reserved or key.startswith(reserved + "/")
|
|
1378
|
+
for reserved in _RESERVED_ARTIFACT_PATHS
|
|
1379
|
+
):
|
|
1380
|
+
raise SystemExit("Use the typed scan tools for canonical artifacts and checkpoints.")
|
|
1381
|
+
write_scan_local_bytes(scan_dir, output, sys.stdin.buffer.read())
|
|
1382
|
+
return {"scanId": scan_id, "path": str(scan_dir / output)}
|
|
1383
|
+
|
|
1384
|
+
|
|
1337
1385
|
def write_scan_draft(db: Any, connection: Any, args: Any) -> dict[str, Any]:
|
|
1338
1386
|
scan_id = db.require_uuid(args.scan_id, "scan-id")
|
|
1339
1387
|
with db.scan_completion_lock(scan_id):
|
|
@@ -1405,6 +1453,29 @@ def write_scan_draft(db: Any, connection: Any, args: Any) -> dict[str, Any]:
|
|
|
1405
1453
|
filename,
|
|
1406
1454
|
(json.dumps(document, allow_nan=False, indent=2) + "\n").encode(),
|
|
1407
1455
|
)
|
|
1456
|
+
# Accepted Standard drafts are evidence of review or report assembly,
|
|
1457
|
+
# even when the parent omitted its explicit progress call.
|
|
1458
|
+
if scan["mode"] == "standard":
|
|
1459
|
+
phase = "discovery" if manifest["scan"].get("complete") is False else "reporting"
|
|
1460
|
+
earlier = PHASES[: PHASES.index(phase)]
|
|
1461
|
+
placeholders = ",".join("?" for _ in earlier)
|
|
1462
|
+
timestamp = db.now()
|
|
1463
|
+
try:
|
|
1464
|
+
with connection:
|
|
1465
|
+
changed = connection.execute(
|
|
1466
|
+
"UPDATE scans SET phase = ?, updated_at = ? "
|
|
1467
|
+
f"WHERE id = ? AND status = 'running' AND phase IN ({placeholders})",
|
|
1468
|
+
(phase, timestamp, scan_id, *earlier),
|
|
1469
|
+
)
|
|
1470
|
+
if changed.rowcount:
|
|
1471
|
+
connection.execute(
|
|
1472
|
+
"UPDATE scan_progress SET phase_items_total = 0, "
|
|
1473
|
+
"phase_items_completed = 0, phase_progress_unit = NULL, updated_at = ? "
|
|
1474
|
+
"WHERE scan_id = ?",
|
|
1475
|
+
(timestamp, scan_id),
|
|
1476
|
+
)
|
|
1477
|
+
except sqlite3.Error as exc:
|
|
1478
|
+
print(f"Could not save scan progress: {exc}", file=sys.stderr)
|
|
1408
1479
|
return {"scanId": scan_id, "status": "draft_written"}
|
|
1409
1480
|
|
|
1410
1481
|
|
|
@@ -14,10 +14,125 @@ from urllib.parse import urlsplit
|
|
|
14
14
|
|
|
15
15
|
# Some plugin hosts launch Python with safe-path isolation enabled.
|
|
16
16
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
|
+
from finalize_scan_contract import ContractError, _prepare_scan_finalization
|
|
17
18
|
from report_projection import SEVERITY_ORDER
|
|
18
|
-
from workbench_constants import FINDINGS_PAGE_MAX
|
|
19
|
+
from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX
|
|
20
|
+
from workbench_scan_start import scan_target_identity
|
|
19
21
|
from workbench_scan_usage import stored_scan_cost_fields
|
|
20
|
-
from workbench_target import git_output
|
|
22
|
+
from workbench_target import git_output, require_scan_target_identity
|
|
23
|
+
from workbench_validation import reject_non_finite_json
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
|
|
27
|
+
if scan["recipe_json"] is None:
|
|
28
|
+
raise SystemExit("This scan does not have a saved launch recipe.")
|
|
29
|
+
return {
|
|
30
|
+
"parentScanId": scan["parent_scan_id"],
|
|
31
|
+
"recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
|
|
32
|
+
"scanId": scan["id"],
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def preserve_sealed_completion(
|
|
37
|
+
binding: dict[str, Any], manifest: dict[str, Any] | None
|
|
38
|
+
) -> dict[str, Any]:
|
|
39
|
+
manifest_scan = manifest.get("scan") if manifest is not None else None
|
|
40
|
+
if isinstance(manifest_scan, dict) and manifest_scan.get("sealedAt") is not None:
|
|
41
|
+
# Keep the original producer; finalization still validates schema, seal and owner.
|
|
42
|
+
binding["startedAt"] = manifest_scan.get("startedAt")
|
|
43
|
+
binding["completedAt"] = manifest_scan.get("completedAt")
|
|
44
|
+
producer = manifest_scan.get("producer")
|
|
45
|
+
if isinstance(producer, dict):
|
|
46
|
+
binding["producer"]["version"] = producer.get("version")
|
|
47
|
+
return binding
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def cli_scan_resume(
|
|
51
|
+
connection: sqlite3.Connection,
|
|
52
|
+
scan: sqlite3.Row,
|
|
53
|
+
workspace: sqlite3.Row,
|
|
54
|
+
*,
|
|
55
|
+
parse_scan_recipe: Callable[[str, Path], dict[str, Any]],
|
|
56
|
+
scan_contract: Callable[[sqlite3.Row], dict[str, Any]],
|
|
57
|
+
require_scan_directory: Callable[[Path], Path],
|
|
58
|
+
artifact_path: Callable[..., Path | None],
|
|
59
|
+
read_json_object: Callable[[Path], dict[str, Any]],
|
|
60
|
+
workbench_completion_binding: Callable[..., dict[str, Any]],
|
|
61
|
+
) -> dict[str, Any]:
|
|
62
|
+
if scan["mode"] != "deep" or scan["recipe_json"] is None:
|
|
63
|
+
raise SystemExit("Resume requires a Deep Scan with a saved CLI launch recipe.")
|
|
64
|
+
if scan["status"] != "running" or scan["canceled_at"] is not None:
|
|
65
|
+
raise SystemExit(
|
|
66
|
+
"Resume requires a running scan; completed, failed, and canceled scans cannot resume."
|
|
67
|
+
)
|
|
68
|
+
thread_id = scan["continuation_thread_id"]
|
|
69
|
+
owner = scan["deep_scan_owner_thread_id"] or workspace["thread_id"]
|
|
70
|
+
if (
|
|
71
|
+
not thread_id
|
|
72
|
+
or (owner is not None and owner != thread_id)
|
|
73
|
+
or scan["handoff_status"] != "delivered"
|
|
74
|
+
or scan["handoff_claim_token"] is not None
|
|
75
|
+
):
|
|
76
|
+
raise SystemExit("Resume requires the original owning CLI session.")
|
|
77
|
+
run = connection.execute(
|
|
78
|
+
"SELECT status, cancel_requested FROM deep_scan_runs WHERE scan_id = ?", (scan["id"],)
|
|
79
|
+
).fetchone()
|
|
80
|
+
if run is not None and (
|
|
81
|
+
run["status"] not in {"running", "succeeded"} or run["cancel_requested"]
|
|
82
|
+
):
|
|
83
|
+
raise SystemExit("This Deep Scan has stopped and cannot resume.")
|
|
84
|
+
try:
|
|
85
|
+
repository = require_scan_target_identity(scan)
|
|
86
|
+
except SystemExit as exc:
|
|
87
|
+
raise SystemExit(
|
|
88
|
+
"Cannot resume: the original checkout is missing or was replaced."
|
|
89
|
+
) from exc
|
|
90
|
+
if scan_target_identity(repository, None) != (
|
|
91
|
+
scan["target_revision"],
|
|
92
|
+
scan["target_snapshot_digest"],
|
|
93
|
+
scan["target_device"],
|
|
94
|
+
scan["target_inode"],
|
|
95
|
+
):
|
|
96
|
+
raise SystemExit("Cannot resume: the original checkout revision or contents changed.")
|
|
97
|
+
recipe = parse_scan_recipe(scan["recipe_json"], repository)
|
|
98
|
+
scan_dir = require_scan_directory(Path(scan["scan_dir"]))
|
|
99
|
+
progress = connection.execute(
|
|
100
|
+
"SELECT scope_file_count FROM scan_progress WHERE scan_id = ?", (scan["id"],)
|
|
101
|
+
).fetchone()
|
|
102
|
+
result = {
|
|
103
|
+
"contract": scan_contract(scan),
|
|
104
|
+
"recipe": recipe,
|
|
105
|
+
"scanDir": str(scan_dir),
|
|
106
|
+
"scanId": scan["id"],
|
|
107
|
+
"scopeFileCount": progress["scope_file_count"],
|
|
108
|
+
"startedAt": scan["started_at"],
|
|
109
|
+
"targetId": scan["target_id"],
|
|
110
|
+
"targetRevision": scan["target_revision"],
|
|
111
|
+
"threadId": thread_id,
|
|
112
|
+
"userContext": scan["user_context"],
|
|
113
|
+
}
|
|
114
|
+
# Active coordinators may still be writing drafts. Validate sealed results
|
|
115
|
+
# before attaching to a coordinator that has finished.
|
|
116
|
+
if run is not None and run["status"] == "succeeded":
|
|
117
|
+
manifest_path = artifact_path(scan_dir, ARTIFACTS["manifest"], required=False)
|
|
118
|
+
if manifest_path is not None:
|
|
119
|
+
manifest = read_json_object(manifest_path)
|
|
120
|
+
manifest_scan = manifest.get("scan")
|
|
121
|
+
if isinstance(manifest_scan, dict) and (
|
|
122
|
+
manifest_scan.get("sealedAt") is not None
|
|
123
|
+
or manifest_scan.get("artifacts") is not None
|
|
124
|
+
):
|
|
125
|
+
try:
|
|
126
|
+
binding = workbench_completion_binding(scan, scan["started_at"], manifest)
|
|
127
|
+
_prepare_scan_finalization(
|
|
128
|
+
scan_dir,
|
|
129
|
+
expected_coverage_mode=binding["coverageMode"],
|
|
130
|
+
completion_binding=binding,
|
|
131
|
+
)
|
|
132
|
+
result["sealedProducerVersion"] = manifest_scan["producer"]["version"]
|
|
133
|
+
except ContractError as exc:
|
|
134
|
+
raise SystemExit(f"Cannot resume sealed scan: {exc}") from exc
|
|
135
|
+
return result
|
|
21
136
|
|
|
22
137
|
|
|
23
138
|
def _windows_path_key(value: str) -> str:
|