@openai/codex-security 0.1.23 → 0.1.25

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 (135) hide show
  1. package/README.md +200 -23
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/references/scan-contract.md +10 -0
  7. package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
  8. package/_bundled_plugin/scripts/finalize_scan_contract.py +27 -78
  9. package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -8
  10. package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
  11. package/_bundled_plugin/scripts/rank_preview.py +12 -1
  12. package/_bundled_plugin/scripts/report_projection.py +8 -14
  13. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
  14. package/_bundled_plugin/scripts/windows_scan_local_files.py +5 -15
  15. package/_bundled_plugin/scripts/workbench_cli.py +14 -1
  16. package/_bundled_plugin/scripts/workbench_dashboard.py +41 -18
  17. package/_bundled_plugin/scripts/workbench_db.py +127 -541
  18. package/_bundled_plugin/scripts/workbench_finding_workflows.py +31 -13
  19. package/_bundled_plugin/scripts/workbench_findings.py +8 -3
  20. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
  21. package/_bundled_plugin/scripts/workbench_publication.py +520 -0
  22. package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
  23. package/_bundled_plugin/scripts/workbench_saved_results.py +298 -90
  24. package/_bundled_plugin/scripts/workbench_scan_history.py +375 -68
  25. package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
  26. package/_bundled_plugin/scripts/workbench_schema.py +49 -21
  27. package/_bundled_plugin/scripts/workbench_target.py +96 -17
  28. package/_bundled_plugin/scripts/workbench_validation.py +1 -5
  29. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
  30. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
  31. package/dist/api.d.ts +18 -3
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +350 -28
  34. package/dist/api.js.map +1 -1
  35. package/dist/auth.d.ts.map +1 -1
  36. package/dist/auth.js +35 -3
  37. package/dist/auth.js.map +1 -1
  38. package/dist/cli.d.ts +2 -0
  39. package/dist/cli.d.ts.map +1 -1
  40. package/dist/cli.js +118 -35
  41. package/dist/cli.js.map +1 -1
  42. package/dist/component-plan.d.ts.map +1 -1
  43. package/dist/component-plan.js +4 -2
  44. package/dist/component-plan.js.map +1 -1
  45. package/dist/component-scan.d.ts.map +1 -1
  46. package/dist/component-scan.js +21 -6
  47. package/dist/component-scan.js.map +1 -1
  48. package/dist/config.d.ts.map +1 -1
  49. package/dist/config.js +46 -2
  50. package/dist/config.js.map +1 -1
  51. package/dist/cost.d.ts +1 -0
  52. package/dist/cost.d.ts.map +1 -1
  53. package/dist/cost.js +23 -11
  54. package/dist/cost.js.map +1 -1
  55. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  56. package/dist/deduplication/checkpointed-review.js +2 -1
  57. package/dist/deduplication/checkpointed-review.js.map +1 -1
  58. package/dist/deduplication/codex-review.d.ts +3 -0
  59. package/dist/deduplication/codex-review.d.ts.map +1 -1
  60. package/dist/deduplication/codex-review.js +122 -36
  61. package/dist/deduplication/codex-review.js.map +1 -1
  62. package/dist/deduplication/deduplication-prompts.d.ts +4 -3
  63. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  64. package/dist/deduplication/deduplication-prompts.js +18 -9
  65. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  66. package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
  67. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  68. package/dist/deduplication/deduplication-reviewer.js +46 -24
  69. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  70. package/dist/deduplication/deduplication.d.ts.map +1 -1
  71. package/dist/deduplication/deduplication.js +186 -23
  72. package/dist/deduplication/deduplication.js.map +1 -1
  73. package/dist/deduplication/scan.d.ts +9 -1
  74. package/dist/deduplication/scan.d.ts.map +1 -1
  75. package/dist/deduplication/scan.js +24 -7
  76. package/dist/deduplication/scan.js.map +1 -1
  77. package/dist/deep-progress.d.ts +21 -0
  78. package/dist/deep-progress.d.ts.map +1 -0
  79. package/dist/deep-progress.js +108 -0
  80. package/dist/deep-progress.js.map +1 -0
  81. package/dist/errors.d.ts +13 -0
  82. package/dist/errors.d.ts.map +1 -1
  83. package/dist/errors.js +7 -0
  84. package/dist/errors.js.map +1 -1
  85. package/dist/index.d.ts +6 -5
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +2 -2
  88. package/dist/index.js.map +1 -1
  89. package/dist/mock-scan.d.ts +4 -0
  90. package/dist/mock-scan.d.ts.map +1 -0
  91. package/dist/mock-scan.js +210 -0
  92. package/dist/mock-scan.js.map +1 -0
  93. package/dist/publish.d.ts.map +1 -1
  94. package/dist/publish.js +2 -2
  95. package/dist/publish.js.map +1 -1
  96. package/dist/runtime.d.ts +1 -0
  97. package/dist/runtime.d.ts.map +1 -1
  98. package/dist/runtime.js +54 -14
  99. package/dist/runtime.js.map +1 -1
  100. package/dist/scan-activity.d.ts.map +1 -1
  101. package/dist/scan-activity.js +12 -2
  102. package/dist/scan-activity.js.map +1 -1
  103. package/dist/scan-comparison.d.ts +11 -2
  104. package/dist/scan-comparison.d.ts.map +1 -1
  105. package/dist/scan-comparison.js +237 -39
  106. package/dist/scan-comparison.js.map +1 -1
  107. package/dist/scan-dashboard.d.ts +3 -1
  108. package/dist/scan-dashboard.d.ts.map +1 -1
  109. package/dist/scan-dashboard.js +70 -3
  110. package/dist/scan-dashboard.js.map +1 -1
  111. package/dist/scan-history-renderer.d.ts.map +1 -1
  112. package/dist/scan-history-renderer.js +21 -0
  113. package/dist/scan-history-renderer.js.map +1 -1
  114. package/dist/server/api.d.ts +6 -0
  115. package/dist/server/api.d.ts.map +1 -0
  116. package/dist/server/api.js +4 -0
  117. package/dist/server/api.js.map +1 -0
  118. package/dist/server/dashboard/app.css +1 -1
  119. package/dist/server/embeddings.d.ts +2 -1
  120. package/dist/server/embeddings.d.ts.map +1 -1
  121. package/dist/server/embeddings.js +8 -3
  122. package/dist/server/embeddings.js.map +1 -1
  123. package/dist/server/index.js +2 -28
  124. package/dist/server/index.js.map +1 -1
  125. package/dist/server/serve.d.ts +2 -0
  126. package/dist/server/serve.d.ts.map +1 -0
  127. package/dist/server/serve.js +28 -0
  128. package/dist/server/serve.js.map +1 -0
  129. package/dist/targets.d.ts.map +1 -1
  130. package/dist/targets.js +3 -5
  131. package/dist/targets.js.map +1 -1
  132. package/dist/version.d.ts +1 -1
  133. package/dist/version.js +1 -1
  134. package/dist/version.js.map +1 -1
  135. package/package.json +10 -5
