@openai/codex-security 0.1.31 → 0.2.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 (314) hide show
  1. package/README.md +295 -32
  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/THIRD_PARTY_NOTICES.txt +4 -4
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  14. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  15. package/_bundled_plugin/references/artifact-storage.md +4 -4
  16. package/_bundled_plugin/references/config-preflight.md +1 -1
  17. package/_bundled_plugin/references/core-scan.md +14 -2
  18. package/_bundled_plugin/references/final-report.md +4 -2
  19. package/_bundled_plugin/references/scan-artifacts.md +2 -2
  20. package/_bundled_plugin/references/scan-contract.md +2 -2
  21. package/_bundled_plugin/references/threat-model.md +2 -2
  22. package/_bundled_plugin/schemas/coverage.schema.json +22 -0
  23. package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
  24. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
  25. package/_bundled_plugin/scripts/config_preflight.py +4 -8
  26. package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
  27. package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
  28. package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
  29. package/_bundled_plugin/scripts/finding_preview.py +42 -82
  30. package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
  31. package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
  32. package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
  33. package/_bundled_plugin/scripts/rank_preview.py +85 -68
  34. package/_bundled_plugin/scripts/report_projection.py +37 -58
  35. package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
  36. package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
  37. package/_bundled_plugin/scripts/workbench/storage.py +11 -0
  38. package/_bundled_plugin/scripts/workbench_cli.py +11 -17
  39. package/_bundled_plugin/scripts/workbench_constants.py +6 -14
  40. package/_bundled_plugin/scripts/workbench_db.py +116 -228
  41. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
  42. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
  43. package/_bundled_plugin/scripts/workbench_progress.py +12 -34
  44. package/_bundled_plugin/scripts/workbench_publication.py +47 -62
  45. package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
  46. package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
  47. package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
  48. package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
  49. package/_bundled_plugin/scripts/workbench_schema.py +86 -271
  50. package/_bundled_plugin/scripts/workbench_severity.py +3 -0
  51. package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
  52. package/_bundled_plugin/scripts/workbench_target.py +98 -10
  53. package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
  54. package/_bundled_plugin/scripts/workbench_validation.py +6 -20
  55. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  56. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
  57. package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
  58. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  59. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  60. package/dist/api.d.ts +3 -5
  61. package/dist/api.d.ts.map +1 -1
  62. package/dist/api.js +201 -207
  63. package/dist/api.js.map +1 -1
  64. package/dist/artifact-export.d.ts +70 -0
  65. package/dist/artifact-export.d.ts.map +1 -0
  66. package/dist/artifact-export.js +277 -0
  67. package/dist/artifact-export.js.map +1 -0
  68. package/dist/auth.d.ts.map +1 -1
  69. package/dist/auth.js +8 -3
  70. package/dist/auth.js.map +1 -1
  71. package/dist/bulk-scan-discovery.d.ts +1 -0
  72. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  73. package/dist/bulk-scan-discovery.js +8 -9
  74. package/dist/bulk-scan-discovery.js.map +1 -1
  75. package/dist/classify-scan-severity.d.ts.map +1 -1
  76. package/dist/classify-scan-severity.js +2 -5
  77. package/dist/classify-scan-severity.js.map +1 -1
  78. package/dist/classify-severity.d.ts +2 -8
  79. package/dist/classify-severity.d.ts.map +1 -1
  80. package/dist/classify-severity.js +3 -5
  81. package/dist/classify-severity.js.map +1 -1
  82. package/dist/cli-help.d.ts +3 -0
  83. package/dist/cli-help.d.ts.map +1 -0
  84. package/dist/cli-help.js +281 -0
  85. package/dist/cli-help.js.map +1 -0
  86. package/dist/cli.d.ts +19 -22
  87. package/dist/cli.d.ts.map +1 -1
  88. package/dist/cli.js +631 -714
  89. package/dist/cli.js.map +1 -1
  90. package/dist/cloud-publish.d.ts.map +1 -1
  91. package/dist/cloud-publish.js +1 -8
  92. package/dist/cloud-publish.js.map +1 -1
  93. package/dist/codex-prompt.d.ts.map +1 -1
  94. package/dist/codex-prompt.js +1 -2
  95. package/dist/codex-prompt.js.map +1 -1
  96. package/dist/codex-sdk-environment.d.ts +2 -0
  97. package/dist/codex-sdk-environment.d.ts.map +1 -0
  98. package/dist/codex-sdk-environment.js +30 -0
  99. package/dist/codex-sdk-environment.js.map +1 -0
  100. package/dist/component-plan.d.ts.map +1 -1
  101. package/dist/component-plan.js +2 -6
  102. package/dist/component-plan.js.map +1 -1
  103. package/dist/component-scan.d.ts +1 -0
  104. package/dist/component-scan.d.ts.map +1 -1
  105. package/dist/component-scan.js +31 -9
  106. package/dist/component-scan.js.map +1 -1
  107. package/dist/config.d.ts.map +1 -1
  108. package/dist/config.js +32 -33
  109. package/dist/config.js.map +1 -1
  110. package/dist/contract.d.ts +2 -1
  111. package/dist/contract.d.ts.map +1 -1
  112. package/dist/contract.js +63 -122
  113. package/dist/contract.js.map +1 -1
  114. package/dist/cost-model.d.ts.map +1 -1
  115. package/dist/cost-model.js +65 -34
  116. package/dist/cost-model.js.map +1 -1
  117. package/dist/cost.d.ts.map +1 -1
  118. package/dist/cost.js +15 -31
  119. package/dist/cost.js.map +1 -1
  120. package/dist/custom-validation-prompt.js +4 -4
  121. package/dist/custom-validation-prompt.js.map +1 -1
  122. package/dist/custom-validation.d.ts.map +1 -1
  123. package/dist/custom-validation.js +17 -16
  124. package/dist/custom-validation.js.map +1 -1
  125. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  126. package/dist/deduplication/checkpointed-review.js +10 -11
  127. package/dist/deduplication/checkpointed-review.js.map +1 -1
  128. package/dist/deduplication/codex-review.d.ts +2 -0
  129. package/dist/deduplication/codex-review.d.ts.map +1 -1
  130. package/dist/deduplication/codex-review.js +3 -3
  131. package/dist/deduplication/codex-review.js.map +1 -1
  132. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  133. package/dist/deduplication/deduplication-reviewer.js +2 -0
  134. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  135. package/dist/deduplication/deduplication.js +40 -62
  136. package/dist/deduplication/deduplication.js.map +1 -1
  137. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  138. package/dist/deduplication/records-protocol.js +1 -4
  139. package/dist/deduplication/records-protocol.js.map +1 -1
  140. package/dist/deduplication/records.d.ts +2 -1
  141. package/dist/deduplication/records.d.ts.map +1 -1
  142. package/dist/deduplication/records.js +24 -6
  143. package/dist/deduplication/records.js.map +1 -1
  144. package/dist/deduplication/review.d.ts +7 -0
  145. package/dist/deduplication/review.d.ts.map +1 -1
  146. package/dist/deduplication/review.js.map +1 -1
  147. package/dist/deduplication/scan.js +3 -7
  148. package/dist/deduplication/scan.js.map +1 -1
  149. package/dist/deep-config.d.ts.map +1 -1
  150. package/dist/deep-config.js +3 -19
  151. package/dist/deep-config.js.map +1 -1
  152. package/dist/deep-progress.d.ts +0 -1
  153. package/dist/deep-progress.d.ts.map +1 -1
  154. package/dist/deep-progress.js +22 -40
  155. package/dist/deep-progress.js.map +1 -1
  156. package/dist/errors.d.ts +3 -2
  157. package/dist/errors.d.ts.map +1 -1
  158. package/dist/errors.js +5 -7
  159. package/dist/errors.js.map +1 -1
  160. package/dist/finding-catalogue.d.ts.map +1 -1
  161. package/dist/finding-catalogue.js +22 -22
  162. package/dist/finding-catalogue.js.map +1 -1
  163. package/dist/finding-workflow.d.ts.map +1 -1
  164. package/dist/finding-workflow.js +4 -7
  165. package/dist/finding-workflow.js.map +1 -1
  166. package/dist/findings-import.d.ts.map +1 -1
  167. package/dist/findings-import.js +7 -17
  168. package/dist/findings-import.js.map +1 -1
  169. package/dist/github.d.ts.map +1 -1
  170. package/dist/github.js +2 -3
  171. package/dist/github.js.map +1 -1
  172. package/dist/import-scan.js +2 -2
  173. package/dist/import-scan.js.map +1 -1
  174. package/dist/index.d.ts +4 -2
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +2 -1
  177. package/dist/index.js.map +1 -1
  178. package/dist/knowledge-base.js +2 -2
  179. package/dist/knowledge-base.js.map +1 -1
  180. package/dist/linear.d.ts.map +1 -1
  181. package/dist/linear.js +2 -3
  182. package/dist/linear.js.map +1 -1
  183. package/dist/models.d.ts +24 -0
  184. package/dist/models.d.ts.map +1 -1
  185. package/dist/models.js.map +1 -1
  186. package/dist/multiscan.d.ts.map +1 -1
  187. package/dist/multiscan.js +36 -31
  188. package/dist/multiscan.js.map +1 -1
  189. package/dist/owner-evidence.d.ts.map +1 -1
  190. package/dist/owner-evidence.js +2 -6
  191. package/dist/owner-evidence.js.map +1 -1
  192. package/dist/patch-tui.d.ts.map +1 -1
  193. package/dist/patch-tui.js +2 -4
  194. package/dist/patch-tui.js.map +1 -1
  195. package/dist/project-config-schema.d.ts +10 -0
  196. package/dist/project-config-schema.d.ts.map +1 -1
  197. package/dist/project-config-schema.js +1 -0
  198. package/dist/project-config-schema.js.map +1 -1
  199. package/dist/project-config.d.ts +1 -0
  200. package/dist/project-config.d.ts.map +1 -1
  201. package/dist/project-config.js +2 -0
  202. package/dist/project-config.js.map +1 -1
  203. package/dist/prompt-files.d.ts +0 -1
  204. package/dist/prompt-files.d.ts.map +1 -1
  205. package/dist/prompt-files.js +2 -4
  206. package/dist/prompt-files.js.map +1 -1
  207. package/dist/publication-events.d.ts.map +1 -1
  208. package/dist/publication-events.js +15 -29
  209. package/dist/publication-events.js.map +1 -1
  210. package/dist/publication-store.d.ts.map +1 -1
  211. package/dist/publication-store.js +9 -13
  212. package/dist/publication-store.js.map +1 -1
  213. package/dist/publication.d.ts.map +1 -1
  214. package/dist/publication.js +11 -14
  215. package/dist/publication.js.map +1 -1
  216. package/dist/publish.d.ts.map +1 -1
  217. package/dist/publish.js +31 -41
  218. package/dist/publish.js.map +1 -1
  219. package/dist/record.d.ts +2 -0
  220. package/dist/record.d.ts.map +1 -0
  221. package/dist/record.js +4 -0
  222. package/dist/record.js.map +1 -0
  223. package/dist/result.d.ts +4 -1
  224. package/dist/result.d.ts.map +1 -1
  225. package/dist/result.js +7 -0
  226. package/dist/result.js.map +1 -1
  227. package/dist/runtime.d.ts +10 -13
  228. package/dist/runtime.d.ts.map +1 -1
  229. package/dist/runtime.js +203 -131
  230. package/dist/runtime.js.map +1 -1
  231. package/dist/saved-scan.d.ts.map +1 -1
  232. package/dist/saved-scan.js +10 -20
  233. package/dist/saved-scan.js.map +1 -1
  234. package/dist/scan-activity.d.ts.map +1 -1
  235. package/dist/scan-activity.js +8 -22
  236. package/dist/scan-activity.js.map +1 -1
  237. package/dist/scan-comparison.d.ts +3 -3
  238. package/dist/scan-comparison.d.ts.map +1 -1
  239. package/dist/scan-comparison.js +38 -73
  240. package/dist/scan-comparison.js.map +1 -1
  241. package/dist/scan-dashboard.d.ts +0 -1
  242. package/dist/scan-dashboard.d.ts.map +1 -1
  243. package/dist/scan-dashboard.js +10 -19
  244. package/dist/scan-dashboard.js.map +1 -1
  245. package/dist/scan-history-renderer.d.ts.map +1 -1
  246. package/dist/scan-history-renderer.js +1 -2
  247. package/dist/scan-history-renderer.js.map +1 -1
  248. package/dist/scan-logs.d.ts.map +1 -1
  249. package/dist/scan-logs.js +2 -6
  250. package/dist/scan-logs.js.map +1 -1
  251. package/dist/scan-sessions.d.ts.map +1 -1
  252. package/dist/scan-sessions.js +1 -3
  253. package/dist/scan-sessions.js.map +1 -1
  254. package/dist/scan-settings.d.ts +5 -0
  255. package/dist/scan-settings.d.ts.map +1 -1
  256. package/dist/scan-settings.js +4 -0
  257. package/dist/scan-settings.js.map +1 -1
  258. package/dist/security-policy-cli.d.ts.map +1 -1
  259. package/dist/security-policy-cli.js +8 -6
  260. package/dist/security-policy-cli.js.map +1 -1
  261. package/dist/security-policy.d.ts +8 -4
  262. package/dist/security-policy.d.ts.map +1 -1
  263. package/dist/security-policy.js +98 -84
  264. package/dist/security-policy.js.map +1 -1
  265. package/dist/server/dashboard/app.js +5 -5
  266. package/dist/server/embeddings.d.ts.map +1 -1
  267. package/dist/server/embeddings.js +1 -0
  268. package/dist/server/embeddings.js.map +1 -1
  269. package/dist/server/routes.d.ts +3 -2
  270. package/dist/server/routes.d.ts.map +1 -1
  271. package/dist/server/routes.js +19 -7
  272. package/dist/server/routes.js.map +1 -1
  273. package/dist/server/server.d.ts.map +1 -1
  274. package/dist/server/server.js +2 -3
  275. package/dist/server/server.js.map +1 -1
  276. package/dist/server/sqlite-store.d.ts.map +1 -1
  277. package/dist/server/sqlite-store.js +4 -14
  278. package/dist/server/sqlite-store.js.map +1 -1
  279. package/dist/severity-store.js +8 -15
  280. package/dist/severity-store.js.map +1 -1
  281. package/dist/suggest-owners.d.ts +2 -3
  282. package/dist/suggest-owners.d.ts.map +1 -1
  283. package/dist/suggest-owners.js +4 -5
  284. package/dist/suggest-owners.js.map +1 -1
  285. package/dist/targets.d.ts +1 -0
  286. package/dist/targets.d.ts.map +1 -1
  287. package/dist/targets.js +24 -21
  288. package/dist/targets.js.map +1 -1
  289. package/dist/trusted-executable.d.ts +5 -0
  290. package/dist/trusted-executable.d.ts.map +1 -1
  291. package/dist/trusted-executable.js +22 -5
  292. package/dist/trusted-executable.js.map +1 -1
  293. package/dist/value.d.ts +2 -0
  294. package/dist/value.d.ts.map +1 -0
  295. package/dist/value.js +20 -0
  296. package/dist/value.js.map +1 -0
  297. package/dist/version.d.ts.map +1 -1
  298. package/dist/version.js +3 -6
  299. package/dist/version.js.map +1 -1
  300. package/dist/windows-path.d.ts.map +1 -1
  301. package/dist/windows-path.js +1 -2
  302. package/dist/windows-path.js.map +1 -1
  303. package/dist/worker-progress.d.ts +1 -0
  304. package/dist/worker-progress.d.ts.map +1 -1
  305. package/dist/worker-progress.js +13 -34
  306. package/dist/worker-progress.js.map +1 -1
  307. package/docs/dedupe-records.md +24 -0
  308. package/package.json +11 -10
  309. package/schemas/project-config.schema.json +5 -0
  310. package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
  311. package/dist/server/findings-service.d.ts +0 -20
  312. package/dist/server/findings-service.d.ts.map +0 -1
  313. package/dist/server/findings-service.js +0 -31
  314. package/dist/server/findings-service.js.map +0 -1
