@openai/codex-security 0.4.0 → 0.5.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.
Files changed (180) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/references/core-scan.md +2 -0
  9. package/_bundled_plugin/references/final-report.md +5 -1
  10. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  11. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  12. package/_bundled_plugin/references/scan-prologue.md +2 -6
  13. package/_bundled_plugin/references/scan-runtime.md +15 -0
  14. package/_bundled_plugin/references/threat-model.md +2 -0
  15. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  16. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  17. package/_bundled_plugin/scripts/finalize_scan_contract.py +80 -43
  18. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  19. package/_bundled_plugin/scripts/generate_rank_input.py +1 -0
  20. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  21. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  22. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  23. package/_bundled_plugin/scripts/workbench_cli.py +0 -3
  24. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  25. package/_bundled_plugin/scripts/workbench_db.py +56 -33
  26. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  27. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  28. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  29. package/_bundled_plugin/scripts/workbench_scan_usage.py +190 -30
  30. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  31. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  32. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  33. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  34. package/_bundled_plugin/scripts/workbench_validation.py +37 -1
  35. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  36. package/_bundled_plugin/shared/workbench-migrations.json +5 -0
  37. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  38. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  39. package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
  40. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  41. package/dist/api.d.ts +3 -2
  42. package/dist/api.d.ts.map +1 -1
  43. package/dist/api.js +54 -36
  44. package/dist/api.js.map +1 -1
  45. package/dist/artifact-export.d.ts +2 -1
  46. package/dist/artifact-export.d.ts.map +1 -1
  47. package/dist/artifact-export.js +38 -23
  48. package/dist/artifact-export.js.map +1 -1
  49. package/dist/classify-severity-records.d.ts +76 -0
  50. package/dist/classify-severity-records.d.ts.map +1 -0
  51. package/dist/classify-severity-records.js +141 -0
  52. package/dist/classify-severity-records.js.map +1 -0
  53. package/dist/classify-severity.d.ts +1 -23
  54. package/dist/classify-severity.d.ts.map +1 -1
  55. package/dist/classify-severity.js +3 -24
  56. package/dist/classify-severity.js.map +1 -1
  57. package/dist/cli-help.d.ts.map +1 -1
  58. package/dist/cli-help.js +2 -0
  59. package/dist/cli-help.js.map +1 -1
  60. package/dist/cli.d.ts +4 -2
  61. package/dist/cli.d.ts.map +1 -1
  62. package/dist/cli.js +136 -147
  63. package/dist/cli.js.map +1 -1
  64. package/dist/cloud-publish.js +1 -1
  65. package/dist/cloud-publish.js.map +1 -1
  66. package/dist/codex-sdk-environment.js +1 -1
  67. package/dist/codex-sdk-environment.js.map +1 -1
  68. package/dist/config.d.ts +12 -0
  69. package/dist/config.d.ts.map +1 -1
  70. package/dist/config.js +10 -4
  71. package/dist/config.js.map +1 -1
  72. package/dist/contract.d.ts +5 -0
  73. package/dist/contract.d.ts.map +1 -1
  74. package/dist/contract.js +65 -17
  75. package/dist/contract.js.map +1 -1
  76. package/dist/cost-model.d.ts.map +1 -1
  77. package/dist/cost-model.js +7 -2
  78. package/dist/cost-model.js.map +1 -1
  79. package/dist/custom-validation-prompt.js +3 -3
  80. package/dist/custom-validation-prompt.js.map +1 -1
  81. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  82. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  83. package/dist/deduplication/deduplication-prompts.js +2 -2
  84. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  85. package/dist/deduplication/records.js +1 -1
  86. package/dist/deduplication/records.js.map +1 -1
  87. package/dist/deduplication/scan.d.ts.map +1 -1
  88. package/dist/deduplication/scan.js +10 -9
  89. package/dist/deduplication/scan.js.map +1 -1
  90. package/dist/deep-config.d.ts +4 -1
  91. package/dist/deep-config.d.ts.map +1 -1
  92. package/dist/deep-config.js +21 -1
  93. package/dist/deep-config.js.map +1 -1
  94. package/dist/findings-import.d.ts +1 -1
  95. package/dist/findings-import.d.ts.map +1 -1
  96. package/dist/findings-import.js +3 -3
  97. package/dist/findings-import.js.map +1 -1
  98. package/dist/git-remote.d.ts +10 -0
  99. package/dist/git-remote.d.ts.map +1 -0
  100. package/dist/git-remote.js +24 -0
  101. package/dist/git-remote.js.map +1 -0
  102. package/dist/github.d.ts.map +1 -1
  103. package/dist/github.js +5 -7
  104. package/dist/github.js.map +1 -1
  105. package/dist/host-protocol.js +1 -1
  106. package/dist/host-protocol.js.map +1 -1
  107. package/dist/host-records-protocol.d.ts +15 -0
  108. package/dist/host-records-protocol.d.ts.map +1 -0
  109. package/dist/host-records-protocol.js +15 -0
  110. package/dist/host-records-protocol.js.map +1 -0
  111. package/dist/hosted-scan.d.ts +1 -6
  112. package/dist/hosted-scan.d.ts.map +1 -1
  113. package/dist/hosted-scan.js +2 -2
  114. package/dist/hosted-scan.js.map +1 -1
  115. package/dist/index.d.ts +4 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +2 -0
  118. package/dist/index.js.map +1 -1
  119. package/dist/knowledge-base.d.ts.map +1 -1
  120. package/dist/knowledge-base.js +87 -7
  121. package/dist/knowledge-base.js.map +1 -1
  122. package/dist/multiscan.d.ts.map +1 -1
  123. package/dist/multiscan.js +62 -28
  124. package/dist/multiscan.js.map +1 -1
  125. package/dist/patch-publication.d.ts +26 -0
  126. package/dist/patch-publication.d.ts.map +1 -0
  127. package/dist/patch-publication.js +105 -0
  128. package/dist/patch-publication.js.map +1 -0
  129. package/dist/patch-tui.d.ts.map +1 -1
  130. package/dist/patch-tui.js +4 -1
  131. package/dist/patch-tui.js.map +1 -1
  132. package/dist/project-config-schema.d.ts +2 -0
  133. package/dist/project-config-schema.d.ts.map +1 -1
  134. package/dist/project-config-schema.js +1 -0
  135. package/dist/project-config-schema.js.map +1 -1
  136. package/dist/project-config.d.ts +1 -0
  137. package/dist/project-config.d.ts.map +1 -1
  138. package/dist/project-config.js +16 -6
  139. package/dist/project-config.js.map +1 -1
  140. package/dist/publication.d.ts.map +1 -1
  141. package/dist/publication.js +135 -19
  142. package/dist/publication.js.map +1 -1
  143. package/dist/publish.d.ts.map +1 -1
  144. package/dist/publish.js +39 -25
  145. package/dist/publish.js.map +1 -1
  146. package/dist/runtime.d.ts.map +1 -1
  147. package/dist/runtime.js +83 -22
  148. package/dist/runtime.js.map +1 -1
  149. package/dist/scan-settings.d.ts +1 -0
  150. package/dist/scan-settings.d.ts.map +1 -1
  151. package/dist/scan-settings.js +7 -1
  152. package/dist/scan-settings.js.map +1 -1
  153. package/dist/scan-time-budget.d.ts +9 -0
  154. package/dist/scan-time-budget.d.ts.map +1 -0
  155. package/dist/scan-time-budget.js +16 -0
  156. package/dist/scan-time-budget.js.map +1 -0
  157. package/dist/severity-review.d.ts +29 -0
  158. package/dist/severity-review.d.ts.map +1 -0
  159. package/dist/severity-review.js +47 -0
  160. package/dist/severity-review.js.map +1 -0
  161. package/dist/validation-records.d.ts +38 -0
  162. package/dist/validation-records.d.ts.map +1 -0
  163. package/dist/validation-records.js +76 -0
  164. package/dist/validation-records.js.map +1 -0
  165. package/dist/version.d.ts.map +1 -1
  166. package/dist/version.js +4 -2
  167. package/dist/version.js.map +1 -1
  168. package/dist/worker-progress.d.ts +2 -6
  169. package/dist/worker-progress.d.ts.map +1 -1
  170. package/dist/worker-progress.js +1 -43
  171. package/dist/worker-progress.js.map +1 -1
  172. package/docs/classify-severity-records.md +89 -0
  173. package/docs/cli.md +269 -33
  174. package/docs/validate-records.md +69 -0
  175. package/package.json +12 -10
  176. package/schemas/project-config.schema.json +7 -1
  177. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  178. package/_bundled_plugin/references/config-preflight.md +0 -93
  179. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  180. package/_bundled_plugin/scripts/config_preflight.py +0 -911
