@openai/codex-security 0.3.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 (244) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  7. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
  8. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  9. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  10. package/_bundled_plugin/references/core-scan.md +2 -0
  11. package/_bundled_plugin/references/final-report.md +5 -1
  12. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  13. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  14. package/_bundled_plugin/references/scan-prologue.md +2 -6
  15. package/_bundled_plugin/references/scan-runtime.md +15 -0
  16. package/_bundled_plugin/references/threat-model.md +2 -0
  17. package/_bundled_plugin/schemas/coverage.schema.json +45 -126
  18. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  19. package/_bundled_plugin/schemas/findings.schema.json +140 -427
  20. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  21. package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
  22. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  23. package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
  24. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  25. package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  27. package/_bundled_plugin/scripts/report_projection.py +35 -13
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  30. package/_bundled_plugin/scripts/workbench_cli.py +9 -9
  31. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  32. package/_bundled_plugin/scripts/workbench_db.py +103 -45
  33. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  34. package/_bundled_plugin/scripts/workbench_publication.py +216 -247
  35. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  36. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  37. package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
  38. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  39. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  40. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  41. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  42. package/_bundled_plugin/scripts/workbench_validation.py +52 -2
  43. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  44. package/_bundled_plugin/shared/workbench-migrations.json +22 -0
  45. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  46. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  47. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  48. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  49. package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
  50. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  51. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
  52. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
  53. package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
  54. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  55. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
  56. package/dist/api.d.ts +6 -2
  57. package/dist/api.d.ts.map +1 -1
  58. package/dist/api.js +266 -39
  59. package/dist/api.js.map +1 -1
  60. package/dist/artifact-export.d.ts +2 -1
  61. package/dist/artifact-export.d.ts.map +1 -1
  62. package/dist/artifact-export.js +38 -23
  63. package/dist/artifact-export.js.map +1 -1
  64. package/dist/classify-severity-records.d.ts +76 -0
  65. package/dist/classify-severity-records.d.ts.map +1 -0
  66. package/dist/classify-severity-records.js +141 -0
  67. package/dist/classify-severity-records.js.map +1 -0
  68. package/dist/classify-severity.d.ts +1 -23
  69. package/dist/classify-severity.d.ts.map +1 -1
  70. package/dist/classify-severity.js +3 -24
  71. package/dist/classify-severity.js.map +1 -1
  72. package/dist/cli-help.d.ts.map +1 -1
  73. package/dist/cli-help.js +2 -0
  74. package/dist/cli-help.js.map +1 -1
  75. package/dist/cli.d.ts +4 -2
  76. package/dist/cli.d.ts.map +1 -1
  77. package/dist/cli.js +148 -149
  78. package/dist/cli.js.map +1 -1
  79. package/dist/cloud-publish.js +1 -1
  80. package/dist/cloud-publish.js.map +1 -1
  81. package/dist/codex-sdk-environment.js +1 -1
  82. package/dist/codex-sdk-environment.js.map +1 -1
  83. package/dist/component-plan.js +1 -1
  84. package/dist/component-plan.js.map +1 -1
  85. package/dist/component-scan.d.ts.map +1 -1
  86. package/dist/component-scan.js +5 -4
  87. package/dist/component-scan.js.map +1 -1
  88. package/dist/config.d.ts +12 -0
  89. package/dist/config.d.ts.map +1 -1
  90. package/dist/config.js +10 -4
  91. package/dist/config.js.map +1 -1
  92. package/dist/contract.d.ts +6 -0
  93. package/dist/contract.d.ts.map +1 -1
  94. package/dist/contract.js +69 -20
  95. package/dist/contract.js.map +1 -1
  96. package/dist/cost-model.d.ts.map +1 -1
  97. package/dist/cost-model.js +7 -2
  98. package/dist/cost-model.js.map +1 -1
  99. package/dist/custom-validation-prompt.js +3 -3
  100. package/dist/custom-validation-prompt.js.map +1 -1
  101. package/dist/deduplication/codex-review.d.ts +1 -5
  102. package/dist/deduplication/codex-review.d.ts.map +1 -1
  103. package/dist/deduplication/codex-review.js +2 -2
  104. package/dist/deduplication/codex-review.js.map +1 -1
  105. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  106. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  107. package/dist/deduplication/deduplication-prompts.js +2 -2
  108. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  109. package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
  110. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  111. package/dist/deduplication/deduplication-reviewer.js +1 -1
  112. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  113. package/dist/deduplication/records-protocol.d.ts +3 -8
  114. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  115. package/dist/deduplication/records-protocol.js +11 -171
  116. package/dist/deduplication/records-protocol.js.map +1 -1
  117. package/dist/deduplication/records.js +1 -1
  118. package/dist/deduplication/records.js.map +1 -1
  119. package/dist/deduplication/scan.d.ts.map +1 -1
  120. package/dist/deduplication/scan.js +10 -9
  121. package/dist/deduplication/scan.js.map +1 -1
  122. package/dist/deep-config.d.ts +4 -1
  123. package/dist/deep-config.d.ts.map +1 -1
  124. package/dist/deep-config.js +21 -1
  125. package/dist/deep-config.js.map +1 -1
  126. package/dist/deep-progress.d.ts +15 -1
  127. package/dist/deep-progress.d.ts.map +1 -1
  128. package/dist/deep-progress.js +15 -16
  129. package/dist/deep-progress.js.map +1 -1
  130. package/dist/executable-path.d.ts +2 -0
  131. package/dist/executable-path.d.ts.map +1 -0
  132. package/dist/executable-path.js +12 -0
  133. package/dist/executable-path.js.map +1 -0
  134. package/dist/feedback.d.ts +1 -4
  135. package/dist/feedback.d.ts.map +1 -1
  136. package/dist/feedback.js +1 -1
  137. package/dist/feedback.js.map +1 -1
  138. package/dist/findings-import.d.ts +1 -1
  139. package/dist/findings-import.d.ts.map +1 -1
  140. package/dist/findings-import.js +3 -3
  141. package/dist/findings-import.js.map +1 -1
  142. package/dist/git-remote.d.ts +10 -0
  143. package/dist/git-remote.d.ts.map +1 -0
  144. package/dist/git-remote.js +24 -0
  145. package/dist/git-remote.js.map +1 -0
  146. package/dist/github.d.ts.map +1 -1
  147. package/dist/github.js +5 -7
  148. package/dist/github.js.map +1 -1
  149. package/dist/host-protocol.d.ts +19 -0
  150. package/dist/host-protocol.d.ts.map +1 -0
  151. package/dist/host-protocol.js +270 -0
  152. package/dist/host-protocol.js.map +1 -0
  153. package/dist/host-records-protocol.d.ts +15 -0
  154. package/dist/host-records-protocol.d.ts.map +1 -0
  155. package/dist/host-records-protocol.js +15 -0
  156. package/dist/host-records-protocol.js.map +1 -0
  157. package/dist/hosted-scan-protocol.d.ts +4 -0
  158. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  159. package/dist/hosted-scan-protocol.js +25 -0
  160. package/dist/hosted-scan-protocol.js.map +1 -0
  161. package/dist/hosted-scan.d.ts +112 -0
  162. package/dist/hosted-scan.d.ts.map +1 -0
  163. package/dist/hosted-scan.js +260 -0
  164. package/dist/hosted-scan.js.map +1 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +3 -0
  168. package/dist/index.js.map +1 -1
  169. package/dist/knowledge-base.d.ts.map +1 -1
  170. package/dist/knowledge-base.js +87 -7
  171. package/dist/knowledge-base.js.map +1 -1
  172. package/dist/multiscan.d.ts.map +1 -1
  173. package/dist/multiscan.js +108 -36
  174. package/dist/multiscan.js.map +1 -1
  175. package/dist/patch-publication.d.ts +26 -0
  176. package/dist/patch-publication.d.ts.map +1 -0
  177. package/dist/patch-publication.js +105 -0
  178. package/dist/patch-publication.js.map +1 -0
  179. package/dist/patch-tui.d.ts.map +1 -1
  180. package/dist/patch-tui.js +4 -1
  181. package/dist/patch-tui.js.map +1 -1
  182. package/dist/project-config-schema.d.ts +2 -0
  183. package/dist/project-config-schema.d.ts.map +1 -1
  184. package/dist/project-config-schema.js +1 -0
  185. package/dist/project-config-schema.js.map +1 -1
  186. package/dist/project-config.d.ts +1 -0
  187. package/dist/project-config.d.ts.map +1 -1
  188. package/dist/project-config.js +16 -6
  189. package/dist/project-config.js.map +1 -1
  190. package/dist/publication-store.d.ts.map +1 -1
  191. package/dist/publication-store.js +73 -63
  192. package/dist/publication-store.js.map +1 -1
  193. package/dist/publication.d.ts +0 -2
  194. package/dist/publication.d.ts.map +1 -1
  195. package/dist/publication.js +135 -24
  196. package/dist/publication.js.map +1 -1
  197. package/dist/publish.d.ts.map +1 -1
  198. package/dist/publish.js +39 -25
  199. package/dist/publish.js.map +1 -1
  200. package/dist/runtime.d.ts +5 -2
  201. package/dist/runtime.d.ts.map +1 -1
  202. package/dist/runtime.js +86 -58
  203. package/dist/runtime.js.map +1 -1
  204. package/dist/scan-executor.d.ts +104 -0
  205. package/dist/scan-executor.d.ts.map +1 -0
  206. package/dist/scan-executor.js +62 -0
  207. package/dist/scan-executor.js.map +1 -0
  208. package/dist/scan-settings.d.ts +1 -0
  209. package/dist/scan-settings.d.ts.map +1 -1
  210. package/dist/scan-settings.js +7 -1
  211. package/dist/scan-settings.js.map +1 -1
  212. package/dist/scan-time-budget.d.ts +9 -0
  213. package/dist/scan-time-budget.d.ts.map +1 -0
  214. package/dist/scan-time-budget.js +16 -0
  215. package/dist/scan-time-budget.js.map +1 -0
  216. package/dist/severity-review.d.ts +29 -0
  217. package/dist/severity-review.d.ts.map +1 -0
  218. package/dist/severity-review.js +47 -0
  219. package/dist/severity-review.js.map +1 -0
  220. package/dist/targets.d.ts.map +1 -1
  221. package/dist/targets.js +17 -25
  222. package/dist/targets.js.map +1 -1
  223. package/dist/validation-records.d.ts +38 -0
  224. package/dist/validation-records.d.ts.map +1 -0
  225. package/dist/validation-records.js +76 -0
  226. package/dist/validation-records.js.map +1 -0
  227. package/dist/version.d.ts.map +1 -1
  228. package/dist/version.js +4 -2
  229. package/dist/version.js.map +1 -1
  230. package/dist/worker-progress.d.ts +43 -15
  231. package/dist/worker-progress.d.ts.map +1 -1
  232. package/dist/worker-progress.js +22 -80
  233. package/dist/worker-progress.js.map +1 -1
  234. package/docs/classify-severity-records.md +89 -0
  235. package/docs/cli.md +281 -35
  236. package/docs/hosted-scans.md +242 -0
  237. package/docs/validate-records.md +69 -0
  238. package/package.json +18 -14
  239. package/schemas/hosted-scan-v2.fixture.json +145 -0
  240. package/schemas/project-config.schema.json +7 -1
  241. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  242. package/_bundled_plugin/references/config-preflight.md +0 -93
  243. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  244. package/_bundled_plugin/scripts/config_preflight.py +0 -911