@@ -27,14 +27,18 @@ TEXT_CODE_EXTENSIONS = {
27
27
  ".cue",
28
28
  ".cxx",
29
29
  ".dart",
30
+ ".ejs",
31
+ ".erb",
30
32
  ".ex",
31
33
  ".exs",
32
34
  ".go",
33
35
  ".graphql",
34
36
  ".h",
37
+ ".hh",
35
38
  ".hpp",
36
39
  ".hs",
37
40
  ".html",
41
+ ".hxx",
38
42
  ".java",
39
43
  ".js",
40
44
  ".json",
@@ -47,6 +51,7 @@ TEXT_CODE_EXTENSIONS = {
47
51
  ".mm",
48
52
  ".mts",
49
53
  ".php",
54
+ ".phtml",
50
55
  ".proto",
51
56
  ".ps1",
52
57
  ".psd1",
@@ -56,20 +61,35 @@ TEXT_CODE_EXTENSIONS = {
56
61
  ".rs",
57
62
  ".scala",
58
63
  ".sh",
64
+ ".sol",
59
65
  ".sql",
66
+ ".svelte",
60
67
  ".swift",
61
68
  ".tf",
62
69
  ".toml",
63
70
  ".ts",
64
71
  ".tsx",
65
72
  ".vue",
73
+ ".vy",
66
74
  ".xml",
67
75
  ".yaml",
68
76
  ".yml",
69
77
  }
70
78
 
71
79
  JAVASCRIPT_EXTENSIONS = {".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx", ".vue"}
72
- JAVA_LIKE_EXTENSIONS = {".c", ".cc", ".cpp", ".cs", ".cxx", ".h", ".hpp", ".java", ".mm"}
80
+ JAVA_LIKE_EXTENSIONS = {
81
+ ".c",
82
+ ".cc",
83
+ ".cpp",
84
+ ".cs",
85
+ ".cxx",
86
+ ".h",
87
+ ".hh",
88
+ ".hpp",
89
+ ".hxx",
90
+ ".java",
91
+ ".mm",
92
+ }
73
93
  BRACE_LANGUAGE_EXTENSIONS = {
74
94
  *JAVASCRIPT_EXTENSIONS,
75
95
  *JAVA_LIKE_EXTENSIONS,
@@ -83,6 +103,7 @@ BRACE_LANGUAGE_EXTENSIONS = {
83
103
  ".swift",
84
104
  }
85
105
  NESTED_BLOCK_COMMENT_EXTENSIONS = {".kt", ".kts", ".rs", ".scala", ".swift"}
106
+ CPP_RAW_STRING_RE = re.compile(r'(?<![\w\x80-\U0010ffff])(?:u8|u|U|L)?R"([^\s()\\]{0,16})\(')
86
107
  RUST_RAW_STRING_RE = re.compile(r'(?:br|r)(#{0,16})"')
87
108
  RUST_LIFETIME_RE = re.compile(r"'[A-Za-z_][A-Za-z0-9_]*")
88
109
  PHP_HEREDOC_RE = re.compile(r"<<<\s*['\"]?([A-Za-z_]\w*)['\"]?")
@@ -184,7 +205,7 @@ def python_arguments(node: ast.FunctionDef | ast.AsyncFunctionDef) -> str:
184
205
  def python_outline(text: str) -> list[str]:
185
206
  try:
186
207
  tree = ast.parse(text)
187
- except (SyntaxError, ValueError, TypeError, MemoryError):
208
+ except (SyntaxError, ValueError, TypeError, MemoryError, RecursionError):
188
209
  return []
189
210
 
190
211
  outline: list[str] = []
@@ -284,13 +305,13 @@ def mask_c_style_source(text: str, suffix: str) -> str:
284
305
  continue
285
306
  if heredoc_terminator:
286
307
  if index == 0 or text[index - 1] == "\n":
287
- line_end = text.find("\n", index)
288
- if line_end < 0:
289
- line_end = len(text)
290
- candidate = text[index:line_end].strip().removesuffix(";")
291
- if candidate == heredoc_terminator:
292
- masked.extend(" " * (line_end - index))
293
- index = line_end
308
+ # PHP identifiers allow every non-ASCII byte, including non-word characters.
309
+ terminator_match = re.compile(
310
+ rf"[ \t]*{heredoc_terminator}(?![A-Za-z0-9_\x80-\U0010ffff])"
311
+ ).match(text, index)
312
+ if terminator_match:
313
+ masked.extend(" " * (terminator_match.end() - index))
314
+ index = terminator_match.end()
294
315
  heredoc_terminator = ""
295
316
  continue
296
317
  masked.append(" ")
@@ -338,6 +359,14 @@ def mask_c_style_source(text: str, suffix: str) -> str:
338
359
  quote = ""
339
360
  index += 1
340
361
  continue
362
+ if suffix in {".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}:
363
+ raw_match = CPP_RAW_STRING_RE.match(text, index)
364
+ if raw_match:
365
+ token = raw_match.group(0)
366
+ masked.extend(" " * len(token))
367
+ raw_terminator = f'){raw_match.group(1)}"'
368
+ index += len(token)
369
+ continue
341
370
  if suffix == ".rs":
342
371
  raw_match = RUST_RAW_STRING_RE.match(text, index)
343
372
  if raw_match:
@@ -360,6 +389,11 @@ def mask_c_style_source(text: str, suffix: str) -> str:
360
389
  quote = '@"'
361
390
  index += 2
362
391
  continue
392
+ if suffix == ".go" and char == "`":
393
+ masked.append(" ")
394
+ raw_terminator = "`"
395
+ index += 1
396
+ continue
363
397
  triple_quote = text[index : index + 3]
364
398
  if triple_quote in {'"""', "'''"}:
365
399
  masked.extend((" ", " ", " "))
@@ -457,7 +491,7 @@ def match_type_declaration(line: str, suffix: str) -> tuple[str, str] | None:
457
491
  match = re.search(r"\b(class|struct|enum|protocol|actor|extension)\s+([A-Za-z_]\w*)", line)
458
492
  elif suffix == ".dart":
459
493
  match = re.search(r"\b(class|mixin|enum|extension)\s+([A-Za-z_]\w*)", line)
460
- elif suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"}:
494
+ elif suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}:
461
495
  match = re.search(
462
496
  r"\b(class|struct|union|enum(?:\s+class)?)\s+([A-Za-z_]\w*)",
463
497
  line,
@@ -509,12 +543,20 @@ def match_java_like_function(
509
543
  prefix = before[: name_match.start()].strip()
510
544
  if not prefix and name != (type_name or ""):
511
545
  return None
512
- if suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"} and prefix.startswith(
513
- ("typedef", "using")
514
- ):
546
+ if suffix in {
547
+ ".c",
548
+ ".cc",
549
+ ".cpp",
550
+ ".cxx",
551
+ ".h",
552
+ ".hh",
553
+ ".hpp",
554
+ ".hxx",
555
+ ".mm",
556
+ } and prefix.startswith(("typedef", "using")):
515
557
  return None
516
558
  if (
517
- suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".mm"}
559
+ suffix in {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".mm"}
518
560
  and type_name is None
519
561
  and line.endswith(";")
520
562
  and not re.search(
@@ -652,8 +694,7 @@ def strip_leading_annotations(original: str, masked: str) -> tuple[str, str, lis
652
694
  def brace_language_outline(text: str, suffix: str) -> list[str]:
653
695
  original_lines = text.splitlines()
654
696
  masked_lines = mask_c_style_source(text, suffix).splitlines()
655
- outline: list[str] = []
656
- seen: set[str] = set()
697
+ outline: dict[str, None] = {}
657
698
  type_stack: list[tuple[str, int]] = []
658
699
  function_depths: list[int] = []
659
700
  blocked_depths: list[int] = []
@@ -664,9 +705,7 @@ def brace_language_outline(text: str, suffix: str) -> list[str]:
664
705
 
665
706
  def add(value: str) -> None:
666
707
  decorated = f"{' '.join(pending_annotations[-2:])} {value}".strip()
667
- if decorated not in seen:
668
- seen.add(decorated)
669
- outline.append(decorated)
708
+ outline[decorated] = None
670
709
 
671
710
  def next_lines_open_body(line_index: int) -> bool:
672
711
  inspected = 0
@@ -778,20 +817,14 @@ def brace_language_outline(text: str, suffix: str) -> list[str]:
778
817
  type_stack.pop()
779
818
  while blocked_depths and depth < blocked_depths[-1]:
780
819
  blocked_depths.pop()
781
- return outline
820
+ return list(outline)
782
821
 
783
822
 
784
823
  def ruby_outline(text: str) -> list[str]:
785
- outline: list[str] = []
786
- seen: set[str] = set()
824
+ outline: dict[str, None] = {}
787
825
  type_stack: list[tuple[int, str]] = []
788
826
  function_indents: list[int] = []
789
827
 
790
- def add(value: str) -> None:
791
- if value not in seen:
792
- seen.add(value)
793
- outline.append(value)
794
-
795
828
  for raw_line in text.splitlines():
796
829
  stripped = raw_line.strip()
797
830
  if not stripped or stripped.startswith("#"):
@@ -805,7 +838,7 @@ def ruby_outline(text: str) -> list[str]:
805
838
  type_match = re.match(r"^(class|module)\s+([A-Z]\w*(?:::[A-Z]\w*)*)", stripped)
806
839
  if type_match and not function_indents:
807
840
  kind, name = type_match.groups()
808
- add(f"{kind} {name}")
841
+ outline[f"{kind} {name}"] = None
809
842
  type_stack.append((indent, name))
810
843
  continue
811
844
 
@@ -813,21 +846,15 @@ def ruby_outline(text: str) -> list[str]:
813
846
  if function_match and not function_indents:
814
847
  name = function_match.group(1)
815
848
  if type_stack:
816
- add(f"method {type_stack[-1][1]}.{name}")
849
+ outline[f"method {type_stack[-1][1]}.{name}"] = None
817
850
  else:
818
- add(f"function {name}")
851
+ outline[f"function {name}"] = None
819
852
  function_indents.append(indent)
820
- return outline
853
+ return list(outline)
821
854
 
822
855
 
823
856
  def simple_language_outline(text: str, suffix: str) -> list[str]:
824
- outline: list[str] = []
825
- seen: set[str] = set()
826
-
827
- def add(value: str) -> None:
828
- if value not in seen:
829
- seen.add(value)
830
- outline.append(value)
857
+ outline: dict[str, None] = {}
831
858
 
832
859
  for raw_line in text.splitlines():
833
860
  line = compact_preview_line(raw_line)
@@ -837,69 +864,63 @@ def simple_language_outline(text: str, suffix: str) -> list[str]:
837
864
  if suffix == ".py":
838
865
  match = re.match(r"^(async\s+)?def\s+([A-Za-z_]\w*)\s*\(", line)
839
866
  if match:
840
- add(f"{'async function' if match.group(1) else 'function'} {match.group(2)}")
867
+ outline[
868
+ f"{'async function' if match.group(1) else 'function'} {match.group(2)}"
869
+ ] = None
841
870
  continue
842
871
  match = re.match(r"^class\s+([A-Za-z_]\w*)", line)
843
872
  if match:
844
- add(f"class {match.group(1)}")
845
- elif suffix == ".rb":
846
- match = re.match(r"^(class|module)\s+([A-Z]\w*(?:::[A-Z]\w*)*)", line)
847
- if match:
848
- add(f"{match.group(1)} {match.group(2)}")
849
- continue
850
- match = re.match(r"^def\s+(?:self\.)?([^\s(]+)", line)
851
- if match:
852
- add(f"function {match.group(1)}")
873
+ outline[f"class {match.group(1)}"] = None
853
874
  elif suffix in {".ex", ".exs"}:
854
875
  match = re.match(r"^defmodule\s+([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)", line)
855
876
  if match:
856
- add(f"module {match.group(1)}")
877
+ outline[f"module {match.group(1)}"] = None
857
878
  continue
858
879
  match = re.match(r"^(?:def|defp|defmacro)\s+([A-Za-z_]\w*[!?]?)", line)
859
880
  if match:
860
- add(f"function {match.group(1)}")
881
+ outline[f"function {match.group(1)}"] = None
861
882
  elif suffix == ".clj":
862
883
  match = re.match(
863
884
  r"^\((defn|defmacro|defprotocol|defrecord|deftype|defmulti|defmethod)\s+([^\s)]+)",
864
885
  line,
865
886
  )
866
887
  if match:
867
- add(f"{match.group(1)} {match.group(2)}")
888
+ outline[f"{match.group(1)} {match.group(2)}"] = None
868
889
  elif suffix == ".lua":
869
890
  match = re.match(r"^(?:local\s+)?function\s+([A-Za-z_]\w*(?:[.:][A-Za-z_]\w*)*)", line)
870
891
  if match:
871
- add(f"function {match.group(1)}")
892
+ outline[f"function {match.group(1)}"] = None
872
893
  elif suffix == ".sh":
873
894
  match = re.match(r"^(?:function\s+)?([A-Za-z_]\w*)\s*\(\s*\)\s*\{?", line)
874
895
  if match:
875
- add(f"function {match.group(1)}")
896
+ outline[f"function {match.group(1)}"] = None
876
897
  elif suffix == ".hs":
877
898
  match = re.match(r"^(data|newtype|type|class)\s+([A-Z]\w*)", line)
878
899
  if match:
879
- add(f"{match.group(1)} {match.group(2)}")
900
+ outline[f"{match.group(1)} {match.group(2)}"] = None
880
901
  continue
881
902
  match = re.match(r"^([a-z_]\w*)\s*::", line)
882
903
  if match:
883
- add(f"function {match.group(1)}")
904
+ outline[f"function {match.group(1)}"] = None
884
905
  elif suffix == ".proto":
885
906
  match = re.match(r"^(message|service|enum)\s+([A-Za-z_]\w*)", line)
886
907
  if match:
887
- add(f"{match.group(1)} {match.group(2)}")
908
+ outline[f"{match.group(1)} {match.group(2)}"] = None
888
909
  continue
889
910
  match = re.match(r"^rpc\s+([A-Za-z_]\w*)\s*\(", line)
890
911
  if match:
891
- add(f"rpc {match.group(1)}")
912
+ outline[f"rpc {match.group(1)}"] = None
892
913
  elif suffix == ".graphql":
893
914
  match = re.match(
894
915
  r"^(type|interface|input|enum|union|scalar|directive)\s+([A-Za-z_]\w*)",
895
916
  line,
896
917
  )
897
918
  if match:
898
- add(f"{match.group(1)} {match.group(2)}")
919
+ outline[f"{match.group(1)} {match.group(2)}"] = None
899
920
  continue
900
921
  match = re.match(r"^(query|mutation|subscription)\s+([A-Za-z_]\w*)", line)
901
922
  if match:
902
- add(f"{match.group(1)} {match.group(2)}")
923
+ outline[f"{match.group(1)} {match.group(2)}"] = None
903
924
  elif suffix == ".sql":
904
925
  match = re.match(
905
926
  r"^CREATE\s+(?:OR\s+REPLACE\s+)?(FUNCTION|PROCEDURE|TABLE|VIEW|TRIGGER)\s+"
@@ -908,16 +929,16 @@ def simple_language_outline(text: str, suffix: str) -> list[str]:
908
929
  flags=re.IGNORECASE,
909
930
  )
910
931
  if match:
911
- add(f"{match.group(1).lower()} {match.group(2)}")
932
+ outline[f"{match.group(1).lower()} {match.group(2)}"] = None
912
933
  elif suffix in {".yaml", ".yml"}:
913
934
  match = re.match(r"^([A-Za-z0-9_.-]+):(?:\s|$)", raw_line)
914
935
  if match:
915
- add(f"key {match.group(1)}")
936
+ outline[f"key {match.group(1)}"] = None
916
937
  elif suffix in {".toml", ".cfg"}:
917
938
  match = re.match(r"^\[([^]]+)]$", line)
918
939
  if match:
919
- add(f"section {match.group(1)}")
920
- return outline
940
+ outline[f"section {match.group(1)}"] = None
941
+ return list(outline)
921
942
 
922
943
 
923
944
  def json_outline(text: str) -> list[str]:
@@ -977,12 +998,8 @@ def preview_for_bytes(path: Path, data: bytes, preview_bytes: int) -> tuple[str,
977
998
  return fit_preview_lines(preview_lines, preview_bytes), False
978
999
 
979
1000
 
980
- def main() -> None:
1001
+ if __name__ == "__main__":
981
1002
  parser = argparse.ArgumentParser(
982
1003
  description="Build structural or sampled previews for Codex Security rank inputs."
983
1004
  )
984
1005
  parser.parse_args()
985
-
986
-
987
- if __name__ == "__main__":
988
- main()
@@ -32,18 +32,10 @@ def _text(value: Any, fallback: str) -> str:
32
32
  return ""
33
33
  if re.match(r"^(?:#{1,6}\s|[-*+]\s|>\s|```|\d+\.\s|\|)", normalized):
34
34
  normalized = f"Text: {normalized}"
35
- rendered: list[str] = []
36
- cursor = 0
37
- for match in re.finditer(r"(?<!`)`([^`\n]+)`(?!`)", normalized):
38
- rendered.append(_escape_markdown_text(normalized[cursor : match.start()]))
39
- rendered.append(f"`{match.group(1)}`")
40
- cursor = match.end()
41
- rendered.append(_escape_markdown_text(normalized[cursor:]))
42
- return "".join(rendered)
43
-
44
-
45
- def _escape_markdown_text(value: str) -> str:
46
- return re.sub(r"([\\`*\[\]<>])", r"\\\1", value)
35
+ return "".join(
36
+ part if index % 2 else re.sub(r"([\\`*\[\]<>])", r"\\\1", part)
37
+ for index, part in enumerate(re.split(r"((?<!`)`[^`\n]+`(?!`))", normalized))
38
+ )
47
39
 
48
40
 
49
41
  def _strings(value: Any) -> list[str]:
@@ -63,10 +55,6 @@ def _cell(value: Any) -> str:
63
55
  return _text(value, "none").replace("|", "\\|").replace("\n", "<br>")
64
56
 
65
57
 
66
- def _link_label(value: Any, fallback: str) -> str:
67
- return _cell(value) or _cell(fallback)
68
-
69
-
70
58
  def _deep_report_id(finding: dict[str, Any]) -> str:
71
59
  extensions = finding.get("extensions")
72
60
  if isinstance(extensions, dict):
@@ -141,10 +129,6 @@ def _deep_title_parts(finding: dict[str, Any]) -> tuple[str, str | None]:
141
129
  return normalized, None
142
130
 
143
131
 
144
- def _deep_finding_title(finding: dict[str, Any]) -> str:
145
- return _deep_title_parts(finding)[0]
146
-
147
-
148
132
  def _deep_finding_groups(
149
133
  findings: list[dict[str, Any]], writeup_paths: list[str | None]
150
134
  ) -> list[list[tuple[int, dict[str, Any], str | None]]]:
@@ -155,12 +139,9 @@ def _deep_finding_groups(
155
139
 
156
140
 
157
141
  def _deep_group_titles(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
158
- titles: list[str] = []
159
- for _, finding, _ in group:
160
- title = _cell(_deep_finding_title(finding))
161
- if title not in titles:
162
- titles.append(title)
163
- return "<br>".join(titles)
142
+ return "<br>".join(
143
+ dict.fromkeys(_cell(_deep_title_parts(finding)[0]) for _, finding, _ in group)
144
+ )
164
145
 
165
146
 
166
147
  def _deep_group_levels(
@@ -197,7 +178,7 @@ def _deep_group_report_labels(
197
178
  def _deep_group_report_links(group: list[tuple[int, dict[str, Any], str | None]]) -> str:
198
179
  labels = _deep_group_report_labels(group)
199
180
  return "<br>".join(
200
- f"[{_link_label(label, 'Unidentified report')}](#finding-{number})"
181
+ f"[{_cell(label)}](#finding-{number})"
201
182
  for label, (number, _, _) in zip(labels, group, strict=True)
202
183
  )
203
184
 
@@ -206,7 +187,7 @@ def _deep_group_writeup_links(group: list[tuple[int, dict[str, Any], str | None]
206
187
  labels = _deep_group_report_labels(group)
207
188
  links: list[str] = []
208
189
  for label, (_, _, report_path) in zip(labels, group, strict=True):
209
- report_id = _link_label(label, "Unidentified report")
190
+ report_id = _cell(label)
210
191
  links.append(
211
192
  f"[Open {report_id}]({report_path})" if report_path else f"{report_id}: inline below"
212
193
  )
@@ -282,15 +263,11 @@ def _section_code_evidence(
282
263
  and isinstance(item.get("code"), str)
283
264
  and item["code"].strip()
284
265
  )
285
- unique: list[dict[str, Any]] = []
286
- seen: set[tuple[str, str]] = set()
266
+ unique: dict[tuple[str, str], dict[str, Any]] = {}
287
267
  for item in resolved:
288
268
  key = (str(item.get("id", "")), item["code"])
289
- if key in seen:
290
- continue
291
- seen.add(key)
292
- unique.append(item)
293
- return unique
269
+ unique.setdefault(key, item)
270
+ return list(unique.values())
294
271
 
295
272
 
296
273
  def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
@@ -867,26 +844,32 @@ def build_report_markdown(
867
844
  "",
868
845
  "## Threat Model",
869
846
  "",
847
+ ]
848
+ )
849
+ content = threat_model.get("content")
850
+ if threat_model.get("format") == "markdown" and isinstance(content, str) and content.strip():
851
+ lines.append(content)
852
+ else:
853
+ lines.append(
870
854
  _text(
871
855
  threat_model.get("summary"),
872
856
  "No explicit canonical threat-model summary was recorded.",
857
+ )
858
+ )
859
+ for heading, key, fallback in (
860
+ ("Assets", "assets", "No assets were recorded."),
861
+ ("Trust Boundaries", "trustBoundaries", "No trust boundaries were recorded."),
862
+ (
863
+ "Attacker Capabilities",
864
+ "attackerCapabilities",
865
+ "No attacker capabilities were recorded.",
873
866
  ),
874
- ]
875
- )
876
- for heading, key, fallback in (
877
- ("Assets", "assets", "No assets were recorded."),
878
- ("Trust Boundaries", "trustBoundaries", "No trust boundaries were recorded."),
879
- (
880
- "Attacker Capabilities",
881
- "attackerCapabilities",
882
- "No attacker capabilities were recorded.",
883
- ),
884
- ("Security Objectives", "securityObjectives", "No security objectives were recorded."),
885
- ("Assumptions", "assumptions", "No assumptions were recorded."),
886
- ):
887
- values = _strings(threat_model.get(key))
888
- if values:
889
- lines.extend(["", f"### {heading}", "", *_bullets(values, fallback)])
867
+ ("Security Objectives", "securityObjectives", "No security objectives were recorded."),
868
+ ("Assumptions", "assumptions", "No assumptions were recorded."),
869
+ ):
870
+ values = _strings(threat_model.get(key))
871
+ if values:
872
+ lines.extend(["", f"### {heading}", "", *_bullets(values, fallback)])
890
873
  lines.extend(["", "## Findings", ""])
891
874
  if findings:
892
875
  if deep_presentation:
@@ -913,7 +896,7 @@ def build_report_markdown(
913
896
  for number, (finding, report_path) in enumerate(
914
897
  zip(findings, writeup_paths, strict=True), 1
915
898
  ):
916
- title = _link_label(finding["title"], "Untitled finding")
899
+ title = _cell(finding["title"])
917
900
  finding_link = f"[{title}](#finding-{number})"
918
901
  writeup_link = f"[Open report]({report_path})" if report_path else "inline below"
919
902
  lines.append(
@@ -1078,11 +1061,7 @@ def generate_report_markdown(
1078
1061
  return build_report_markdown(manifest, findings, coverage).encode("utf-8")
1079
1062
 
1080
1063
 
1081
- def main() -> int:
1064
+ if __name__ == "__main__":
1082
1065
  parser = argparse.ArgumentParser(description=__doc__)
1083
1066
  parser.parse_args()
1084
- return 0
1085
-
1086
-
1087
- if __name__ == "__main__":
1088
- raise SystemExit(main())
1067
+ raise SystemExit(0)