@@ -23,13 +23,13 @@ from __future__ import annotations
23
23
  import argparse
24
24
  import contextlib
25
25
  import ctypes
26
+ import ctypes.wintypes as wintypes
26
27
  import errno
27
28
  import importlib
28
29
  import ntpath
29
30
  import os
30
31
  import secrets
31
32
  from collections.abc import Iterator
32
- from ctypes import wintypes
33
33
  from pathlib import Path, PurePosixPath
34
34
  from typing import BinaryIO
35
35
 
@@ -71,7 +71,9 @@ _ERROR_ACCESS_DENIED = 5
71
71
  _ERROR_SHARING_VIOLATION = 32
72
72
  _ERROR_LOCK_VIOLATION = 33
73
73
  _ERROR_FILE_EXISTS = 80
74
+ _ERROR_INSUFFICIENT_BUFFER = 122
74
75
  _ERROR_ALREADY_EXISTS = 183
76
+ _DACL_SECURITY_INFORMATION = 0x00000004
75
77
  _MISSING_ERRORS = {_ERROR_FILE_NOT_FOUND, _ERROR_PATH_NOT_FOUND}
76
78
  _COLLISION_ERRORS = {_ERROR_FILE_EXISTS, _ERROR_ALREADY_EXISTS}
77
79
  _INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value