@@ -21,11 +21,7 @@ def windows_stream_component(path: Path) -> str | None:
21
21
  if os.name != "nt":
22
22
  return None
23
23
  return next(
24
- (
25
- component
26
- for component in path.parts
27
- if component != path.anchor and ":" in component
28
- ),
24
+ (component for component in path.parts if component != path.anchor and ":" in component),
29
25
  None,
30
26
  )
31
27
 
@@ -49,9 +45,7 @@ def resolve_scope(repository: Path, value: str) -> str:
49
45
  requested = Path(value).expanduser()
50
46
  stream = windows_stream_component(requested)
51
47
  if stream is not None:
52
- raise InventoryError(
53
- f"--scope: NTFS alternate data streams are not supported: {stream}"
54
- )
48
+ raise InventoryError(f"--scope: NTFS alternate data streams are not supported: {stream}")
55
49
  scope = requested if requested.is_absolute() else repository / requested
56
50
  try:
57
51
  resolved = scope.resolve(strict=True)
@@ -299,11 +299,7 @@ def windows_stream_component(path: Path) -> str | None:
299
299
  if os.name != "nt":
300
300
  return None
301
301
  return next(
302
- (
303
- component
304
- for component in path.parts
305
- if component != path.anchor and ":" in component
306
- ),
302
+ (component for component in path.parts if component != path.anchor and ":" in component),
307
303
  None,
308
304
  )
309
305
 
@@ -11,6 +11,7 @@ from pathlib import Path
11
11
  DEFAULT_PREVIEW_BYTES = 1024
12
12
  PREVIEW_HEAD_LINES = 12
13
13
  PREVIEW_SAMPLE_LINES = 10
14
+ _UTF16_BOMS = (b"\xff\xfe", b"\xfe\xff")
14
15
 
15
16
  TEXT_CODE_EXTENSIONS = {
16
17
  ".c",
@@ -42,6 +43,9 @@ TEXT_CODE_EXTENSIONS = {
42
43
  ".mm",
43
44
  ".php",
44
45
  ".proto",
46
+ ".ps1",
47
+ ".psd1",
48
+ ".psm1",
45
49
  ".py",
46
50
  ".rb",
47
51
  ".rs",
@@ -78,7 +82,14 @@ RUST_LIFETIME_RE = re.compile(r"'[A-Za-z_][A-Za-z0-9_]*")
78
82
  PHP_HEREDOC_RE = re.compile(r"<<<\s*['\"]?([A-Za-z_]\w*)['\"]?")
79
83
 
80
84
 
85
+ def _decode_source(data: bytes) -> str:
86
+ encoding = "utf-16" if data.startswith(_UTF16_BOMS) else "utf-8"
87
+ return data.decode(encoding, errors="ignore")
88
+
89
+
81
90
  def is_binary_sample(data: bytes) -> bool:
91
+ if data.startswith(_UTF16_BOMS):
92
+ return "\0" in _decode_source(data)
82
93
  return b"\0" in data
83
94
 
84
95
 
@@ -955,7 +966,7 @@ def preview_for(
955
966
  def preview_for_bytes(path: Path, data: bytes, preview_bytes: int) -> tuple[str, bool]:
956
967
  if is_binary_sample(data):
957
968
  return "", True
958
- text = data.decode("utf-8", errors="ignore")
969
+ text = _decode_source(data)
959
970
  outline = structural_outline(path, text)
960
971
  preview_lines = select_preview_lines(outline or text.splitlines())
961
972
  return fit_preview_lines(preview_lines, preview_bytes), False
@@ -333,13 +333,13 @@ def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
333
333
  "language",
334
334
  ):
335
335
  continue
336
- if field in text_fields and (
337
- not isinstance(item, str) or not item.strip()
338
- ):
336
+ if field in text_fields and (not isinstance(item, str) or not item.strip()):
339
337
  continue
340
338
  current = merged.get(field)
341
- if field not in merged or current in (None, "", [], {}) or (
342
- isinstance(current, str) and not current.strip()
339
+ if (
340
+ field not in merged
341
+ or current in (None, "", [], {})
342
+ or (isinstance(current, str) and not current.strip())
343
343
  ):
344
344
  merged[field] = item
345
345
 
@@ -363,9 +363,7 @@ def merged_root_cause(value: dict[str, Any]) -> tuple[str | None, Any]:
363
363
  item
364
364
  for detail in details
365
365
  for field in ("codeEvidence", "code_evidence")
366
- for item in (
367
- detail.get(field, []) if isinstance(detail.get(field), list) else []
368
- )
366
+ for item in (detail.get(field, []) if isinstance(detail.get(field), list) else [])
369
367
  ]
370
368
  if embedded_evidence:
371
369
  merged["codeEvidence"] = embedded_evidence
@@ -541,9 +539,7 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
541
539
  (
542
540
  section[key]
543
541
  for section in dataflow_sections
544
- if key in section
545
- and isinstance(section[key], str)
546
- and section[key].strip()
542
+ if key in section and isinstance(section[key], str) and section[key].strip()
547
543
  ),
548
544
  None,
549
545
  )
@@ -652,9 +648,7 @@ def _finding_section(number: int, finding: dict[str, Any]) -> list[str]:
652
648
  if validation.get("method"):
653
649
  lines.extend(["", f"Validation method: {_text(validation['method'], 'not recorded')}"])
654
650
  if validation_outcomes:
655
- lines.extend(
656
- ["", *(f"- **{label}:** {value}" for label, value in validation_outcomes)]
657
- )
651
+ lines.extend(["", *(f"- **{label}:** {value}" for label, value in validation_outcomes)])
658
652
  lines.extend(_code_evidence_lines(validation_code_evidence))
659
653
  if validation_assertions:
660
654
  lines.extend(["", "Assertions:", *_bullets(validation_assertions, "None recorded.")])
@@ -64,9 +64,7 @@ def validate_contract(scan_dir: Path) -> dict[str, Any]:
64
64
  FINALIZER._validate_derived_finding_identities(manifest, findings)
65
65
  FINALIZER._validate_coverage(manifest, coverage, scan_dir)
66
66
  FINALIZER._validate_sealed_coverage_receipts(scan, coverage)
67
- FINALIZER.validate_against_schema(
68
- findings_for_validation, schema_dir / "findings.schema.json"
69
- )
67
+ FINALIZER.validate_against_schema(findings_for_validation, schema_dir / "findings.schema.json")
70
68
  FINALIZER.validate_against_schema(coverage, schema_dir / "coverage.schema.json")
71
69
  FINALIZER._require_scan_local_file(scan_dir, "report.md", "report.md")
72
70
  return {
@@ -410,13 +410,8 @@ def _locked_parent(
410
410
  _require_windows()
411
411
  parts = _validated_parts(relative_path)
412
412
  root_path, observed_root_identity = _canonical_scan_directory(scan_dir)
413
- if (
414
- expected_root_identity is not None
415
- and observed_root_identity != expected_root_identity
416
- ):
417
- raise _invalid_path(
418
- scan_dir, "scan directory changed after artifact restoration setup"
419
- )
413
+ if expected_root_identity is not None and observed_root_identity != expected_root_identity:
414
+ raise _invalid_path(scan_dir, "scan directory changed after artifact restoration setup")
420
415
  handles: list[_OwnedHandle] = []
421
416
  try:
422
417
  # Absolute-path Win32 calls remain safe only while every ancestor is
@@ -429,12 +424,9 @@ def _locked_parent(
429
424
  current_root = root_path.lstat()
430
425
  current_root_identity = (current_root.st_dev, current_root.st_ino)
431
426
  if current_root_identity != observed_root_identity or (
432
- expected_root_identity is not None
433
- and current_root_identity != expected_root_identity
427
+ expected_root_identity is not None and current_root_identity != expected_root_identity
434
428
  ):
435
- raise _invalid_path(
436
- scan_dir, "scan directory changed while it was being opened"
437
- )
429
+ raise _invalid_path(scan_dir, "scan directory changed while it was being opened")
438
430
  current_path = root_path
439
431
  for component in parts[:-1]:
440
432
  current_path /= component
@@ -596,9 +588,7 @@ def _existing_output_matches(path: Path, payload: bytes) -> bool:
596
588
  raw_handle = handle.detach()
597
589
  try:
598
590
  assert _msvcrt is not None
599
- descriptor = _msvcrt.open_osfhandle(
600
- raw_handle, os.O_RDONLY | os.O_BINARY
601
- )
591
+ descriptor = _msvcrt.open_osfhandle(raw_handle, os.O_RDONLY | os.O_BINARY)
602
592
  except BaseException:
603
593
  _close_handle(raw_handle)
604
594
  raise
@@ -160,6 +160,10 @@ def parse_args(description: str) -> argparse.Namespace:
160
160
  set_scan_thread.add_argument("--scan-id", required=True)
161
161
  set_scan_thread.add_argument("--thread-id", required=True)
162
162
 
163
+ set_scan_cost_limit = subparsers.add_parser("set-scan-cost-limit")
164
+ set_scan_cost_limit.add_argument("--scan-id", required=True)
165
+ set_scan_cost_limit.add_argument("--max-cost-usd", required=True, type=float)
166
+
163
167
  get_scan_recipe = subparsers.add_parser("get-scan-recipe")
164
168
  get_scan_recipe.add_argument("--scan-id", required=True)
165
169
 
@@ -169,7 +173,10 @@ def parse_args(description: str) -> argparse.Namespace:
169
173
  compare_scans.add_argument("--include-matching-inputs", action="store_true")
170
174
  compare_scans.add_argument("--require-matches", action="store_true")
171
175
 
172
- save_scan_comparison = subparsers.add_parser("save-scan-comparison")
176
+ save_scan_comparison = subparsers.add_parser(
177
+ "save-scan-comparison",
178
+ description="Comparison payload supports related findings.",
179
+ )
173
180
  save_scan_comparison.add_argument("--before-scan-id", required=True)
174
181
  save_scan_comparison.add_argument("--after-scan-id", required=True)
175
182
  matches = save_scan_comparison.add_mutually_exclusive_group(required=True)
@@ -247,6 +254,12 @@ def parse_args(description: str) -> argparse.Namespace:
247
254
  preserve_scan.add_argument("--claim-token")
248
255
  preserve_scan.add_argument("--coordinator-generation", type=positive_int)
249
256
 
257
+ recovery_help = "Validate and republish retained checkpoints for a failed, non-canceled scan."
258
+ recover_scan = subparsers.add_parser(
259
+ "recover-scan-results", help=recovery_help, description=recovery_help
260
+ )
261
+ recover_scan.add_argument("--scan-id", required=True, help="ID of the stopped scan to recover.")
262
+
250
263
  write_scan_draft = subparsers.add_parser("write-scan-draft")
251
264
  write_scan_draft.add_argument("--scan-id", required=True)
252
265
  write_scan_draft.add_argument("--draft-path", required=True)
@@ -12,7 +12,6 @@ from typing import Any
12
12
  sys.path.insert(0, str(Path(__file__).resolve().parent))
13
13
  from workbench_findings import list_dedupe_groups
14
14
 
15
-
16
15
  FINDING_RECORDS = """
17
16
  SELECT findings.id, json_extract(details_json, '$.title') AS title,
18
17
  COALESCE(repositories.ids, '[]') AS repositoryIds,
@@ -52,17 +51,24 @@ def detail(connection: sqlite3.Connection, view: str, selected: dict[str, Any])
52
51
  result: dict[str, Any] = {"item": selected}
53
52
  selected_id = selected["id"]
54
53
  if view == "findings":
55
- result["finding"] = json.loads(connection.execute(
56
- "SELECT details_json FROM findings WHERE id = ?", (selected_id,),
57
- ).fetchone()[0])
54
+ result["finding"] = json.loads(
55
+ connection.execute(
56
+ "SELECT details_json FROM findings WHERE id = ?",
57
+ (selected_id,),
58
+ ).fetchone()[0]
59
+ )
58
60
  result["groups"] = list_dedupe_groups(connection, selected_id)["groups"]
59
61
  else:
60
62
  result["group"] = {
61
- "groupId": selected_id, "createdAt": selected["createdAt"],
62
- "findingIds": [r[0] for r in connection.execute(
63
- "SELECT finding_id FROM finding_dedupe_group_members WHERE group_id = ? ORDER BY finding_id",
64
- (selected_id,),
65
- )],
63
+ "groupId": selected_id,
64
+ "createdAt": selected["createdAt"],
65
+ "findingIds": [
66
+ r[0]
67
+ for r in connection.execute(
68
+ "SELECT finding_id FROM finding_dedupe_group_members WHERE group_id = ? ORDER BY finding_id",
69
+ (selected_id,),
70
+ )
71
+ ],
66
72
  }
67
73
  return result
68
74
 
@@ -76,7 +82,11 @@ def dashboard(connection: sqlite3.Connection, query: dict[str, Any]) -> dict[str
76
82
  if query.get("query"):
77
83
  connection.create_function("casefold", 1, str.casefold, deterministic=True)
78
84
  columns = ["id", "title", "repositoryIds"]
79
- clauses.append("(" + " OR ".join(f"instr(casefold(COALESCE({c}, '')), casefold(?)) > 0" for c in columns) + ")")
85
+ clauses.append(
86
+ "("
87
+ + " OR ".join(f"instr(casefold(COALESCE({c}, '')), casefold(?)) > 0" for c in columns)
88
+ + ")"
89
+ )
80
90
  values.extend([query["query"]] * len(columns))
81
91
  if query.get("repository"):
82
92
  clauses.append("EXISTS (SELECT 1 FROM json_each(repositoryIds) WHERE value = ?)")
@@ -89,23 +99,36 @@ def dashboard(connection: sqlite3.Connection, query: dict[str, Any]) -> dict[str
89
99
  SELECT DISTINCT repository_id AS id, repository_id AS label
90
100
  FROM finding_repositories ORDER BY repository_id
91
101
  """).fetchall()
92
- total = connection.execute(f"SELECT COUNT(*) FROM ({records}) {where}", values).fetchone()[0]
102
+ total = connection.execute(f"SELECT COUNT(*) FROM ({records}) {where}", values).fetchone()[
103
+ 0
104
+ ]
93
105
  rows = connection.execute(
94
106
  f"SELECT * FROM ({records}) {where} ORDER BY {order} LIMIT ? OFFSET ?",
95
107
  (*values, query["limit"], query["offset"]),
96
108
  ).fetchall()
97
- selected = connection.execute(
98
- f"SELECT * FROM ({records}) WHERE id = ?", (query["id"],),
99
- ).fetchone() if query.get("id") else None
109
+ selected = (
110
+ connection.execute(
111
+ f"SELECT * FROM ({records}) WHERE id = ?",
112
+ (query["id"],),
113
+ ).fetchone()
114
+ if query.get("id")
115
+ else None
116
+ )
100
117
  next_offset = query["offset"] + len(rows)
101
118
  return {
102
119
  "overview": {
103
- "findings": connection.execute("SELECT COUNT(*) FROM findings WHERE details_json IS NOT NULL").fetchone()[0],
104
- "groups": connection.execute("SELECT COUNT(*) FROM finding_dedupe_groups").fetchone()[0],
120
+ "findings": connection.execute(
121
+ "SELECT COUNT(*) FROM findings WHERE details_json IS NOT NULL"
122
+ ).fetchone()[0],
123
+ "groups": connection.execute(
124
+ "SELECT COUNT(*) FROM finding_dedupe_groups"
125
+ ).fetchone()[0],
105
126
  },
106
127
  "repositories": [dict(row) for row in repositories],
107
- "items": [item(row) for row in rows], "total": total,
108
- "limit": query["limit"], "offset": query["offset"],
128
+ "items": [item(row) for row in rows],
129
+ "total": total,
130
+ "limit": query["limit"],
131
+ "offset": query["offset"],
109
132
  "nextOffset": next_offset if next_offset < total else None,
110
133
  "detail": detail(connection, view, item(selected)) if selected is not None else None,
111
134
  }