@@ -7,7 +7,7 @@ import json
7
7
  import re
8
8
  import sys
9
9
  from bisect import bisect_right
10
- from itertools import chain
10
+ from itertools import chain, islice
11
11
  from pathlib import Path
12
12
  from typing import Any
13
13
 
@@ -390,7 +390,7 @@ def bounded_json_value(
390
390
  if not consume_json_budget(budget, 2):
391
391
  return {}
392
392
  result = {}
393
- for key, item in list(value.items())[:20]:
393
+ for key, item in islice(value.items(), 20):
394
394
  if budget[0] <= 0 or not isinstance(key, str):
395
395
  break
396
396
  remaining = budget[0]
@@ -447,7 +447,9 @@ def consume_json_budget(budget: list[int], size: int) -> bool:
447
447
 
448
448
 
449
449
  def bounded_json_text(value: str, maximum_bytes: int) -> tuple[str, int]:
450
- length = bisect_right(range(len(value) + 1), maximum_bytes, key=lambda n: json_size(value[:n]))
450
+ length = bisect_right(
451
+ range(min(len(value), maximum_bytes) + 1), maximum_bytes, key=lambda n: json_size(value[:n])
452
+ )
451
453
  selected = value[: max(0, length - 1)]
452
454
  return selected, json_size(selected)
453
455
 
@@ -3,14 +3,13 @@
3
3
 
4
4
  This script stays deliberately model-free:
5
5
 
6
- - `make-repo-rank-input` creates the deterministic repository or scoped-path
7
- JSONL candidate worklist that ranking subagents consume.
6
+ - `make-repo-scope-input` lists every explicitly scoped repository file.
8
7
  - `make-diff-rank-input` creates the deterministic diff-scoped JSONL candidate
9
8
  worklist from Git changed paths. It supports committed revision diffs and
10
9
  local working-tree patches.
11
10
 
12
11
  Candidate selection uses repository scope, native tool ignore rules, and binary detection,
13
- not filename or directory classifications. Ranking inputs use bounded source previews.
12
+ not filename or directory classifications. Diff inputs use bounded source previews.
14
13
  """
15
14
 
16
15
  from __future__ import annotations
@@ -41,29 +40,6 @@ def parse_args() -> argparse.Namespace:
41
40
  parser = argparse.ArgumentParser(description="Codex Security scan worklist helper.")
42
41
  subparsers = parser.add_subparsers(dest="command", required=True)
43
42
 
44
- make = subparsers.add_parser(
45
- "make-repo-rank-input",
46
- help="Create rank_input.jsonl for subagent-based file ranking.",
47
- )
48
- make.add_argument("--repo", required=True, help="Repository root.")
49
- make.add_argument(
50
- "--scope",
51
- default=".",
52
- help="Path within the repository to scan. Defaults to the repository root.",
53
- )
54
- make.add_argument(
55
- "--scopes-file",
56
- help="JSON array of repository-relative files and directories to scan together.",
57
- )
58
- make.add_argument("--out", required=True, help="Output rank_input.jsonl path.")
59
- make.add_argument("--area", default="", help="Area label. Defaults to scope.")
60
- make.add_argument(
61
- "--preview-bytes",
62
- type=int,
63
- default=DEFAULT_PREVIEW_BYTES,
64
- help=f"Maximum UTF-8 bytes in each preview. Defaults to {DEFAULT_PREVIEW_BYTES}.",
65
- )
66
-
67
43
  scoped = subparsers.add_parser(
68
44
  "make-repo-scope-input",
69
45
  help="List every explicitly scoped file without ranking or reading its contents.",
@@ -90,7 +66,7 @@ def parse_args() -> argparse.Namespace:
90
66
  )
91
67
  diff.add_argument("--head", default="HEAD", help="Git diff head revision.")
92
68
  diff.add_argument("--out", required=True, help="Output rank_input.jsonl path.")
93
- diff.add_argument("--area", default="diff", help="Area label for ranking rows.")
69
+ diff.add_argument("--area", default="diff", help="Area label for changed-file rows.")
94
70
  diff.add_argument(
95
71
  "--preview-bytes",
96
72
  type=int,
@@ -101,39 +77,32 @@ def parse_args() -> argparse.Namespace:
101
77
  return parser.parse_args()
102
78
 
103
79
 
104
- def resolve_scope(
105
- repo: Path,
106
- scope: str,
107
- *,
108
- expand_user: bool = True,
109
- reject_symlinks: bool = False,
110
- ) -> Path:
111
- scope_path = Path(scope).expanduser() if expand_user else Path(scope)
80
+ def resolve_scope(repo: Path, scope: str) -> Path:
81
+ scope_path = Path(scope)
112
82
  stream = windows_stream_component(scope_path)
113
83
  if stream is not None:
114
84
  raise SystemExit(f"Scope must not use an NTFS alternate data stream: {stream}")
115
85
  if not scope_path.is_absolute():
116
86
  scope_path = repo / scope_path
117
- if reject_symlinks:
118
- repository = repo.resolve()
87
+ repository = repo.resolve()
88
+ try:
89
+ relative = scope_path.relative_to(repository)
90
+ except ValueError as exc:
91
+ raise SystemExit(f"Scope must be inside repo: {scope_path}") from exc
92
+ ancestor = repository
93
+ for part in relative.parts:
94
+ if part == "..":
95
+ if ancestor == repository:
96
+ raise SystemExit(f"Scope must be inside repo: {scope_path}")
97
+ ancestor = ancestor.parent
98
+ continue
99
+ ancestor /= part
119
100
  try:
120
- relative = scope_path.relative_to(repository)
121
- except ValueError as exc:
122
- raise SystemExit(f"Scope must be inside repo: {scope_path}") from exc
123
- ancestor = repository
124
- for part in relative.parts:
125
- if part == "..":
126
- if ancestor == repository:
127
- raise SystemExit(f"Scope must be inside repo: {scope_path}")
128
- ancestor = ancestor.parent
129
- continue
130
- ancestor /= part
131
- try:
132
- metadata = ancestor.stat(follow_symlinks=False)
133
- except OSError as exc:
134
- raise SystemExit(f"Scope path not found: {ancestor}") from exc
135
- if ancestor.is_symlink() or getattr(metadata, "st_reparse_tag", 0) & 0x20000000:
136
- raise SystemExit(f"Requested scope must not contain symbolic links: {ancestor}")
101
+ metadata = ancestor.stat(follow_symlinks=False)
102
+ except OSError as exc:
103
+ raise SystemExit(f"Scope path not found: {ancestor}") from exc
104
+ if ancestor.is_symlink() or getattr(metadata, "st_reparse_tag", 0) & 0x20000000:
105
+ raise SystemExit(f"Requested scope must not contain symbolic links: {ancestor}")
137
106
  scope_path = scope_path.resolve()
138
107
  repo_resolved = repo.resolve()
139
108
  try:
@@ -221,54 +190,6 @@ def scope_candidates(repo: Path, scope_path: Path) -> Iterable[Path]:
221
190
  return (repo / os.fsdecode(path) for path in result.stdout.split(b"\0") if path)
222
191
 
223
192
 
224
- def make_repo_rank_input(args: argparse.Namespace) -> None:
225
- repo = Path(args.repo).expanduser().resolve()
226
- if not repo.is_dir():
227
- raise SystemExit(f"Repo path not found: {repo}")
228
- scopes = [args.scope]
229
- explicit_scopes = args.scopes_file is not None
230
- if explicit_scopes:
231
- scopes = load_scopes_file(Path(args.scopes_file).expanduser())
232
-
233
- resolved_scopes = [
234
- resolve_scope(repo, scope, expand_user=not explicit_scopes) for scope in scopes
235
- ]
236
- directly_requested_files = {
237
- scope_abs for scope_abs in resolved_scopes if explicit_scopes and scope_abs.is_file()
238
- }
239
- rows_by_path: dict[str, JsonRow] = {}
240
- for scope_abs in resolved_scopes:
241
- scope_rel = scope_abs.relative_to(repo)
242
- area = args.area or scope_rel.as_posix()
243
- candidates = scope_candidates(repo, scope_abs)
244
- for path in candidates:
245
- try:
246
- if path.is_symlink() or not path.is_file():
247
- continue
248
- path.resolve(strict=True).relative_to(repo)
249
- except (OSError, ValueError):
250
- continue
251
- rel = path.relative_to(repo)
252
- directly_requested = path in directly_requested_files
253
- if ".git" in rel.parts:
254
- continue
255
-
256
- preview, is_binary = preview_for(path, args.preview_bytes)
257
- if is_binary or is_binary_file(path):
258
- if not directly_requested:
259
- continue
260
- preview = ""
261
- rows_by_path.setdefault(
262
- rel.as_posix(),
263
- {"path": rel.as_posix(), "area": area, "preview": preview},
264
- )
265
-
266
- rows = sorted(rows_by_path.values(), key=lambda row: str(row["path"]))
267
- output = Path(args.out).expanduser()
268
- write_jsonl(output, rows)
269
- print(f"Wrote {len(rows)} rows to {output}")
270
-
271
-
272
193
  def make_repo_scope_input(args: argparse.Namespace) -> None:
273
194
  repo = Path(args.repo).expanduser().resolve()
274
195
  if not repo.is_dir():
@@ -277,7 +198,7 @@ def make_repo_scope_input(args: argparse.Namespace) -> None:
277
198
  scopes = load_scopes_file(Path(args.scopes_file).expanduser())
278
199
  rows_by_path: dict[str, JsonRow] = {}
279
200
  for scope in scopes:
280
- scope_path = resolve_scope(repo, scope, expand_user=False, reject_symlinks=True)
201
+ scope_path = resolve_scope(repo, scope)
281
202
  candidates = scope_candidates(repo, scope_path)
282
203
  for path in candidates:
283
204
  try:
@@ -306,6 +227,7 @@ def run_git_changed_paths(repo: Path, diff_args: list[str]) -> list[tuple[Path,
306
227
  "-z",
307
228
  "--diff-filter=ACMRDT",
308
229
  *diff_args,
230
+ "--",
309
231
  text=False,
310
232
  )
311
233
  result.check_returncode()
@@ -410,9 +332,7 @@ def make_diff_rank_input(args: argparse.Namespace) -> None:
410
332
 
411
333
  def main() -> None:
412
334
  args = parse_args()
413
- if args.command == "make-repo-rank-input":
414
- make_repo_rank_input(args)
415
- elif args.command == "make-repo-scope-input":
335
+ if args.command == "make-repo-scope-input":
416
336
  make_repo_scope_input(args)
417
337
  elif args.command == "make-diff-rank-input":
418
338
  make_diff_rank_input(args)
@@ -47,20 +47,55 @@ case "${CODEX_CLI_PATH:-}" in
47
47
  */*) codex_resources=${CODEX_CLI_PATH%/*} ;;
48
48
  esac
49
49
 
50
+ # An explicitly selected runtime remains authoritative.
51
+ if [ -n "${CODEX_MCP_NODE_PATH:-}" ] && [ -x "$CODEX_MCP_NODE_PATH" ]; then
52
+ launch_node "$CODEX_MCP_NODE_PATH" "$@"
53
+ fi
54
+
55
+ first_node=
56
+ can_load_native() {
57
+ if [ -z "$first_node" ]; then
58
+ first_node=$1
59
+ fi
60
+ # Some managed macOS runtimes enforce library validation and cannot load the
61
+ # plugin's addon. Check before starting a server or helper with side effects.
62
+ # Capture output without opening a writable file for read-only callers.
63
+ _native_probe_output=$("$1" -e '
64
+ if (process.platform === "darwin") {
65
+ require("node:sqlite");
66
+ require(require("node:path").join(process.argv[1], "native",
67
+ `${process.platform}-${process.arch}`, "unix.node"));
68
+ }
69
+ ' "$launcher_dir/../mcp" </dev/null 2>&1)
70
+ }
71
+
50
72
  for candidate in \
51
- "${CODEX_MCP_NODE_PATH:-}" \
52
73
  "${CODEX_BROWSER_USE_NODE_PATH:-}" \
53
74
  "${CODEX_ELECTRON_RESOURCES_PATH:-}/cua_node/bin/node" \
54
75
  "$codex_resources/cua_node/bin/node" \
55
76
  "$cache_root/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
56
77
  do
57
- if [ -n "$candidate" ] && [ -x "$candidate" ]; then
78
+ if [ -n "$candidate" ] && [ -x "$candidate" ] && can_load_native "$candidate"; then
58
79
  launch_node "$candidate" "$@"
59
80
  fi
60
81
  done
61
82
 
62
- if node_path=$(command -v node); then
63
- launch_node "$node_path" "$@"
83
+ remaining_path=$PATH
84
+ while :; do
85
+ path_entry=${remaining_path%%:*}
86
+ node_path=${path_entry:-.}/node
87
+ if [ -x "$node_path" ] && can_load_native "$node_path"; then
88
+ launch_node "$node_path" "$@"
89
+ fi
90
+ case "$remaining_path" in
91
+ *:*) remaining_path=${remaining_path#*:} ;;
92
+ *) break ;;
93
+ esac
94
+ done
95
+
96
+ if [ -n "$first_node" ]; then
97
+ # Helpers that do not use the addon can still run with the original default.
98
+ launch_node "$first_node" "$@"
64
99
  fi
65
100
 
66
101
  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
@@ -4,6 +4,7 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
+ import json
7
8
  import re
8
9
  from collections import Counter
9
10
  from typing import Any
@@ -28,7 +29,7 @@ class ReportProjectionError(ValueError):
28
29
  def _text(value: Any, fallback: str) -> str:
29
30
  candidate = value if isinstance(value, str) and value.strip() else fallback
30
31
  normalized = " ".join(candidate.split())
31
- if re.match(r"^(?:#{1,6}\s|[-*+]\s|>\s|```|\d+\.\s|\|)", normalized):
32
+ if re.match(r"^(?:#{1,6}\s|[-*+]\s|>\s|```|~~~|\d+[.)]\s|\|)", normalized):
32
33
  normalized = f"Text: {normalized}"
33
34
  return "".join(
34
35
  part if index % 2 else re.sub(r"([\\`*_\[\]<>])", r"\\\1", part)
@@ -44,6 +45,20 @@ def _strings(value: Any) -> list[str]:
44
45
  return [text for item in value if (text := _text(item, ""))]
45
46
 
46
47
 
48
+ def _path_label(value: str) -> str:
49
+ if "," in value or value != " ".join(value.split()) or any(ord(c) < 32 for c in value):
50
+ return json.dumps(value)
51
+ return value
52
+
53
+
54
+ def _path_text(value: str) -> str:
55
+ label = _path_label(value)
56
+ if label != value:
57
+ marker = _code_fence(label, minimum=1)
58
+ return f"{marker}{label}{marker}"
59
+ return re.sub(r"([\\`*_\[\]<>])", r"\\\1", value)
60
+
61
+
47
62
  def _cell(value: Any) -> str:
48
63
  return _text(value, "none").replace("|", "\\|").replace("\n", "<br>")
49
64
 
@@ -386,17 +401,20 @@ def _root_cause_code_evidence(
386
401
  def _code_evidence_location(item: dict[str, Any]) -> str:
387
402
  location = item.get("location")
388
403
  if isinstance(location, str):
389
- return location
404
+ return " ".join(location.split())
390
405
  if isinstance(location, dict):
391
406
  item = location
392
407
  path = item.get("path")
393
408
  start = item.get("startLine")
394
- end = item.get("endLine", start)
409
+ end = item.get("endLine")
395
410
  if not isinstance(path, str) or not path:
396
411
  return ""
397
- if not isinstance(start, int):
412
+ path = _path_label(path)
413
+ if not isinstance(start, int) or isinstance(start, bool) or start < 1:
398
414
  return path
399
- return f"{path}:{start}" if end == start else f"{path}:{start}-{end}"
415
+ if not isinstance(end, int) or isinstance(end, bool) or end <= start:
416
+ return f"{path}:{start}"
417
+ return f"{path}:{start}-{end}"
400
418
 
401
419
 
402
420
  def _code_fence(code: str, minimum: int = 3) -> str:
@@ -408,7 +426,7 @@ def _code_evidence_lines(evidence: list[dict[str, Any]]) -> list[str]:
408
426
  lines: list[str] = []
409
427
  for index, item in enumerate(evidence):
410
428
  label = _text(item.get("label"), f"Code evidence {index + 1}")
411
- location = " ".join(_code_evidence_location(item).split())
429
+ location = _code_evidence_location(item)
412
430
  explanation = _text(item.get("explanation"), "")
413
431
  language = item.get("language") if isinstance(item.get("language"), str) else ""
414
432
  language = language if re.fullmatch(r"[A-Za-z0-9_+.-]*", language) else ""
@@ -437,7 +455,7 @@ def _locations(finding: dict[str, Any]) -> str:
437
455
  start = location["startLine"]
438
456
  end = location.get("endLine", start)
439
457
  suffix = f":{start}" if end == start else f":{start}-{end}"
440
- rendered.append(f"{location['path']}{suffix}")
458
+ rendered.append(f"{_path_text(location['path'])}{suffix}")
441
459
  return ", ".join(rendered)
442
460
 
443
461
 
@@ -541,7 +559,7 @@ def _finding_header(number: int, finding: dict[str, Any]) -> list[str]:
541
559
  f"| Confidence rationale | {_cell(finding['confidence']['rationale'])} |",
542
560
  f"| Category | {_cell(finding['taxonomy']['category'])} |",
543
561
  f"| CWE | {_cell(cwes)} |",
544
- f"| Affected lines | {_cell(_locations(finding))} |",
562
+ "| Affected lines | " + _locations(finding).replace("|", "\\|") + " |",
545
563
  ]
546
564
 
547
565
 
@@ -615,9 +633,9 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
615
633
  validation_code_evidence = _section_code_evidence(finding, validation)
616
634
  dataflow_code_evidence = _section_code_evidence(finding, attack_path, *dataflow_sections)
617
635
  reachability_code_evidence = _section_code_evidence(finding, reachability)
618
- dataflow_summary = _text(
619
- dataflow.get("summary"),
620
- f"The canonical finding records the affected path at {_locations(finding)}, but no expanded source-to-sink narrative was recorded.",
636
+ dataflow_summary = _text(dataflow.get("summary"), "") or (
637
+ f"The canonical finding records the affected path at {_locations(finding)}, "
638
+ "but no expanded source-to-sink narrative was recorded."
621
639
  )
622
640
  reachability_summary = _text(reachability.get("summary"), "") or _text(
623
641
  attack_path.get("summary"),
@@ -769,8 +787,12 @@ def build_report_markdown(
769
787
  deep_presentation = uses_deep_presentation(coverage, findings)
770
788
  deep_finding_groups = _deep_finding_groups(findings, writeup_paths) if deep_presentation else []
771
789
  hardening_portfolio_path = _hardening_portfolio_path(scan)
772
- include_paths = _strings(coverage.get("includePaths", scope.get("includePaths", [])))
773
- exclude_paths = _strings(coverage.get("excludePaths", scope.get("excludePaths", [])))
790
+ include_paths = [
791
+ _path_text(path) for path in coverage.get("includePaths", scope.get("includePaths", []))
792
+ ]
793
+ exclude_paths = [
794
+ _path_text(path) for path in coverage.get("excludePaths", scope.get("excludePaths", []))
795
+ ]
774
796
  limitations = _strings(scope.get("limitations"))
775
797
  explicit_exclusions = coverage.get("explicitExclusions", [])
776
798
  lines = [
@@ -22,6 +22,13 @@ def main() -> None:
22
22
  destination.parent.mkdir(parents=True, exist_ok=True)
23
23
  source_uri = f"file:{quote(str(source), safe='')}?mode=ro"
24
24
  with sqlite3.connect(source_uri, uri=True) as source_connection:
25
+ creation_destination = destination.resolve()
26
+ try:
27
+ creation_destination.touch(mode=0o600, exist_ok=False)
28
+ except FileExistsError:
29
+ pass
30
+ else:
31
+ creation_destination.chmod(0o600)
25
32
  with sqlite3.connect(destination) as destination_connection:
26
33
  source_connection.backup(destination_connection)
27
34
  destination.chmod(0o600)
@@ -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)
@@ -208,6 +205,14 @@ def parse_args(description: str) -> argparse.Namespace:
208
205
  complete_scan.add_argument("--claim-token")
209
206
  complete_scan.add_argument("--cost-json")
210
207
  complete_scan.add_argument("--thread-id")
208
+ complete_scan.add_argument("--turn-id")
209
+
210
+ finalize_scan_usage = add_command(
211
+ "finalize-scan-usage", "--scan-id", "--thread-id", "--turn-id"
212
+ )
213
+ finalize_scan_usage.add_argument(
214
+ "--turn-status", choices=("completed", "interrupted", "failed"), default="completed"
215
+ )
211
216
 
212
217
  complete_budget_exhausted_scan = add_command(
213
218
  "complete-budget-exhausted-scan", "--scan-id", "--cost-json"
@@ -299,12 +304,7 @@ def parse_args(description: str) -> argparse.Namespace:
299
304
  export_findings.add_argument("--format", choices=(*EXPORT_FORMATS, "md"))
300
305
  export_findings.add_argument("--validate-only", action="store_true")
301
306
 
302
- for command in (
303
- "inspect-linear-publication",
304
- "prepare-linear-publication",
305
- "record-linear-publications",
306
- ):
307
- add_command(command, "--input-file")
307
+ subparsers.add_parser("finding-issues")
308
308
 
309
309
  subparsers.add_parser("database-info")
310
310
  subparsers.add_parser("finding-workflow")
@@ -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: