@openai/codex-security 0.1.10 → 0.1.12

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 (99) hide show
  1. package/README.md +72 -41
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +5 -1
  4. package/_bundled_plugin/examples/completed-scan/coverage.json +1 -1
  5. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +2 -2
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/preflight/capability-profiles.toml +1 -34
  9. package/_bundled_plugin/references/config-preflight.md +11 -13
  10. package/_bundled_plugin/references/core-scan.md +94 -0
  11. package/_bundled_plugin/references/final-report.md +6 -6
  12. package/_bundled_plugin/references/scan-artifacts.md +15 -14
  13. package/_bundled_plugin/references/scan-prologue.md +27 -0
  14. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +1 -106
  15. package/_bundled_plugin/scripts/config_preflight.py +40 -3
  16. package/_bundled_plugin/scripts/deep_scan_config.py +29 -6
  17. package/_bundled_plugin/scripts/deep_scan_workbench.py +132 -34
  18. package/_bundled_plugin/scripts/finalize_scan_contract.py +44 -224
  19. package/_bundled_plugin/scripts/finding_preview.py +122 -6
  20. package/_bundled_plugin/scripts/generate_in_scope_files.py +77 -31
  21. package/_bundled_plugin/scripts/generate_rank_input.py +58 -7
  22. package/_bundled_plugin/scripts/normalize_candidates.py +5 -5
  23. package/_bundled_plugin/scripts/rank_preview.py +4 -0
  24. package/_bundled_plugin/scripts/report_projection.py +40 -20
  25. package/_bundled_plugin/scripts/workbench_cli.py +5 -0
  26. package/_bundled_plugin/scripts/workbench_db.py +304 -32
  27. package/_bundled_plugin/scripts/workbench_progress.py +0 -5
  28. package/_bundled_plugin/scripts/workbench_scan_usage.py +43 -8
  29. package/_bundled_plugin/scripts/workbench_schema.py +16 -20
  30. package/_bundled_plugin/scripts/workbench_source_excerpt.py +1 -5
  31. package/_bundled_plugin/scripts/workbench_target.py +82 -0
  32. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +8 -11
  33. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +24 -108
  34. package/_bundled_plugin/skills/security-scan/SKILL.md +5 -88
  35. package/_bundled_plugin/skills/threat-model/SKILL.md +4 -2
  36. package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
  37. package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -6
  38. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +6 -7
  39. package/_bundled_plugin/skills/validation/SKILL.md +9 -12
  40. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +3 -2
  41. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +1 -1
  42. package/dist/api.d.ts +2 -0
  43. package/dist/api.d.ts.map +1 -1
  44. package/dist/api.js +393 -145
  45. package/dist/api.js.map +1 -1
  46. package/dist/auth.d.ts +2 -3
  47. package/dist/auth.d.ts.map +1 -1
  48. package/dist/auth.js +59 -270
  49. package/dist/auth.js.map +1 -1
  50. package/dist/bulk-scan-discovery.js +14 -2
  51. package/dist/bulk-scan-discovery.js.map +1 -1
  52. package/dist/cli.d.ts +6 -3
  53. package/dist/cli.d.ts.map +1 -1
  54. package/dist/cli.js +202 -46
  55. package/dist/cli.js.map +1 -1
  56. package/dist/config.d.ts.map +1 -1
  57. package/dist/config.js +1 -0
  58. package/dist/config.js.map +1 -1
  59. package/dist/contract.js +7 -5
  60. package/dist/contract.js.map +1 -1
  61. package/dist/cost.d.ts +1 -0
  62. package/dist/cost.d.ts.map +1 -1
  63. package/dist/cost.js +33 -2
  64. package/dist/cost.js.map +1 -1
  65. package/dist/knowledge-base.d.ts.map +1 -1
  66. package/dist/knowledge-base.js +12 -4
  67. package/dist/knowledge-base.js.map +1 -1
  68. package/dist/multiscan.d.ts +1 -0
  69. package/dist/multiscan.d.ts.map +1 -1
  70. package/dist/multiscan.js +77 -17
  71. package/dist/multiscan.js.map +1 -1
  72. package/dist/runtime.d.ts +9 -6
  73. package/dist/runtime.d.ts.map +1 -1
  74. package/dist/runtime.js +140 -326
  75. package/dist/runtime.js.map +1 -1
  76. package/dist/scan-comparison.js +1 -1
  77. package/dist/scan-comparison.js.map +1 -1
  78. package/dist/scan-dashboard.d.ts +5 -1
  79. package/dist/scan-dashboard.d.ts.map +1 -1
  80. package/dist/scan-dashboard.js +65 -16
  81. package/dist/scan-dashboard.js.map +1 -1
  82. package/dist/scan-logs.d.ts +2 -0
  83. package/dist/scan-logs.d.ts.map +1 -1
  84. package/dist/scan-logs.js +97 -37
  85. package/dist/scan-logs.js.map +1 -1
  86. package/dist/targets.d.ts +1 -0
  87. package/dist/targets.d.ts.map +1 -1
  88. package/dist/targets.js +35 -4
  89. package/dist/targets.js.map +1 -1
  90. package/dist/trusted-executable.js +1 -1
  91. package/dist/trusted-executable.js.map +1 -1
  92. package/dist/version.d.ts +3 -3
  93. package/dist/version.d.ts.map +1 -1
  94. package/dist/version.js +6 -4
  95. package/dist/version.js.map +1 -1
  96. package/package.json +4 -4
  97. package/_bundled_plugin/references/shared-hard-rules.md +0 -15
  98. package/_bundled_plugin/scripts/validate_report_format.py +0 -138
  99. package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +0 -33
@@ -17,6 +17,7 @@ from typing import Any, Callable
17
17
  sys.path.insert(0, str(Path(__file__).resolve().parent))
18
18
  from deep_scan_config import resolve_deep_scan_config
19
19
  from filesystem_identity import serialize_filesystem_identity
20
+ from finalize_scan_contract import _read_scan_local_json
20
21
  from workbench.handoff import require_current_continuation
21
22
  from workbench_target import (
22
23
  directory_content_digest,
@@ -217,6 +218,11 @@ def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlit
217
218
  return row
218
219
 
219
220
 
221
+ def deep_scan_deadline_reached(run: sqlite3.Row) -> bool:
222
+ elapsed = datetime.fromisoformat(now()) - datetime.fromisoformat(str(run["created_at"]))
223
+ return elapsed.total_seconds() / 3600 >= run["max_time_hours"]
224
+
225
+
220
226
  def require_deep_scan_ready_for_parent_completion(
221
227
  connection: sqlite3.Connection, scan: sqlite3.Row
222
228
  ) -> None:
@@ -353,14 +359,25 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A
353
359
  """,
354
360
  (run["scan_id"],),
355
361
  )
356
- successful_reducer = connection.execute(
357
- """
358
- SELECT 1 FROM deep_scan_workers
359
- WHERE scan_id = ? AND kind = 'dedup' AND status = 'succeeded'
360
- LIMIT 1
361
- """,
362
- (run["scan_id"],),
363
- ).fetchone()
362
+ canonical_artifacts = None
363
+ if (
364
+ run["canonical_inventory_path"] is None
365
+ and run["status"] == "succeeded"
366
+ and run["manifest_path"] is not None
367
+ and run["manifest_path"] != str(Path(scan["scan_dir"]) / "scan-manifest.json")
368
+ and (Path(scan["scan_dir"]) / "artifacts" / "02_discovery" / "in_scope_files.txt").exists()
369
+ ):
370
+ canonical_artifacts = canonical_discovery_artifacts(scan)
371
+ if (
372
+ run["terminal_reason"] == "capped"
373
+ and run["completion_sequence"] == 0
374
+ and deep_scan_deadline_reached(run)
375
+ and Path(canonical_artifacts["candidateLedgerPath"]).stat().st_size != 0
376
+ ):
377
+ raise SystemExit(
378
+ "A capped Deep Scan without completed discoveries requires an empty "
379
+ "candidate ledger."
380
+ )
364
381
  return {
365
382
  "scanId": run["scan_id"],
366
383
  "targetPath": scan["target_path"],
@@ -378,17 +395,14 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A
378
395
  "stopAfterNoNew": run["stop_after_no_new"],
379
396
  "stopAfterConsecutiveErrors": run["stop_after_consecutive_errors"],
380
397
  "maxDiscoveryRuns": run["max_discovery_runs"],
398
+ "maxTimeHours": run["max_time_hours"],
381
399
  },
382
400
  "dispatchedCount": run["discovery_runs_dispatched"],
383
401
  "completionSequence": run["completion_sequence"],
384
402
  "noNewStreak": run["consecutive_no_new"],
385
403
  "consecutiveErrors": run["consecutive_errors"],
386
404
  "cancelRequested": bool(run["cancel_requested"]),
387
- "canonicalArtifacts": (
388
- canonical_discovery_artifacts(scan)
389
- if successful_reducer is not None and run["canonical_inventory_path"] is None
390
- else None
391
- ),
405
+ "canonicalArtifacts": canonical_artifacts,
392
406
  "manifestPath": run["manifest_path"],
393
407
  "terminalReason": run["terminal_reason"],
394
408
  "error": run["error_message"],
@@ -466,7 +480,7 @@ def deep_scan_result(
466
480
  return result
467
481
 
468
482
 
469
- def effective_deep_scan_config(args: argparse.Namespace) -> dict[str, int]:
483
+ def effective_deep_scan_config(args: argparse.Namespace) -> dict[str, int | float]:
470
484
  available_parallelism = args.available_parallelism or os.cpu_count() or 1
471
485
  return resolve_deep_scan_config(available_parallelism)
472
486
 
@@ -474,7 +488,7 @@ def effective_deep_scan_config(args: argparse.Namespace) -> dict[str, int]:
474
488
  def ensure_deep_scan_run(
475
489
  connection: sqlite3.Connection,
476
490
  scan: sqlite3.Row,
477
- config: dict[str, int],
491
+ config: dict[str, int | float],
478
492
  workflow_version: str,
479
493
  timestamp: str,
480
494
  ) -> sqlite3.Row:
@@ -492,9 +506,9 @@ def ensure_deep_scan_run(
492
506
  INSERT INTO deep_scan_runs (
493
507
  scan_id, schema_version, workflow_version, status, phase,
494
508
  workers, subagents, stop_after_no_new, stop_after_consecutive_errors,
495
- max_discovery_runs,
509
+ max_discovery_runs, max_time_hours,
496
510
  created_at, updated_at
497
- ) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?)
511
+ ) VALUES (?, 1, ?, 'running', 'setup', ?, ?, ?, ?, ?, ?, ?, ?)
498
512
  """,
499
513
  (
500
514
  scan["id"],
@@ -504,6 +518,7 @@ def ensure_deep_scan_run(
504
518
  config["stopAfterNoNew"],
505
519
  config["stopAfterConsecutiveErrors"],
506
520
  config["maxDiscoveryRuns"],
521
+ config["maxTimeHours"],
507
522
  timestamp,
508
523
  timestamp,
509
524
  ),
@@ -1404,9 +1419,12 @@ def claim_deep_scan_dedup(
1404
1419
  "A Deep Scan dedup worker must claim an ordered prefix of buffered discovery "
1405
1420
  "results in completion order."
1406
1421
  )
1407
- hard_cap_singleton = (
1422
+ capped_singleton = (
1408
1423
  len(input_ids) == 1
1409
- and run["discovery_runs_dispatched"] >= run["max_discovery_runs"]
1424
+ and (
1425
+ run["discovery_runs_dispatched"] >= run["max_discovery_runs"]
1426
+ or deep_scan_deadline_reached(run)
1427
+ )
1410
1428
  and connection.execute(
1411
1429
  """
1412
1430
  SELECT 1 FROM deep_scan_workers
@@ -1425,7 +1443,7 @@ def claim_deep_scan_dedup(
1425
1443
  """,
1426
1444
  (scan_id,),
1427
1445
  ).fetchone()
1428
- minimum_inputs = 1 if successful_reducer is not None or hard_cap_singleton else 2
1446
+ minimum_inputs = 1 if successful_reducer is not None or capped_singleton else 2
1429
1447
  if len(input_ids) < minimum_inputs:
1430
1448
  raise SystemExit(
1431
1449
  "The first Deep Scan dedup requires two buffered discovery results."
@@ -1526,7 +1544,6 @@ def commit_deep_scan_dedup_locked(
1526
1544
  "Canonical candidate ledger path",
1527
1545
  )
1528
1546
  else:
1529
- canonical_discovery_artifacts(scan)
1530
1547
  candidate_ledger_path = None
1531
1548
  canonical_candidate_ledger_path = None
1532
1549
  result_manifest_path = deep_scan_path(
@@ -1634,6 +1651,65 @@ def finish_deep_scan_locked(
1634
1651
  scan, args.manifest_path, "Deep Scan coordinator manifest path", kind="file"
1635
1652
  )
1636
1653
  )
1654
+ standard_scan_manifest = manifest_path == str(Path(scan["scan_dir"]) / "scan-manifest.json")
1655
+
1656
+ failure_capped = False
1657
+ if (
1658
+ standard_scan_manifest
1659
+ and args.terminal_reason == "capped"
1660
+ and (run["status"] == "running" or omitted_worker_ids)
1661
+ ):
1662
+ for artifact_name in ("scan-manifest.json", "findings.json", "coverage.json"):
1663
+ deep_scan_path(
1664
+ scan,
1665
+ str(Path(scan["scan_dir"]) / artifact_name),
1666
+ f"Canonical parent {artifact_name}",
1667
+ kind="file",
1668
+ )
1669
+ coverage = _read_scan_local_json(
1670
+ Path(scan["scan_dir"]), "coverage.json", "Canonical parent coverage.json"
1671
+ )
1672
+ deferred = coverage.get("deferred")
1673
+ failure_capped = (
1674
+ coverage.get("completeness") == "partial"
1675
+ and isinstance(deferred, list)
1676
+ and any(
1677
+ isinstance(item, dict)
1678
+ and isinstance(item.get("reason"), str)
1679
+ and item["reason"].startswith("Deep Scan stopped before completion: ")
1680
+ for item in deferred
1681
+ )
1682
+ and connection.execute(
1683
+ """
1684
+ SELECT 1 FROM deep_scan_workers
1685
+ WHERE scan_id = ? AND kind = 'dedup' AND status = 'succeeded'
1686
+ LIMIT 1
1687
+ """,
1688
+ (scan_id,),
1689
+ ).fetchone()
1690
+ is not None
1691
+ )
1692
+ if failure_capped and run["status"] == "running":
1693
+ require_running_deep_scan(connection, scan_id)
1694
+ connection.execute(
1695
+ """
1696
+ UPDATE deep_scan_workers
1697
+ SET merge_state = 'buffered', updated_at = ?
1698
+ WHERE scan_id = ? AND kind = 'discovery' AND status = 'succeeded'
1699
+ AND merge_state = 'merging'
1700
+ AND id IN (
1701
+ SELECT inputs.discovery_worker_id
1702
+ FROM deep_scan_dedup_inputs AS inputs
1703
+ JOIN deep_scan_workers AS reducers
1704
+ ON reducers.id = inputs.dedup_worker_id
1705
+ AND reducers.scan_id = inputs.scan_id
1706
+ WHERE inputs.scan_id = ?
1707
+ AND reducers.kind = 'dedup'
1708
+ AND reducers.status IN ('failed', 'canceled')
1709
+ )
1710
+ """,
1711
+ (now(), scan_id, scan_id),
1712
+ )
1637
1713
  buffered_worker_ids = [
1638
1714
  row["id"]
1639
1715
  for row in connection.execute(
@@ -1648,7 +1724,7 @@ def finish_deep_scan_locked(
1648
1724
  ]
1649
1725
  omissions_match = (
1650
1726
  set(omitted_worker_ids) == set(buffered_worker_ids)
1651
- if args.terminal_reason == "saturated"
1727
+ if args.terminal_reason == "saturated" or failure_capped
1652
1728
  else not omitted_worker_ids and not buffered_worker_ids
1653
1729
  )
1654
1730
  if run["status"] == "succeeded":
@@ -1679,16 +1755,28 @@ def finish_deep_scan_locked(
1679
1755
  if (
1680
1756
  args.terminal_reason == "capped"
1681
1757
  and run["discovery_runs_dispatched"] < run["max_discovery_runs"]
1758
+ and not deep_scan_deadline_reached(run)
1759
+ and not failure_capped
1682
1760
  ):
1683
1761
  raise SystemExit(
1684
1762
  "Deep Scan cannot finish capped before reaching its configured maximum."
1685
1763
  )
1686
- try:
1687
- canonical_discovery_artifacts(scan)
1688
- except SystemExit as exc:
1689
- raise SystemExit(
1690
- f"Deep Scan cannot finish without canonical discovery artifacts: {exc}"
1691
- ) from exc
1764
+ canonical_artifacts = None
1765
+ if standard_scan_manifest:
1766
+ for artifact_name in ("scan-manifest.json", "findings.json", "coverage.json"):
1767
+ deep_scan_path(
1768
+ scan,
1769
+ str(Path(scan["scan_dir"]) / artifact_name),
1770
+ f"Canonical parent {artifact_name}",
1771
+ kind="file",
1772
+ )
1773
+ else:
1774
+ try:
1775
+ canonical_artifacts = canonical_discovery_artifacts(scan)
1776
+ except SystemExit as exc:
1777
+ raise SystemExit(
1778
+ f"Deep Scan cannot finish without canonical discovery artifacts: {exc}"
1779
+ ) from exc
1692
1780
  successful_reducer = connection.execute(
1693
1781
  """
1694
1782
  SELECT 1 FROM deep_scan_workers
@@ -1697,7 +1785,17 @@ def finish_deep_scan_locked(
1697
1785
  """,
1698
1786
  (scan_id,),
1699
1787
  ).fetchone()
1700
- if successful_reducer is None:
1788
+ zero_discovery_deadline = (
1789
+ args.terminal_reason == "capped"
1790
+ and deep_scan_deadline_reached(run)
1791
+ and run["completion_sequence"] == 0
1792
+ and (
1793
+ standard_scan_manifest
1794
+ or canonical_artifacts is not None
1795
+ and Path(canonical_artifacts["candidateLedgerPath"]).stat().st_size == 0
1796
+ )
1797
+ )
1798
+ if successful_reducer is None and not zero_discovery_deadline:
1701
1799
  raise SystemExit("Deep Scan cannot finish without a successful dedup worker.")
1702
1800
  failed_worker = connection.execute(
1703
1801
  """
@@ -1730,7 +1828,7 @@ def finish_deep_scan_locked(
1730
1828
  """,
1731
1829
  (scan_id,),
1732
1830
  ).fetchone()
1733
- if failed_worker is not None:
1831
+ if failed_worker is not None and not failure_capped:
1734
1832
  raise SystemExit("Deep Scan cannot finish after a worker has failed.")
1735
1833
  active_worker = connection.execute(
1736
1834
  """
@@ -1752,15 +1850,15 @@ def finish_deep_scan_locked(
1752
1850
  ).fetchone()
1753
1851
  if merging_worker is not None:
1754
1852
  raise SystemExit("Deep Scan cannot finish while discovery output is merging.")
1755
- if args.terminal_reason == "capped" and omitted_worker_ids:
1853
+ if args.terminal_reason == "capped" and omitted_worker_ids and not failure_capped:
1756
1854
  raise SystemExit("Deep Scan capped completion cannot declare omitted buffered workers.")
1757
- if args.terminal_reason == "capped" and buffered_worker_ids:
1855
+ if args.terminal_reason == "capped" and buffered_worker_ids and not failure_capped:
1758
1856
  raise SystemExit(
1759
1857
  "Deep Scan cannot finish capped while discovery output remains buffered."
1760
1858
  )
1761
- if args.terminal_reason == "saturated" and not omissions_match:
1859
+ if (args.terminal_reason == "saturated" or failure_capped) and not omissions_match:
1762
1860
  raise SystemExit(
1763
- "Deep Scan saturated completion must exactly identify all buffered discovery "
1861
+ f"Deep Scan {args.terminal_reason} completion must exactly identify all buffered discovery "
1764
1862
  "workers with --omitted-worker-id."
1765
1863
  )
1766
1864
  if args.staged_manifest_path: