@openai/codex-security 0.1.16 → 0.1.17
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 +184 -4
- package/_bundled_plugin/.app.json +1 -1
- package/_bundled_plugin/.mcp.json +9 -3
- 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/config-preflight.md +1 -1
- package/_bundled_plugin/references/sarif-adapter.md +2 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +34 -6
- package/_bundled_plugin/scripts/finalize_scan_contract.py +54 -26
- package/_bundled_plugin/scripts/generate_in_scope_files.py +20 -0
- package/_bundled_plugin/scripts/generate_rank_input.py +23 -7
- package/_bundled_plugin/scripts/launch_codex_security_mcp +32 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +27 -0
- package/_bundled_plugin/scripts/workbench_cli.py +22 -15
- package/_bundled_plugin/scripts/workbench_db.py +35 -35
- package/_bundled_plugin/scripts/workbench_progress.py +6 -3
- package/_bundled_plugin/scripts/workbench_scan_history.py +17 -2
- package/_bundled_plugin/scripts/workbench_target.py +36 -5
- package/_bundled_plugin/scripts/workbench_validation.py +9 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +17 -1
- package/dist/api.d.ts +16 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +180 -11
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +5 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +335 -43
- package/dist/cli.js.map +1 -1
- package/dist/component-plan.d.ts +15 -0
- package/dist/component-plan.d.ts.map +1 -0
- package/dist/component-plan.js +145 -0
- package/dist/component-plan.js.map +1 -0
- package/dist/component-scan.d.ts +83 -0
- package/dist/component-scan.d.ts.map +1 -0
- package/dist/component-scan.js +279 -0
- package/dist/component-scan.js.map +1 -0
- package/dist/contract.d.ts +8 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +27 -8
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +20 -0
- package/dist/cost-model.d.ts.map +1 -0
- package/dist/cost-model.js +86 -0
- package/dist/cost-model.js.map +1 -0
- package/dist/cost.d.ts +2 -11
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -98
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +4 -0
- package/dist/custom-validation-prompt.d.ts.map +1 -0
- package/dist/custom-validation-prompt.js +94 -0
- package/dist/custom-validation-prompt.js.map +1 -0
- package/dist/custom-validation.d.ts +45 -0
- package/dist/custom-validation.d.ts.map +1 -0
- package/dist/custom-validation.js +292 -0
- package/dist/custom-validation.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +53 -5
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.js +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +3 -4
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +109 -38
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +12 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +72 -28
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +9 -2
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +198 -3
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -21
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -0
- package/dist/scan-sessions.js +35 -0
- package/dist/scan-sessions.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +16 -1
- package/dist/targets.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -20
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts +3 -0
- package/dist/windows-path.d.ts.map +1 -0
- package/dist/windows-path.js +16 -0
- package/dist/windows-path.js.map +1 -0
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +12 -0
- package/dist/worker-progress.js.map +1 -1
- package/package.json +8 -2
|
@@ -293,6 +293,21 @@ def path_is_excluded(path: Path) -> bool:
|
|
|
293
293
|
return path.name.endswith((".min.js", ".map"))
|
|
294
294
|
|
|
295
295
|
|
|
296
|
+
def windows_stream_component(path: Path) -> str | None:
|
|
297
|
+
"""Return the first NTFS alternate-data-stream component."""
|
|
298
|
+
|
|
299
|
+
if os.name != "nt":
|
|
300
|
+
return None
|
|
301
|
+
return next(
|
|
302
|
+
(
|
|
303
|
+
component
|
|
304
|
+
for component in path.parts
|
|
305
|
+
if component != path.anchor and ":" in component
|
|
306
|
+
),
|
|
307
|
+
None,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
296
311
|
def resolve_scope(
|
|
297
312
|
repo: Path,
|
|
298
313
|
scope: str,
|
|
@@ -301,6 +316,9 @@ def resolve_scope(
|
|
|
301
316
|
reject_symlinks: bool = False,
|
|
302
317
|
) -> Path:
|
|
303
318
|
scope_path = Path(scope).expanduser() if expand_user else Path(scope)
|
|
319
|
+
stream = windows_stream_component(scope_path)
|
|
320
|
+
if stream is not None:
|
|
321
|
+
raise SystemExit(f"Scope must not use an NTFS alternate data stream: {stream}")
|
|
304
322
|
if not scope_path.is_absolute():
|
|
305
323
|
scope_path = repo / scope_path
|
|
306
324
|
if reject_symlinks:
|
|
@@ -621,20 +639,19 @@ def run_git_changed_paths(repo: Path, diff_args: list[str]) -> list[tuple[Path,
|
|
|
621
639
|
],
|
|
622
640
|
check=True,
|
|
623
641
|
capture_output=True,
|
|
624
|
-
text=True,
|
|
625
642
|
)
|
|
626
|
-
fields = result.stdout.split("\0")
|
|
643
|
+
fields = result.stdout.split(b"\0")
|
|
627
644
|
if fields and not fields[-1]:
|
|
628
645
|
fields.pop()
|
|
629
646
|
|
|
630
647
|
changed: list[tuple[Path, str]] = []
|
|
631
648
|
index = 0
|
|
632
649
|
while index < len(fields):
|
|
633
|
-
status = fields[index][0]
|
|
650
|
+
status = chr(fields[index][0])
|
|
634
651
|
index += 1
|
|
635
652
|
if status in {"C", "R"}:
|
|
636
653
|
index += 1
|
|
637
|
-
path = repo / fields[index]
|
|
654
|
+
path = repo / os.fsdecode(fields[index])
|
|
638
655
|
index += 1
|
|
639
656
|
changed.append((path, status))
|
|
640
657
|
return changed
|
|
@@ -649,14 +666,13 @@ def git_changed_paths(repo: Path, base: str, head: str, mode: str) -> list[tuple
|
|
|
649
666
|
untracked = subprocess.run(
|
|
650
667
|
["git", "-C", str(repo), "ls-files", "--others", "--exclude-standard", "-z"],
|
|
651
668
|
capture_output=True,
|
|
652
|
-
text=True,
|
|
653
669
|
check=True,
|
|
654
670
|
)
|
|
655
671
|
combined = dict(staged)
|
|
656
672
|
combined.update(unstaged)
|
|
657
673
|
combined.update(
|
|
658
|
-
(repo / relative, "A")
|
|
659
|
-
for relative in untracked.stdout.split("\0")
|
|
674
|
+
(repo / os.fsdecode(relative), "A")
|
|
675
|
+
for relative in untracked.stdout.split(b"\0")
|
|
660
676
|
if relative
|
|
661
677
|
)
|
|
662
678
|
return sorted(combined.items())
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
|
|
4
|
+
PATH="${PATH:-/usr/bin:/bin}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
5
|
+
export PATH
|
|
6
|
+
|
|
7
|
+
launcher_dir=$(CDPATH= cd "$(dirname "$0")" && pwd)
|
|
8
|
+
server_path=$launcher_dir/../mcp/server.mjs
|
|
9
|
+
cache_root=${XDG_CACHE_HOME:-${HOME:-}/.cache}
|
|
10
|
+
codex_resources=
|
|
11
|
+
case "${CODEX_CLI_PATH:-}" in
|
|
12
|
+
*/*) codex_resources=${CODEX_CLI_PATH%/*} ;;
|
|
13
|
+
esac
|
|
14
|
+
|
|
15
|
+
for candidate in \
|
|
16
|
+
"${CODEX_MCP_NODE_PATH:-}" \
|
|
17
|
+
"${CODEX_BROWSER_USE_NODE_PATH:-}" \
|
|
18
|
+
"${CODEX_ELECTRON_RESOURCES_PATH:-}/cua_node/bin/node" \
|
|
19
|
+
"$codex_resources/cua_node/bin/node" \
|
|
20
|
+
"$cache_root/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
|
|
21
|
+
do
|
|
22
|
+
if [ -n "$candidate" ] && [ -x "$candidate" ]; then
|
|
23
|
+
exec "$candidate" "$server_path" "$@"
|
|
24
|
+
fi
|
|
25
|
+
done
|
|
26
|
+
|
|
27
|
+
if command -v node >/dev/null 2>&1; then
|
|
28
|
+
exec node "$server_path" "$@"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
printf '%s\n' 'Codex Security could not find a Node runtime. Reinstall or update Codex, or set CODEX_MCP_NODE_PATH to an executable Node runtime.' >&2
|
|
32
|
+
exit 127
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
|
|
4
|
+
set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\server.mjs"
|
|
5
|
+
|
|
6
|
+
rem This process waits for Node and must not keep the installed plugin directory locked.
|
|
7
|
+
if "%~d0"=="" (cd /d "%SystemRoot%") else (cd /d "%~d0\")
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo Codex Security could not start: no safe Windows working directory. 1>&2
|
|
10
|
+
exit /b 1
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
rem WindowsApps can expose a Node path that exists but cannot be executed.
|
|
14
|
+
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" ("%%~fD\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
16
|
+
if defined XDG_CACHE_HOME if exist "%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" ("%XDG_CACHE_HOME%\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
17
|
+
if defined USERPROFILE if exist "%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" ("%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
18
|
+
if defined CODEX_MCP_NODE_PATH if exist "%CODEX_MCP_NODE_PATH%" ("%CODEX_MCP_NODE_PATH%" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
19
|
+
if defined CODEX_BROWSER_USE_NODE_PATH if exist "%CODEX_BROWSER_USE_NODE_PATH%" ("%CODEX_BROWSER_USE_NODE_PATH%" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
20
|
+
if defined CODEX_ELECTRON_RESOURCES_PATH if exist "%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" ("%CODEX_ELECTRON_RESOURCES_PATH%\cua_node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
21
|
+
if defined CODEX_CLI_PATH for %%I in ("%CODEX_CLI_PATH%") do if exist "%%~dpIcua_node\bin\node.exe" ("%%~dpIcua_node\bin\node.exe" "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
22
|
+
|
|
23
|
+
where node >nul 2>&1
|
|
24
|
+
if not errorlevel 1 (node "%CODEX_SECURITY_MCP_SCRIPT%" %* & exit)
|
|
25
|
+
|
|
26
|
+
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
|
+
exit /b 127
|
|
@@ -24,6 +24,12 @@ from workbench_constants import (
|
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
def add_user_context(parser: argparse.ArgumentParser, *, required: bool = False) -> None:
|
|
28
|
+
context = parser.add_mutually_exclusive_group(required=required)
|
|
29
|
+
context.add_argument("--user-context")
|
|
30
|
+
context.add_argument("--user-context-stdin", action="store_true")
|
|
31
|
+
|
|
32
|
+
|
|
27
33
|
def parse_args(description: str) -> argparse.Namespace:
|
|
28
34
|
parser = argparse.ArgumentParser(description=description)
|
|
29
35
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
@@ -34,7 +40,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
34
40
|
create_workspace.add_argument("--target-path")
|
|
35
41
|
create_workspace.add_argument("--target-title")
|
|
36
42
|
create_workspace.add_argument("--target-summary")
|
|
37
|
-
create_workspace
|
|
43
|
+
add_user_context(create_workspace)
|
|
38
44
|
create_workspace.add_argument("--scope")
|
|
39
45
|
create_workspace.add_argument("--mode", choices=MODES, default="standard")
|
|
40
46
|
create_workspace.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
@@ -64,7 +70,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
64
70
|
save_workspace.add_argument("--scope", required=True)
|
|
65
71
|
save_workspace.add_argument("--mode", choices=MODES, required=True)
|
|
66
72
|
save_workspace.add_argument("--target-summary")
|
|
67
|
-
save_workspace
|
|
73
|
+
add_user_context(save_workspace)
|
|
68
74
|
save_workspace.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
69
75
|
save_workspace.add_argument("--diff-base-revision")
|
|
70
76
|
save_workspace.add_argument("--diff-head-revision")
|
|
@@ -82,7 +88,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
82
88
|
start_prompt_only_scan.add_argument("--scope", required=True)
|
|
83
89
|
start_prompt_only_scan.add_argument("--mode", choices=("diff", "standard"), required=True)
|
|
84
90
|
start_prompt_only_scan.add_argument("--target-summary")
|
|
85
|
-
start_prompt_only_scan
|
|
91
|
+
add_user_context(start_prompt_only_scan)
|
|
86
92
|
start_prompt_only_scan.add_argument("--diff-target-kind", choices=DIFF_TARGET_KINDS)
|
|
87
93
|
start_prompt_only_scan.add_argument("--diff-base-revision")
|
|
88
94
|
start_prompt_only_scan.add_argument("--diff-head-revision")
|
|
@@ -96,7 +102,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
96
102
|
start_headless_standard_scan.add_argument("--target-path", required=True)
|
|
97
103
|
start_headless_standard_scan.add_argument("--scope", required=True)
|
|
98
104
|
start_headless_standard_scan.add_argument("--target-summary")
|
|
99
|
-
start_headless_standard_scan
|
|
105
|
+
add_user_context(start_headless_standard_scan)
|
|
100
106
|
start_headless_standard_scan.add_argument("--scan-root")
|
|
101
107
|
start_headless_standard_scan.add_argument("--model")
|
|
102
108
|
start_headless_standard_scan.add_argument("--reasoning-effort")
|
|
@@ -119,7 +125,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
119
125
|
|
|
120
126
|
update_scan_context = subparsers.add_parser("update-scan-context")
|
|
121
127
|
update_scan_context.add_argument("--scan-id", required=True)
|
|
122
|
-
update_scan_context
|
|
128
|
+
add_user_context(update_scan_context, required=True)
|
|
123
129
|
update_scan_context_owner = update_scan_context.add_mutually_exclusive_group(required=True)
|
|
124
130
|
update_scan_context_owner.add_argument("--workspace-id")
|
|
125
131
|
update_scan_context_owner.add_argument("--thread-id")
|
|
@@ -142,7 +148,10 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
142
148
|
register_cli_scan = subparsers.add_parser("register-cli-scan")
|
|
143
149
|
register_cli_scan.add_argument("--scan-dir", required=True)
|
|
144
150
|
register_cli_scan.add_argument("--repository", required=True)
|
|
145
|
-
register_cli_scan.
|
|
151
|
+
recipe = register_cli_scan.add_mutually_exclusive_group(required=True)
|
|
152
|
+
recipe.add_argument("--recipe-json")
|
|
153
|
+
recipe.add_argument("--recipe-json-stdin", action="store_true")
|
|
154
|
+
recipe.add_argument("--registration-json-stdin", action="store_true")
|
|
146
155
|
register_cli_scan.add_argument("--parent-scan-id")
|
|
147
156
|
register_cli_scan.add_argument("--archive-existing", action="store_true")
|
|
148
157
|
register_cli_scan.add_argument("--archived-scan-dir")
|
|
@@ -163,7 +172,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
163
172
|
save_scan_comparison = subparsers.add_parser("save-scan-comparison")
|
|
164
173
|
save_scan_comparison.add_argument("--before-scan-id", required=True)
|
|
165
174
|
save_scan_comparison.add_argument("--after-scan-id", required=True)
|
|
166
|
-
save_scan_comparison.
|
|
175
|
+
matches = save_scan_comparison.add_mutually_exclusive_group(required=True)
|
|
176
|
+
matches.add_argument("--matches-json")
|
|
177
|
+
matches.add_argument("--matches-json-stdin", action="store_true")
|
|
167
178
|
|
|
168
179
|
list_global_findings = subparsers.add_parser("list-global-findings")
|
|
169
180
|
list_global_findings.add_argument("--query")
|
|
@@ -193,7 +204,9 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
193
204
|
update_progress.add_argument("--phase-items-total", type=non_negative_int)
|
|
194
205
|
update_progress.add_argument("--phase-items-completed", type=non_negative_int)
|
|
195
206
|
update_progress.add_argument("--phase-progress-unit", choices=PHASE_PROGRESS_UNITS)
|
|
196
|
-
update_progress.
|
|
207
|
+
preflight_issues = update_progress.add_mutually_exclusive_group()
|
|
208
|
+
preflight_issues.add_argument("--preflight-issues-json")
|
|
209
|
+
preflight_issues.add_argument("--preflight-issues-json-stdin", action="store_true")
|
|
197
210
|
update_progress.add_argument("--review-items-total", type=non_negative_int)
|
|
198
211
|
update_progress.add_argument("--review-items-completed", type=non_negative_int)
|
|
199
212
|
update_progress.add_argument("--reportable-findings-count", type=non_negative_int)
|
|
@@ -309,13 +322,7 @@ def parse_args(description: str) -> argparse.Namespace:
|
|
|
309
322
|
publication.add_argument("--input-file", required=True)
|
|
310
323
|
|
|
311
324
|
subparsers.add_parser("database-info")
|
|
312
|
-
|
|
313
|
-
if "--user-context-stdin" in arguments:
|
|
314
|
-
if arguments.count("--user-context-stdin") != 1 or "--user-context" in arguments:
|
|
315
|
-
parser.error("pass exactly one user-context transport")
|
|
316
|
-
index = arguments.index("--user-context-stdin")
|
|
317
|
-
arguments[index : index + 1] = ["--user-context", sys.stdin.read()]
|
|
318
|
-
return parser.parse_args(arguments)
|
|
325
|
+
return parser.parse_args()
|
|
319
326
|
|
|
320
327
|
|
|
321
328
|
def non_negative_int(value: str) -> int:
|
|
@@ -104,12 +104,14 @@ from workbench_target import (
|
|
|
104
104
|
copy_git_worktree_files,
|
|
105
105
|
directory_content_digest,
|
|
106
106
|
directory_snapshot_regular_file_count,
|
|
107
|
+
git_bytes,
|
|
107
108
|
git_command,
|
|
108
109
|
git_output,
|
|
109
110
|
git_revision,
|
|
110
111
|
git_submodule_paths,
|
|
111
112
|
git_target_metadata,
|
|
112
113
|
git_worktree_context,
|
|
114
|
+
remediation_checkout_snapshot,
|
|
113
115
|
require_git_worktree_head,
|
|
114
116
|
require_remediation_target,
|
|
115
117
|
require_scan_target_identity,
|
|
@@ -127,7 +129,7 @@ from workbench_validation import (
|
|
|
127
129
|
require_occurrence,
|
|
128
130
|
require_uuid,
|
|
129
131
|
sqlite_busy,
|
|
130
|
-
|
|
132
|
+
user_context_argument,
|
|
131
133
|
)
|
|
132
134
|
|
|
133
135
|
FINDING_ARTIFACT_DIRECTORIES_LIMIT = 80
|
|
@@ -314,11 +316,11 @@ def require_diff_target(
|
|
|
314
316
|
}
|
|
315
317
|
if kind == "commit":
|
|
316
318
|
head = resolve_git_commit(target, head_revision or "", "Commit")
|
|
317
|
-
commit =
|
|
319
|
+
commit = git_bytes(target, "cat-file", "-p", head)
|
|
318
320
|
if commit is None:
|
|
319
321
|
raise SystemExit(f"Commit is not available in the local checkout: {head}")
|
|
320
322
|
parent_line = next(
|
|
321
|
-
(line for line in commit.splitlines() if line.startswith("parent ")),
|
|
323
|
+
(line for line in commit.splitlines() if line.startswith(b"parent ")),
|
|
322
324
|
None,
|
|
323
325
|
)
|
|
324
326
|
if parent_line is None:
|
|
@@ -326,7 +328,7 @@ def require_diff_target(
|
|
|
326
328
|
else:
|
|
327
329
|
parent = resolve_git_commit(
|
|
328
330
|
target,
|
|
329
|
-
parent_line.removeprefix("parent ").strip(),
|
|
331
|
+
parent_line.removeprefix(b"parent ").decode("ascii").strip(),
|
|
330
332
|
"Commit parent",
|
|
331
333
|
)
|
|
332
334
|
if base_revision and base_revision != parent:
|
|
@@ -602,17 +604,15 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
|
|
|
602
604
|
|
|
603
605
|
def require_scope(scope: str, mode: str, target: Path) -> str:
|
|
604
606
|
value = scope.strip() or "."
|
|
605
|
-
|
|
607
|
+
requested_scope = Path(value)
|
|
608
|
+
if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
|
|
606
609
|
raise SystemExit("Scan scope must use repository-relative POSIX paths.")
|
|
607
|
-
|
|
608
|
-
if ".." in parsed.parts:
|
|
610
|
+
if ".." in requested_scope.parts:
|
|
609
611
|
raise SystemExit("Scan scope must stay inside the scanned target.")
|
|
610
612
|
try:
|
|
611
613
|
resolved_scope = (
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
else (target / parsed.as_posix()).resolve()
|
|
615
|
-
)
|
|
614
|
+
requested_scope if requested_scope.is_absolute() else target / requested_scope
|
|
615
|
+
).resolve()
|
|
616
616
|
relative_scope = resolved_scope.relative_to(target)
|
|
617
617
|
except (RuntimeError, ValueError) as exc:
|
|
618
618
|
raise SystemExit("Scan scope must stay inside the scanned target.") from exc
|
|
@@ -716,7 +716,7 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
|
|
|
716
716
|
optional_text(args.target_summary, maximum=2400),
|
|
717
717
|
default_scope,
|
|
718
718
|
args.mode,
|
|
719
|
-
|
|
719
|
+
user_context_argument(args),
|
|
720
720
|
diff_target_kind,
|
|
721
721
|
diff_base_revision,
|
|
722
722
|
diff_head_revision,
|
|
@@ -775,7 +775,7 @@ def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) ->
|
|
|
775
775
|
target_summary,
|
|
776
776
|
scope,
|
|
777
777
|
args.mode,
|
|
778
|
-
|
|
778
|
+
user_context_argument(args),
|
|
779
779
|
diff_target["kind"] if diff_target else None,
|
|
780
780
|
diff_target["baseRevision"] if diff_target else None,
|
|
781
781
|
diff_target["headRevision"] if diff_target else None,
|
|
@@ -940,7 +940,7 @@ def _start_prompt_driven_scan(
|
|
|
940
940
|
target_path = str(target)
|
|
941
941
|
scope = inspected["scope"]
|
|
942
942
|
diff_target = inspected["diffTarget"]
|
|
943
|
-
user_context =
|
|
943
|
+
user_context = user_context_argument(args)
|
|
944
944
|
target_summary = optional_text(args.target_summary, maximum=2400)
|
|
945
945
|
if diff_target is not None and not target_summary:
|
|
946
946
|
target_summary = diff_target_summary(diff_target)
|
|
@@ -1606,7 +1606,14 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1606
1606
|
if next(scan_dir.iterdir(), None) is not None:
|
|
1607
1607
|
raise SystemExit("The scan artifact directory must be empty before the scan starts.")
|
|
1608
1608
|
|
|
1609
|
-
|
|
1609
|
+
user_context = None
|
|
1610
|
+
if args.registration_json_stdin:
|
|
1611
|
+
registration = json.load(sys.stdin)
|
|
1612
|
+
recipe_json = json.dumps(registration["recipe"], ensure_ascii=False, separators=(",", ":"))
|
|
1613
|
+
user_context = registration.get("userContext")
|
|
1614
|
+
else:
|
|
1615
|
+
recipe_json = sys.stdin.read() if args.recipe_json_stdin else args.recipe_json
|
|
1616
|
+
recipe = parse_scan_recipe(recipe_json, repository)
|
|
1610
1617
|
requested_target = recipe["target"]
|
|
1611
1618
|
paths = requested_target["paths"]
|
|
1612
1619
|
scope = paths[0] if len(paths) == 1 else "."
|
|
@@ -1691,10 +1698,11 @@ def register_cli_scan(connection: sqlite3.Connection, args: argparse.Namespace)
|
|
|
1691
1698
|
scan_dir=scan_dir,
|
|
1692
1699
|
)
|
|
1693
1700
|
connection.execute(
|
|
1694
|
-
"UPDATE scans SET recipe_json = ?, parent_scan_id = ? WHERE id = ?",
|
|
1701
|
+
"UPDATE scans SET recipe_json = ?, parent_scan_id = ?, user_context = ? WHERE id = ?",
|
|
1695
1702
|
(
|
|
1696
1703
|
json.dumps(recipe, allow_nan=False, separators=(",", ":"), sort_keys=True),
|
|
1697
1704
|
parent_scan_id,
|
|
1705
|
+
user_context,
|
|
1698
1706
|
scan_id,
|
|
1699
1707
|
),
|
|
1700
1708
|
)
|
|
@@ -2842,24 +2850,6 @@ def require_pending_remediation_action(current: sqlite3.Row, requested: str) ->
|
|
|
2842
2850
|
)
|
|
2843
2851
|
|
|
2844
2852
|
|
|
2845
|
-
def remediation_checkout_snapshot(
|
|
2846
|
-
scan: sqlite3.Row, *, expected_revision: str | None = None
|
|
2847
|
-
) -> tuple[str, str | None]:
|
|
2848
|
-
target = require_scan_target_identity(scan)
|
|
2849
|
-
revision = git_revision(target)
|
|
2850
|
-
required_revision = expected_revision or scan["target_revision"]
|
|
2851
|
-
if revision != required_revision:
|
|
2852
|
-
raise SystemExit(
|
|
2853
|
-
"Repository HEAD changed. Regenerate the remediation patch against the current checkout."
|
|
2854
|
-
)
|
|
2855
|
-
content_digest = (
|
|
2856
|
-
worktree_content_digest(target)
|
|
2857
|
-
if revision != "unversioned"
|
|
2858
|
-
else directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
|
|
2859
|
-
)
|
|
2860
|
-
return revision, content_digest
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
2853
|
def require_reviewed_patch_applied(
|
|
2864
2854
|
scan: sqlite3.Row, remediation: sqlite3.Row, patch_path: str
|
|
2865
2855
|
) -> str | None:
|
|
@@ -2906,7 +2896,7 @@ def require_reviewed_patch_applied(
|
|
|
2906
2896
|
applied = git_command(
|
|
2907
2897
|
checkout if unversioned else checkout_root,
|
|
2908
2898
|
*arguments,
|
|
2909
|
-
text=
|
|
2899
|
+
text=False,
|
|
2910
2900
|
git_dir=Path(git_dir) if git_dir is not None else None,
|
|
2911
2901
|
work_tree=checkout_root if git_dir is not None else None,
|
|
2912
2902
|
)
|
|
@@ -2924,6 +2914,14 @@ def require_reviewed_patch_applied(
|
|
|
2924
2914
|
work_tree=checkout_root,
|
|
2925
2915
|
)
|
|
2926
2916
|
)
|
|
2917
|
+
if reverted_digest != remediation["base_content_digest"] and unversioned:
|
|
2918
|
+
checkout = Path(temporary) / "checkout-lf"
|
|
2919
|
+
copy_directory_excluding(target, checkout, excluded)
|
|
2920
|
+
applied_without_conversion = git_command(
|
|
2921
|
+
checkout, "-c", "core.autocrlf=input", *arguments, text=True
|
|
2922
|
+
)
|
|
2923
|
+
if applied_without_conversion.returncode == 0:
|
|
2924
|
+
reverted_digest = directory_content_digest(checkout)
|
|
2927
2925
|
if reverted_digest != remediation["base_content_digest"]:
|
|
2928
2926
|
raise SystemExit(
|
|
2929
2927
|
"The selected checkout contains changes outside the reviewed patch. Remove them before recording the patch as applied."
|
|
@@ -3818,6 +3816,8 @@ def reject_non_finite_json(value: str) -> None:
|
|
|
3818
3816
|
|
|
3819
3817
|
|
|
3820
3818
|
def main() -> None:
|
|
3819
|
+
# Workbench callers send UTF-8 even when Windows uses a legacy code page.
|
|
3820
|
+
sys.stdin.reconfigure(encoding="utf-8")
|
|
3821
3821
|
args = parse_args(__doc__)
|
|
3822
3822
|
deep_scan.configure(
|
|
3823
3823
|
deep_scan.DeepScanDependencies(
|
|
@@ -11,7 +11,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
11
11
|
from deep_scan_workbench import require_current_coordinator
|
|
12
12
|
from workbench.handoff import require_current_continuation
|
|
13
13
|
from workbench_constants import PHASES
|
|
14
|
-
from workbench_validation import optional_text, require_uuid,
|
|
14
|
+
from workbench_validation import optional_text, require_uuid, user_context_argument
|
|
15
15
|
|
|
16
16
|
MAX_PREFLIGHT_ISSUES = 32
|
|
17
17
|
|
|
@@ -83,7 +83,7 @@ def update_context(
|
|
|
83
83
|
scan_context: Callable[[sqlite3.Connection, str], dict[str, Any]],
|
|
84
84
|
) -> dict[str, Any]:
|
|
85
85
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
86
|
-
context =
|
|
86
|
+
context = user_context_argument(args)
|
|
87
87
|
connection.execute("BEGIN IMMEDIATE")
|
|
88
88
|
try:
|
|
89
89
|
scan = require_scan(connection, scan_id)
|
|
@@ -164,7 +164,10 @@ def update_progress(
|
|
|
164
164
|
scan_id = require_uuid(args.scan_id, "scan-id")
|
|
165
165
|
model = optional_text(args.model, maximum=200)
|
|
166
166
|
reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
|
|
167
|
-
|
|
167
|
+
preflight_issues = (
|
|
168
|
+
sys.stdin.read() if args.preflight_issues_json_stdin else args.preflight_issues_json
|
|
169
|
+
)
|
|
170
|
+
serialized_preflight_issues = preflight_issues_json(preflight_issues)
|
|
168
171
|
connection.execute("BEGIN IMMEDIATE")
|
|
169
172
|
try:
|
|
170
173
|
timestamp = now()
|
|
@@ -18,6 +18,10 @@ from workbench_scan_usage import stored_scan_cost_fields
|
|
|
18
18
|
from workbench_target import git_output
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
def _windows_path_key(value: str) -> str:
|
|
22
|
+
return os.path.normcase(os.path.realpath(value))
|
|
23
|
+
|
|
24
|
+
|
|
21
25
|
def _same_repository(
|
|
22
26
|
before: sqlite3.Row,
|
|
23
27
|
after: sqlite3.Row,
|
|
@@ -78,6 +82,8 @@ def _repository_origin(target: Path) -> tuple[str, str] | None:
|
|
|
78
82
|
def list_scans(
|
|
79
83
|
connection: sqlite3.Connection, args: argparse.Namespace | None = None
|
|
80
84
|
) -> dict[str, Any]:
|
|
85
|
+
if os.name == "nt":
|
|
86
|
+
connection.create_function("codex_security_path_key", 1, _windows_path_key)
|
|
81
87
|
clauses: list[str] = []
|
|
82
88
|
values: list[Any] = []
|
|
83
89
|
if args is not None and args.repository:
|
|
@@ -110,7 +116,15 @@ def list_scans(
|
|
|
110
116
|
if args is not None and args.scan_root:
|
|
111
117
|
scan_root = str(Path(args.scan_root).expanduser().resolve())
|
|
112
118
|
prefix = scan_root.rstrip(os.sep) + os.sep
|
|
113
|
-
|
|
119
|
+
if os.name == "nt":
|
|
120
|
+
scan_root = _windows_path_key(scan_root)
|
|
121
|
+
prefix = scan_root.rstrip(os.sep) + os.sep
|
|
122
|
+
clauses.append(
|
|
123
|
+
"(codex_security_path_key(scans.scan_dir) = ? "
|
|
124
|
+
"OR substr(codex_security_path_key(scans.scan_dir), 1, ?) = ?)"
|
|
125
|
+
)
|
|
126
|
+
else:
|
|
127
|
+
clauses.append("(scans.scan_dir = ? OR substr(scans.scan_dir, 1, ?) = ?)")
|
|
114
128
|
values.extend((scan_root, len(prefix), prefix))
|
|
115
129
|
if args is not None and args.target_id:
|
|
116
130
|
clauses.append("scans.target_id = ?")
|
|
@@ -456,8 +470,9 @@ def save_scan_comparison(
|
|
|
456
470
|
read_coverage(after)
|
|
457
471
|
before_findings = _scan_findings(connection, before["id"])
|
|
458
472
|
after_findings = _scan_findings(connection, after["id"])
|
|
473
|
+
matches_json = sys.stdin.read() if args.matches_json_stdin else args.matches_json
|
|
459
474
|
try:
|
|
460
|
-
payload = json.loads(
|
|
475
|
+
payload = json.loads(matches_json)
|
|
461
476
|
except (TypeError, ValueError) as exc:
|
|
462
477
|
raise SystemExit("Scan comparison matches must be a valid JSON object.") from exc
|
|
463
478
|
if not isinstance(payload, dict) or set(payload) != {"matches", "uncertain"}:
|
|
@@ -25,8 +25,8 @@ def git_output(
|
|
|
25
25
|
git_dir: Path | None = None,
|
|
26
26
|
work_tree: Path | None = None,
|
|
27
27
|
) -> str | None:
|
|
28
|
-
completed = git_command(target, *args, text=
|
|
29
|
-
output = completed.stdout.strip()
|
|
28
|
+
completed = git_command(target, *args, text=False, git_dir=git_dir, work_tree=work_tree)
|
|
29
|
+
output = os.fsdecode(completed.stdout).strip()
|
|
30
30
|
return output if completed.returncode == 0 and output else None
|
|
31
31
|
|
|
32
32
|
|
|
@@ -135,7 +135,15 @@ def git_command(
|
|
|
135
135
|
environment.pop(name, None)
|
|
136
136
|
environment["GIT_LITERAL_PATHSPECS"] = "1"
|
|
137
137
|
# Repository-local config is untrusted; fsmonitor may name an executable hook.
|
|
138
|
-
command = [
|
|
138
|
+
command = [
|
|
139
|
+
"git",
|
|
140
|
+
"-c",
|
|
141
|
+
"core.fsmonitor=false",
|
|
142
|
+
"-c",
|
|
143
|
+
"i18n.logOutputEncoding=UTF-8",
|
|
144
|
+
"-C",
|
|
145
|
+
str(target),
|
|
146
|
+
]
|
|
139
147
|
if git_dir is not None and work_tree is not None:
|
|
140
148
|
command.extend(["--git-dir", str(git_dir), "--work-tree", str(work_tree)])
|
|
141
149
|
full_command = [*command, *args]
|
|
@@ -146,6 +154,8 @@ def git_command(
|
|
|
146
154
|
capture_output=True,
|
|
147
155
|
env=environment,
|
|
148
156
|
text=text,
|
|
157
|
+
encoding="utf-8" if text else None,
|
|
158
|
+
errors="surrogateescape" if text else None,
|
|
149
159
|
input=input_data,
|
|
150
160
|
)
|
|
151
161
|
except FileNotFoundError:
|
|
@@ -168,6 +178,24 @@ def worktree_content_digest(target: Path) -> str:
|
|
|
168
178
|
return worktree_content_digest_for_context(repository, pathspec)
|
|
169
179
|
|
|
170
180
|
|
|
181
|
+
def remediation_checkout_snapshot(
|
|
182
|
+
scan: sqlite3.Row, *, expected_revision: str | None = None
|
|
183
|
+
) -> tuple[str, str | None]:
|
|
184
|
+
target = require_scan_target_identity(scan)
|
|
185
|
+
revision = git_revision(target)
|
|
186
|
+
required_revision = expected_revision or scan["target_revision"]
|
|
187
|
+
if revision != required_revision:
|
|
188
|
+
raise SystemExit(
|
|
189
|
+
"Repository HEAD changed. Regenerate the remediation patch against the current checkout."
|
|
190
|
+
)
|
|
191
|
+
content_digest = (
|
|
192
|
+
worktree_content_digest(target)
|
|
193
|
+
if revision != "unversioned"
|
|
194
|
+
else directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
|
|
195
|
+
)
|
|
196
|
+
return revision, content_digest
|
|
197
|
+
|
|
198
|
+
|
|
171
199
|
def worktree_content_digest_for_context(
|
|
172
200
|
repository: Path,
|
|
173
201
|
pathspec: str,
|
|
@@ -513,7 +541,9 @@ def copy_git_worktree_files(source: Path, destination: Path, excluded: tuple[Pat
|
|
|
513
541
|
if nested_git_dir is None:
|
|
514
542
|
raise SystemExit(f"Could not inspect nested Git working tree: {relative}")
|
|
515
543
|
copy_git_worktree_files(source_path, destination_path, excluded)
|
|
516
|
-
(destination_path / ".git").write_text(
|
|
544
|
+
(destination_path / ".git").write_text(
|
|
545
|
+
f"gitdir: {nested_git_dir}\n", encoding="utf-8"
|
|
546
|
+
)
|
|
517
547
|
else:
|
|
518
548
|
raise SystemExit(f"Unsupported Git working-tree file type: {relative}")
|
|
519
549
|
copied_target = destination if pathspec == "." else destination / pathspec
|
|
@@ -548,9 +578,10 @@ def git_target_metadata(target: Path) -> dict[str, Any]:
|
|
|
548
578
|
branch = git_output(target, "symbolic-ref", "--quiet", "--short", "HEAD")
|
|
549
579
|
metadata.update({"branch": branch, "detachedHead": revision is not None and branch is None})
|
|
550
580
|
if revision is not None:
|
|
581
|
+
subject = git_bytes(target, "show", "-s", "--format=%s", "HEAD")
|
|
551
582
|
metadata.update(
|
|
552
583
|
{
|
|
553
|
-
"commitSubject":
|
|
584
|
+
"commitSubject": (subject or b"").decode("utf-8").strip() or None,
|
|
554
585
|
"revision": revision,
|
|
555
586
|
"shortRevision": revision[:7],
|
|
556
587
|
}
|
|
@@ -57,6 +57,15 @@ def user_text(value: str | None) -> str | None:
|
|
|
57
57
|
return optional_text(value)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
+
def user_context_argument(args: argparse.Namespace) -> str | None:
|
|
61
|
+
value = (
|
|
62
|
+
sys.stdin.read()
|
|
63
|
+
if getattr(args, "user_context_stdin", False)
|
|
64
|
+
else args.user_context
|
|
65
|
+
)
|
|
66
|
+
return user_text(value)
|
|
67
|
+
|
|
68
|
+
|
|
60
69
|
def reject_nonstandard_json_number(value: str) -> None:
|
|
61
70
|
raise ValueError(f"invalid JSON number {value}")
|
|
62
71
|
|
|
@@ -42,7 +42,15 @@ Use this guidance whenever reproducing the finding, running tests, or validating
|
|
|
42
42
|
- Do not stop a progressing command merely because it is slow. Inspect process state, logs, artifacts, or resource use first.
|
|
43
43
|
- If runtime validation remains unavailable, use the strongest targeted static or harness-based artifact that preserves the real integration boundary. Do not substitute a simplified harness that removes the behavior being protected. Record every unrun check as unknown.
|
|
44
44
|
|
|
45
|
-
##
|
|
45
|
+
## Pre-Patch Investigation
|
|
46
|
+
|
|
47
|
+
The parent agent owns the patch and independently traces the reported path. Before editing, launch one fresh read-only agent with `fork_turns: "none"` when delegation is available. If delegation is unavailable, perform the same perspective as a separate pass:
|
|
48
|
+
|
|
49
|
+
- **Security-boundary and compatibility investigator:** Independently trace the source-to-sink path and identify the shared enforcement boundary, affected entry points, alternate representations or lifecycle states, parser and validation-to-use transitions, concrete sibling paths, and source-backed bypass risks. Establish the legitimate workflows and public behavior that must remain, then inspect callers, implementations, optional modes, errors, side effects, repository conventions, existing helpers, and focused validation commands for integration constraints.
|
|
50
|
+
|
|
51
|
+
The investigation requires repository-relative evidence and a clear separation between facts, inferences, and unresolved questions. When it completes, reconcile its findings with the parent's investigation and choose the patch boundary.
|
|
52
|
+
|
|
53
|
+
## Implementation Workflow
|
|
46
54
|
|
|
47
55
|
1. Revalidate and scope the finding.
|
|
48
56
|
- Inspect repository instructions, affected code, direct callers, and only the context needed to prove the vulnerable path.
|
|
@@ -76,6 +84,14 @@ Use this guidance whenever reproducing the finding, running tests, or validating
|
|
|
76
84
|
- Treat a failed earlier gate as disqualifying. Revise only the candidate changes or return `blocked`; never compensate for failed security closure or behavior preservation with style, smaller scope, or additional reporting.
|
|
77
85
|
6. Report the outcome with exact commands, results, changed files, and remaining risk.
|
|
78
86
|
|
|
87
|
+
## Patch Candidate Review
|
|
88
|
+
|
|
89
|
+
After implementing and running focused checks, launch one fresh read-only agent with `fork_turns: "none"` when delegation is available. Give it only the finding, repository root, authorized scope, repository policy, and current candidate diff; do not provide the patch rationale, investigator report, or claims that tests passed. If delegation is unavailable, perform the same review perspective as a separate pass before final verification. In either case, use the following assignment:
|
|
90
|
+
|
|
91
|
+
- **Bypass and regression reviewer:** Reconstruct the invariant and look for a concrete surviving route through affected entry points, equivalent representations, parser boundaries, aliases, backend or platform variants, and validation-to-use gaps. Trace changed conditions and direct callers for concrete breakage of legitimate inputs, public contracts, errors, side effects, state transitions, optional modes, compatibility, resource behavior, and repository conventions.
|
|
92
|
+
|
|
93
|
+
The reviewer must not edit or delegate. Report only concrete, source-backed bypasses or regressions and explain how each can be verified. Treat reviewer findings as hypotheses: confirm them against the source or focused execution before revising the implementation. Address only confirmed issues within the finding and compatibility boundary; do not broaden into speculative concerns or redesign. Then rerun relevant verification and ensure no temporary or unrelated changes remain. Perform only one review cycle.
|
|
94
|
+
|
|
79
95
|
## Workbench Remediation Stages
|
|
80
96
|
|
|
81
97
|
When a Codex Security workbench request includes a scan ID, occurrence ID, remediation request ID, action token, and expected version, follow only the requested remediation stage. The stage boundary changes when code may be written, but it does not weaken the validation requirements above.
|