@@ -100,6 +102,14 @@ class _FileAttributeTagInfo(ctypes.Structure):
100
102
  ]
101
103
 
102
104
 
105
+ class _SecurityAttributes(ctypes.Structure):
106
+ _fields_ = [
107
+ ("nLength", wintypes.DWORD),
108
+ ("lpSecurityDescriptor", wintypes.LPVOID),
109
+ ("bInheritHandle", wintypes.BOOL),
110
+ ]
111
+
112
+
103
113
  class _FileDispositionInfo(ctypes.Structure):
104
114
  _fields_ = [("DeleteFile", wintypes.BOOLEAN)]
105
115
 
@@ -143,6 +153,17 @@ class _OwnedHandle:
143
153
 
144
154
  if os.name == "nt":
145
155
  _kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
156
+ _advapi32 = ctypes.WinDLL("advapi32", use_last_error=True)
157
+
158
+ _GetFileSecurityW = _advapi32.GetFileSecurityW
159
+ _GetFileSecurityW.argtypes = [
160
+ wintypes.LPCWSTR,
161
+ wintypes.DWORD,
162
+ wintypes.LPVOID,
163
+ wintypes.DWORD,
164
+ ctypes.POINTER(wintypes.DWORD),
165
+ ]
166
+ _GetFileSecurityW.restype = wintypes.BOOL
146
167
 
147
168
  _CreateFileW = _kernel32.CreateFileW
148
169
  _CreateFileW.argtypes = [
@@ -441,6 +462,27 @@ def _create_directory(path: Path) -> None:
441
462
  _raise_last_error("CreateDirectoryW", path)
442
463
 
443
464
 
465
+ def create_directory_with_same_dacl(path: Path, source: Path) -> None:
466
+ """Create an archive replacement with the original directory's DACL."""
467
+ _require_windows()
468
+ source_path = _extended_path(source)
469
+ size = wintypes.DWORD()
470
+ _GetFileSecurityW(source_path, _DACL_SECURITY_INFORMATION, None, 0, ctypes.byref(size))
471
+ if ctypes.get_last_error() != _ERROR_INSUFFICIENT_BUFFER:
472
+ _raise_last_error("GetFileSecurityW", source)
473
+ descriptor = ctypes.create_string_buffer(size.value)
474
+ if not _GetFileSecurityW(
475
+ source_path, _DACL_SECURITY_INFORMATION, descriptor, size.value, ctypes.byref(size)
476
+ ):
477
+ _raise_last_error("GetFileSecurityW", source)
478
+ attributes = _SecurityAttributes(
479
+ ctypes.sizeof(_SecurityAttributes), ctypes.cast(descriptor, wintypes.LPVOID), False
480
+ )
481
+ # Supply the descriptor at creation, without an inherited-access window.
482
+ if not _CreateDirectoryW(_extended_path(path), ctypes.byref(attributes)):
483
+ _raise_last_error("CreateDirectoryW", path)
484
+
485
+
444
486
  @contextlib.contextmanager
445
487
  def _locked_parent(
446
488
  scan_dir: Path,
@@ -189,9 +189,6 @@ def parse_args(description: str) -> argparse.Namespace:
189
189
  update_progress.add_argument("--phase-items-total", type=deep_scan.non_negative_int)
190
190
  update_progress.add_argument("--phase-items-completed", type=deep_scan.non_negative_int)
191
191
  update_progress.add_argument("--phase-progress-unit", choices=PHASE_PROGRESS_UNITS)
192
- preflight_issues = update_progress.add_mutually_exclusive_group()
193
- preflight_issues.add_argument("--preflight-issues-json")
194
- preflight_issues.add_argument("--preflight-issues-json-stdin", action="store_true")
195
192
  update_progress.add_argument("--review-items-total", type=deep_scan.non_negative_int)
196
193
  update_progress.add_argument("--review-items-completed", type=deep_scan.non_negative_int)
197
194
  update_progress.add_argument("--reportable-findings-count", type=deep_scan.non_negative_int)
@@ -57,6 +57,10 @@ GIT_REPOSITORY_ENVIRONMENT = (
57
57
  "GIT_WORK_TREE",
58
58
  )
59
59
  EMPTY_GIT_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
60
+ EMPTY_GIT_TREES = {
61
+ "sha1": EMPTY_GIT_TREE,
62
+ "sha256": "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321",
63
+ }
60
64
 
61
65
 
62
66
  def positive_int(value: str) -> int:
@@ -64,6 +64,7 @@ from workbench_constants import (
64
64
  DELIVERED_ACTION_LEASE_SECONDS,
65
65
  DIFF_TARGET_KINDS,
66
66
  EMPTY_GIT_TREE,
67
+ EMPTY_GIT_TREES,
67
68
  FINDING_ABSOLUTE_PATH_BYTES,
68
69
  FINDING_LEVEL_BYTES,
69
70
  FINDING_LOCATION_PATH_BYTES,
@@ -95,7 +96,14 @@ from workbench_schema import (
95
96
  from workbench_schema import (
96
97
  apply_migrations as apply_schema_migrations,
97
98
  )
98
- from workbench_source_excerpt import finding_source_excerpt, safe_source_path
99
+ from workbench_source_excerpt import finding_source_excerpt
100
+ from workbench_source_scopes import (
101
+ capture_source_scopes,
102
+ expected_target_kinds,
103
+ public_scan_recipe,
104
+ requested_scan_paths,
105
+ safe_source_path,
106
+ )
99
107
  from workbench_target import (
100
108
  clean_worktree_content_digest,
101
109
  copy_directory_excluding,
@@ -337,7 +345,7 @@ def require_diff_target(
337
345
  None,
338
346
  )
339
347
  if parent_line is None:
340
- parent = EMPTY_GIT_TREE
348
+ parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
341
349
  else:
342
350
  parent = resolve_git_commit(
343
351
  target,
@@ -420,27 +428,6 @@ def require_scannable_target(target: Path) -> None:
420
428
  )
421
429
 
422
430
 
423
- def expected_target_kinds(scan: sqlite3.Row) -> list[str]:
424
- if scan["mode"] == "diff":
425
- return ["git_diff"]
426
- if scan["target_revision"] == "unversioned":
427
- return ["directory_snapshot"]
428
- if scan["target_snapshot_digest"] is None:
429
- return ["git_worktree", "git_revision"]
430
- if scan["target_snapshot_digest"] == clean_worktree_content_digest():
431
- return ["git_revision"]
432
- return ["git_worktree"]
433
-
434
-
435
- def requested_scan_paths(scan: sqlite3.Row) -> list[str]:
436
- if "recipe_json" in scan.keys() and scan["recipe_json"] is not None:
437
- recipe = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
438
- target = recipe["target"]
439
- if target["kind"] == "paths":
440
- return target["paths"]
441
- return [scan["scope"]]
442
-
443
-
444
431
  def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
445
432
  # Older scans did not record path kinds. Retain their lexical scope semantics
446
433
  # rather than infer the original target from a possibly changed checkout.
@@ -866,6 +853,12 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
866
853
  diff_target,
867
854
  metadata=target_metadata,
868
855
  )
856
+ source_scopes = capture_source_scopes(
857
+ target,
858
+ target_identity,
859
+ [scope],
860
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
861
+ )
869
862
  target_root = scan_target_root(args.scan_root, target)
870
863
  create_private_directory(target_root)
871
864
  if manages_transaction:
@@ -914,6 +907,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
914
907
  scope=scope,
915
908
  diff_target=diff_target,
916
909
  target_identity=target_identity,
910
+ source_scopes=source_scopes,
917
911
  target_root=target_root,
918
912
  target_summary=target_summary,
919
913
  scope_file_count=scope_file_count,
@@ -958,6 +952,12 @@ def _start_prompt_driven_scan(
958
952
  )
959
953
  diff_identity = scan_diff_identity(diff_target)
960
954
  target_identity = scan_target_identity(target, diff_target)
955
+ source_scopes = capture_source_scopes(
956
+ target,
957
+ target_identity,
958
+ [scope],
959
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
960
+ )
961
961
  target_root = scan_target_root(args.scan_root, target)
962
962
 
963
963
  busy_timeout = int(connection.execute("PRAGMA busy_timeout").fetchone()[0])
@@ -1070,6 +1070,7 @@ def _start_prompt_driven_scan(
1070
1070
  scope=scope,
1071
1071
  diff_target=diff_target,
1072
1072
  target_identity=target_identity,
1073
+ source_scopes=source_scopes,
1073
1074
  target_root=target_root,
1074
1075
  target_summary=target_summary,
1075
1076
  scope_file_count=scope_file_count,
@@ -1638,13 +1639,15 @@ def complete_scan_locked(
1638
1639
  context["targetWarnings"] = target_warnings
1639
1640
  return context
1640
1641
 
1641
- if cost_json is None:
1642
- measured_usage = scan_usage.collect_scan_usage(
1642
+ cost_fields = scan_usage.stored_scan_cost_fields(cost_json)
1643
+ if "usage" not in cost_fields:
1644
+ cost_fields["usage"] = scan_usage.collect_scan_usage(
1643
1645
  connection,
1644
1646
  scan,
1645
1647
  thread_id=thread_id,
1646
1648
  completed_at=completion_timestamp,
1647
1649
  )
1650
+ measured_usage = cost_fields["usage"]
1648
1651
  if thread_id is not None and turn_id is not None:
1649
1652
  measured_usage["completion"] = {
1650
1653
  "threadId": thread_id,
@@ -1653,11 +1656,10 @@ def complete_scan_locked(
1653
1656
  }
1654
1657
  if measured_usage["coverage"] == "complete":
1655
1658
  measured_usage["coverage"] = "partial"
1656
- measured_usage["warnings"] = [
1657
- *measured_usage.get("warnings", []),
1658
- "turn_in_progress",
1659
- ]
1660
- cost_json = parse_scan_cost(scan_usage.measured_scan_cost_json(measured_usage))
1659
+ measured_usage["warnings"] = sorted(
1660
+ {*measured_usage.get("warnings", []), "turn_in_progress"}
1661
+ )
1662
+ cost_json = parse_scan_cost(json.dumps(cost_fields))
1661
1663
  connection.execute("BEGIN IMMEDIATE")
1662
1664
  with connection:
1663
1665
  timestamp = manifest["scan"]["completedAt"]
@@ -1753,6 +1755,7 @@ def register_cli_scan(
1753
1755
  recipe = parse_scan_recipe(recipe_json, repository)
1754
1756
  requested_target = recipe["target"]
1755
1757
  paths = requested_target["paths"]
1758
+ recipe.pop("_codexSecurityFileScopes", None)
1756
1759
  # Capture host-observed kinds once; resumes and publication use the saved recipe.
1757
1760
  recipe.pop("scopeFilePaths", None)
1758
1761
  if file_paths := [path for path in paths if (repository / path).is_file()]:
@@ -1774,6 +1777,12 @@ def register_cli_scan(
1774
1777
  diff_target["contentDigest"] = worktree_content_digest(repository)
1775
1778
  mode = "diff" if diff_target is not None else recipe["mode"]
1776
1779
  target_identity = scan_target_identity(repository, diff_target)
1780
+ source_scopes = capture_source_scopes(
1781
+ repository,
1782
+ target_identity,
1783
+ paths or ["."],
1784
+ diff_target_kind=diff_target["kind"] if diff_target is not None else None,
1785
+ )
1777
1786
  scope_file_count = (
1778
1787
  directory_snapshot_regular_file_count(repository)
1779
1788
  if not paths
@@ -1844,6 +1853,7 @@ def register_cli_scan(
1844
1853
  scope=scope,
1845
1854
  diff_target=diff_target,
1846
1855
  target_identity=target_identity,
1856
+ source_scopes=source_scopes,
1847
1857
  target_root=scan_dir.parent,
1848
1858
  target_summary=None,
1849
1859
  scope_file_count=scope_file_count,
@@ -2725,7 +2735,7 @@ def scan_context(
2725
2735
  }
2726
2736
  if scan["recipe_json"] is not None:
2727
2737
  context["parentScanId"] = scan["parent_scan_id"]
2728
- context["recipe"] = json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json)
2738
+ context["recipe"] = public_scan_recipe(scan)
2729
2739
  return context
2730
2740
 
2731
2741
 
@@ -3023,6 +3033,7 @@ def finding_result(
3023
3033
  severity = details.get("severity")
3024
3034
  severity = severity if isinstance(severity, dict) else {}
3025
3035
  locations = []
3036
+ excerpt_locations = []
3026
3037
  try:
3027
3038
  target = require_scan_target_identity(scan)
3028
3039
  except SystemExit:
@@ -3037,10 +3048,20 @@ def finding_result(
3037
3048
  """,
3038
3049
  (occurrence["id"], FINDING_LOCATIONS_LIMIT),
3039
3050
  ):
3051
+ display_path = bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES)
3052
+ if display_path == row["relative_path"]:
3053
+ excerpt_locations.append(
3054
+ {
3055
+ "endLine": row["end_line"],
3056
+ "path": row["relative_path"],
3057
+ "role": row["role"],
3058
+ "startLine": row["start_line"],
3059
+ }
3060
+ )
3040
3061
  absolute_path = safe_source_path(target, row["relative_path"]) if target else None
3041
3062
  location = {
3042
3063
  "endLine": row["end_line"],
3043
- "path": bounded_output_text(row["relative_path"], FINDING_LOCATION_PATH_BYTES),
3064
+ "path": display_path,
3044
3065
  "role": (
3045
3066
  bounded_output_text(row["role"], FINDING_LOCATION_ROLE_BYTES)
3046
3067
  if row["role"] is not None
@@ -3082,7 +3103,9 @@ def finding_result(
3082
3103
  result["knownScanIds"] = known_scan_ids
3083
3104
  if related:
3084
3105
  result["related"] = related
3085
- source_excerpt = finding_source_excerpt(scan, target, locations)
3106
+ source_excerpt = finding_source_excerpt(
3107
+ scan, target, excerpt_locations, requested_scan_paths(scan)
3108
+ )
3086
3109
  if source_excerpt:
3087
3110
  result["sourceExcerpt"] = source_excerpt
3088
3111
  artifact_paths = finding_artifact_paths(Path(scan["scan_dir"]), details)
@@ -1,7 +1,6 @@
1
1
  """Progress transition helpers for the Codex Security workbench."""
2
2
 
3
3
  import argparse
4
- import json
5
4
  import sqlite3
6
5
  import sys
7
6
  from pathlib import Path
@@ -13,45 +12,6 @@ from workbench.handoff import require_current_continuation
13
12
  from workbench_constants import PHASES
14
13
  from workbench_validation import optional_text, require_uuid, user_context_argument
15
14
 
16
- MAX_PREFLIGHT_ISSUES = 32
17
-
18
-
19
- def _preflight_issue_text(value: Any, maximum: int, label: str) -> str:
20
- if not isinstance(value, str):
21
- raise SystemExit(f"Preflight issue {label} must be text.")
22
- normalized = value.strip()
23
- # Match JavaScript's UTF-16 code-unit length.
24
- if not normalized or len(normalized.encode("utf-16-le", errors="surrogatepass")) // 2 > maximum:
25
- raise SystemExit(f"Preflight issue {label} must contain 1 to {maximum} characters.")
26
- return normalized
27
-
28
-
29
- def preflight_issues_json(value: str | None) -> str | None:
30
- if value is None:
31
- return None
32
- try:
33
- payload = json.loads(value)
34
- except json.JSONDecodeError as exc:
35
- raise SystemExit("Preflight issues must be valid JSON.") from exc
36
- if not isinstance(payload, list) or len(payload) > MAX_PREFLIGHT_ISSUES:
37
- raise SystemExit(
38
- f"Preflight issues must be an array of at most {MAX_PREFLIGHT_ISSUES} objects."
39
- )
40
- expected_keys = {"capability", "reason", "severity", "status"}
41
- for index, issue in enumerate(payload):
42
- label = f"{index + 1}"
43
- if not isinstance(issue, dict) or set(issue) != expected_keys:
44
- raise SystemExit(
45
- f"Preflight issue {label} must contain capability, reason, severity, and status."
46
- )
47
- severity = issue.get("severity")
48
- status = issue.get("status")
49
- if severity not in {"block", "warn"} or status not in {"fail", "unknown"}:
50
- raise SystemExit(f"Preflight issue {label} has an invalid severity or status.")
51
- for field, maximum in (("capability", 128), ("reason", 1200)):
52
- issue[field] = _preflight_issue_text(issue.get(field), maximum, f"{label} {field}")
53
- return json.dumps(payload, ensure_ascii=True, separators=(",", ":"), sort_keys=True)
54
-
55
15
 
56
16
  def reportable_count(
57
17
  current_phase: str, requested_phase: str | None, count: int | None
@@ -115,10 +75,6 @@ def update_progress(
115
75
  scan_id = require_uuid(args.scan_id, "scan-id")
116
76
  model = optional_text(args.model, maximum=200)
117
77
  reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
118
- preflight_issues = (
119
- sys.stdin.read() if args.preflight_issues_json_stdin else args.preflight_issues_json
120
- )
121
- serialized_preflight_issues = preflight_issues_json(preflight_issues)
122
78
  connection.execute("BEGIN IMMEDIATE")
123
79
  with connection:
124
80
  timestamp = wb.now()
@@ -142,11 +98,6 @@ def update_progress(
142
98
  )
143
99
  if args.deep_review_pass is not None and scan["mode"] != "deep":
144
100
  raise SystemExit("Only Deep Scan can record a deep review pass.")
145
- if serialized_preflight_issues is not None:
146
- if scan["mode"] == "deep":
147
- raise SystemExit("Deep Scan preflight progress is owned by its coordinator.")
148
- if scan["phase"] != "preflight" or args.phase not in {None, "preflight"}:
149
- raise SystemExit("Preflight issues can only be updated during preflight.")
150
101
  progress = connection.execute(
151
102
  "SELECT * FROM scan_progress WHERE scan_id = ?", (scan["id"],)
152
103
  ).fetchone()
@@ -194,7 +145,6 @@ def update_progress(
194
145
  updates.extend(["preflight_checks_total = ?", "preflight_checks_completed = ?"])
195
146
  values.extend([phase_total, phase_completed])
196
147
  for column, value in (
197
- ("preflight_issues_json", serialized_preflight_issues),
198
148
  ("review_items_total", args.review_items_total),
199
149
  ("review_items_completed", args.review_items_completed),
200
150
  (
@@ -19,8 +19,9 @@ from report_projection import SEVERITY_ORDER
19
19
  from workbench_constants import ARTIFACTS, FINDINGS_PAGE_MAX
20
20
  from workbench_scan_start import scan_target_identity
21
21
  from workbench_scan_usage import stored_scan_cost_fields
22
+ from workbench_source_scopes import public_scan_recipe
22
23
  from workbench_target import git_output, require_scan_target_identity
23
- from workbench_validation import reject_non_finite_json, timestamp_key
24
+ from workbench_validation import timestamp_key
24
25
 
25
26
 
26
27
  def rename_scan(connection: sqlite3.Connection, scan: sqlite3.Row, name: str) -> dict[str, Any]:
@@ -37,7 +38,7 @@ def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
37
38
  raise SystemExit("This scan does not have a saved launch recipe.")
38
39
  return {
39
40
  "parentScanId": scan["parent_scan_id"],
40
- "recipe": json.loads(scan["recipe_json"], parse_constant=reject_non_finite_json),
41
+ "recipe": public_scan_recipe(scan),
41
42
  "scanId": scan["id"],
42
43
  }
43
44
 
@@ -13,6 +13,7 @@ from collections.abc import Callable, Iterator
13
13
  from contextlib import contextmanager
14
14
  from datetime import datetime, timezone
15
15
  from pathlib import Path
16
+ from typing import Any
16
17
 
17
18
  # Some plugin hosts launch Python with safe-path isolation enabled.
18
19
  sys.path.insert(0, str(Path(__file__).resolve().parent))
@@ -160,8 +161,13 @@ def archive_scan(
160
161
  archived_scan_dir.rmdir()
161
162
  scan_dir.rename(archived_scan_dir)
162
163
  moved = True
163
- scan_dir.mkdir(mode=0o700)
164
- scan_dir.chmod(0o700)
164
+ if os.name == "nt":
165
+ from windows_scan_local_files import create_directory_with_same_dacl
166
+
167
+ create_directory_with_same_dacl(scan_dir, archived_scan_dir)
168
+ else:
169
+ scan_dir.mkdir(mode=0o700)
170
+ scan_dir.chmod(0o700)
165
171
  if previous_scan is not None:
166
172
  connection.execute(
167
173
  "UPDATE scans SET scan_dir = ?, updated_at = ? WHERE id = ?",
@@ -221,6 +227,7 @@ def insert_running_scan(
221
227
  scope: str,
222
228
  diff_target: dict[str, str] | None,
223
229
  target_identity: tuple[str, str | None, int | str, int | str],
230
+ source_scopes: dict[str, Any],
224
231
  target_root: Path,
225
232
  target_summary: str | None,
226
233
  scope_file_count: int,
@@ -244,11 +251,11 @@ def insert_running_scan(
244
251
  """
245
252
  INSERT INTO scans (
246
253
  id, workspace_id, target_id, target_path, target_revision, target_snapshot_digest,
247
- target_device, target_inode, scope, mode, user_context,
254
+ target_device, target_inode, source_scopes_json, scope, mode, user_context,
248
255
  deep_scan_owner_thread_id, diff_target_kind, diff_base_revision,
249
256
  diff_head_revision, diff_content_digest, target_summary, scan_dir, model,
250
257
  reasoning_effort, status, phase, handoff_status, started_at, created_at, updated_at
251
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
258
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
252
259
  'running', 'preflight', ?, ?, ?, ?)
253
260
  """,
254
261
  (
@@ -257,6 +264,7 @@ def insert_running_scan(
257
264
  workspace["target_id"],
258
265
  str(target),
259
266
  *target_identity,
267
+ json.dumps(source_scopes, allow_nan=False, separators=(",", ":"), sort_keys=True),
260
268
  scope,
261
269
  workspace["default_mode"],
262
270
  user_context,