@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
@@ -4,6 +4,7 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
+ import os
7
8
  import subprocess
8
9
  import sys
9
10
  import tempfile
@@ -68,7 +69,18 @@ def resolve_output(value: str) -> Path:
68
69
 
69
70
  def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:
70
71
  """Atomically write the exact ripgrep inventory sorted as ``LC_ALL=C``."""
71
- command = ["rg", "--files", "--hidden", "--no-ignore", "--glob", "!.git/**", "--", scope]
72
+ command = [
73
+ "rg",
74
+ "--files",
75
+ "--hidden",
76
+ "--no-ignore",
77
+ "--path-separator",
78
+ "/",
79
+ "--glob",
80
+ "!.git/**",
81
+ "--",
82
+ scope,
83
+ ]
72
84
  with tempfile.TemporaryFile(mode="w+b") as inventory:
73
85
  try:
74
86
  result = subprocess.run(
@@ -94,6 +106,38 @@ def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:
94
106
  return write_inventory(output, rows)
95
107
 
96
108
 
109
+ def committed_changed_paths(repository: Path, base: str, head: str) -> list[tuple[Path, str]]:
110
+ result = subprocess.run(
111
+ [
112
+ "git",
113
+ "-C",
114
+ str(repository),
115
+ "diff",
116
+ "--raw",
117
+ "-z",
118
+ "--diff-filter=ACMRD",
119
+ f"{base}..{head}",
120
+ ],
121
+ capture_output=True,
122
+ check=True,
123
+ )
124
+ fields = result.stdout.split(b"\0")
125
+ changed: list[tuple[Path, str]] = []
126
+ index = 0
127
+ while index < len(fields) - 1:
128
+ metadata = fields[index].split()
129
+ status = chr(metadata[-1][0])
130
+ index += 1
131
+ if status in {"C", "R"}:
132
+ index += 1
133
+ path = os.fsdecode(fields[index])
134
+ index += 1
135
+ selected_mode = metadata[0].removeprefix(b":") if status == "D" else metadata[1]
136
+ if selected_mode != b"120000":
137
+ changed.append((repository / path, status))
138
+ return changed
139
+
140
+
97
141
  def generate_diff_in_scope_files(
98
142
  repository: Path,
99
143
  base: str,
@@ -103,50 +147,52 @@ def generate_diff_in_scope_files(
103
147
  ) -> int:
104
148
  """Reuse the existing diff selection without generating previews or duplicate worklists."""
105
149
  sys.path.insert(0, str(Path(__file__).resolve().parent))
106
- from generate_rank_input import git_changed_paths, path_is_excluded, run_git_changed_paths
150
+ from generate_rank_input import git_changed_paths, path_is_excluded
107
151
  from rank_preview import (
108
152
  DEFAULT_PREVIEW_BYTES,
109
153
  TEXT_CODE_EXTENSIONS,
110
154
  is_binary_sample,
111
155
  preview_for,
112
156
  )
157
+ from workbench_target import git_blob_bytes
113
158
 
114
159
  rows: list[bytes] = []
115
160
  try:
116
- if mode == "local-patch":
117
- changed = run_git_changed_paths(repository, [base])
118
- untracked = subprocess.run(
119
- ["git", "-C", str(repository), "ls-files", "--others", "--exclude-standard", "-z"],
120
- capture_output=True,
121
- text=True,
122
- check=True,
161
+ changed = (
162
+ committed_changed_paths(repository, base, head)
163
+ if mode == "revisions"
164
+ else git_changed_paths(repository, base, head, mode)
165
+ )
166
+ eligible = [
167
+ (path, status)
168
+ for path, status in changed
169
+ if not path_is_excluded(path.relative_to(repository))
170
+ and path.suffix.lower() in TEXT_CODE_EXTENSIONS
171
+ ]
172
+ revision_paths = [
173
+ path.relative_to(repository)
174
+ for path, status in eligible
175
+ if mode == "revisions" and status != "D"
176
+ ]
177
+ revision_blobs = dict(
178
+ zip(
179
+ revision_paths,
180
+ git_blob_bytes(
181
+ repository,
182
+ [f"{head}:{path.as_posix()}" for path in revision_paths],
183
+ ),
123
184
  )
124
- changed.extend(
125
- (repository / relative, "A")
126
- for relative in untracked.stdout.split("\0")
127
- if relative
128
- )
129
- else:
130
- changed = git_changed_paths(repository, base, head, mode)
185
+ )
131
186
 
132
- for path, status in changed:
187
+ for path, status in eligible:
133
188
  relative = path.relative_to(repository)
134
- if path_is_excluded(relative) or path.suffix.lower() not in TEXT_CODE_EXTENSIONS:
135
- continue
136
189
  if status != "D":
137
190
  if mode == "revisions":
138
- contents = subprocess.run(
139
- [
140
- "git",
141
- "-C",
142
- str(repository),
143
- "cat-file",
144
- "blob",
145
- f"{head}:{relative.as_posix()}",
146
- ],
147
- capture_output=True,
148
- check=True,
149
- ).stdout
191
+ contents = revision_blobs[relative]
192
+ if contents is None:
193
+ raise InventoryError(
194
+ f"could not read committed diff blob: {head}:{relative.as_posix()}"
195
+ )
150
196
  if is_binary_sample(contents):
151
197
  continue
152
198
  elif (
@@ -37,8 +37,13 @@ from pathlib import Path
37
37
 
38
38
  # Some plugin hosts launch Python with safe-path isolation enabled.
39
39
  sys.path.insert(0, str(Path(__file__).resolve().parent))
40
- from rank_preview import DEFAULT_PREVIEW_BYTES, TEXT_CODE_EXTENSIONS, preview_for
41
- from workbench_target import git_directory_snapshot_paths
40
+ from rank_preview import (
41
+ DEFAULT_PREVIEW_BYTES,
42
+ TEXT_CODE_EXTENSIONS,
43
+ preview_for,
44
+ preview_for_bytes,
45
+ )
46
+ from workbench_target import git_blob_bytes, git_directory_snapshot_paths
42
47
 
43
48
  EXCLUDED_DIRS = {
44
49
  ".cache",
@@ -641,8 +646,19 @@ def git_changed_paths(repo: Path, base: str, head: str, mode: str) -> list[tuple
641
646
  if mode == "local-patch":
642
647
  unstaged = run_git_changed_paths(repo, [base])
643
648
  staged = run_git_changed_paths(repo, ["--cached", base])
649
+ untracked = subprocess.run(
650
+ ["git", "-C", str(repo), "ls-files", "--others", "--exclude-standard", "-z"],
651
+ capture_output=True,
652
+ text=True,
653
+ check=True,
654
+ )
644
655
  combined = dict(staged)
645
656
  combined.update(unstaged)
657
+ combined.update(
658
+ (repo / relative, "A")
659
+ for relative in untracked.stdout.split("\0")
660
+ if relative
661
+ )
646
662
  return sorted(combined.items())
647
663
  raise SystemExit(f"Unknown diff mode: {mode}")
648
664
 
@@ -652,18 +668,53 @@ def make_diff_rank_input(args: argparse.Namespace) -> None:
652
668
  if not repo.is_dir():
653
669
  raise SystemExit(f"Repo path not found: {repo}")
654
670
 
671
+ changed = [
672
+ (path, status)
673
+ for path, status in git_changed_paths(repo, args.base, args.head, args.mode)
674
+ if not path_is_excluded(path.relative_to(repo))
675
+ and path.suffix.lower() in TEXT_CODE_EXTENSIONS
676
+ ]
677
+ revision_paths = [
678
+ path.relative_to(repo)
679
+ for path, status in changed
680
+ if args.mode == "revisions" and status != "D"
681
+ ]
682
+ revision_blobs = dict(
683
+ zip(
684
+ revision_paths,
685
+ git_blob_bytes(
686
+ repo,
687
+ [f"{args.head}:{path.as_posix()}" for path in revision_paths],
688
+ ),
689
+ )
690
+ )
691
+
655
692
  rows: list[JsonRow] = []
656
- for path, status in git_changed_paths(repo, args.base, args.head, args.mode):
693
+ for path, status in changed:
657
694
  rel = path.relative_to(repo)
658
- if path_is_excluded(rel) or path.suffix.lower() not in TEXT_CODE_EXTENSIONS:
659
- continue
660
695
 
661
696
  if status == "D":
662
697
  preview = ""
663
- elif path.is_file():
664
- preview, is_binary = preview_for(path, args.preview_bytes)
698
+ elif args.mode == "revisions":
699
+ content = revision_blobs[rel]
700
+ if content is None:
701
+ raise SystemExit(
702
+ f"Unable to read committed diff blob: {args.head}:{rel.as_posix()}"
703
+ )
704
+ preview, is_binary = preview_for_bytes(rel, content, args.preview_bytes)
665
705
  if is_binary:
666
706
  continue
707
+ elif path.is_symlink():
708
+ preview = ""
709
+ elif path.is_file():
710
+ try:
711
+ path.resolve(strict=True).relative_to(repo)
712
+ except (OSError, ValueError):
713
+ preview = ""
714
+ else:
715
+ preview, is_binary = preview_for(path, args.preview_bytes)
716
+ if is_binary:
717
+ continue
667
718
  else:
668
719
  preview = ""
669
720
  rows.append({"path": rel.as_posix(), "area": args.area, "preview": preview})
@@ -308,10 +308,6 @@ def main() -> None:
308
308
  raise ValueError(f"{source} row {number}: {error}") from error
309
309
  combined = combine(rows)
310
310
  output.parent.mkdir(parents=True, exist_ok=True)
311
- payload = "".join(
312
- json.dumps(row, ensure_ascii=False, separators=(",", ":"), sort_keys=True) + "\n"
313
- for row in combined
314
- )
315
311
  temporary: Path | None = None
316
312
  try:
317
313
  with tempfile.NamedTemporaryFile(
@@ -323,7 +319,11 @@ def main() -> None:
323
319
  delete=False,
324
320
  ) as handle:
325
321
  temporary = Path(handle.name)
326
- handle.write(payload)
322
+ for row in combined:
323
+ handle.write(
324
+ json.dumps(row, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
325
+ + "\n"
326
+ )
327
327
  temporary.replace(output)
328
328
  finally:
329
329
  if temporary is not None:
@@ -949,6 +949,10 @@ def preview_for(
949
949
  data = sample + remaining
950
950
  except OSError:
951
951
  return "", True
952
+ return preview_for_bytes(path, data, preview_bytes)
953
+
954
+
955
+ def preview_for_bytes(path: Path, data: bytes, preview_bytes: int) -> tuple[str, bool]:
952
956
  if is_binary_sample(data):
953
957
  return "", True
954
958
  text = data.decode("utf-8", errors="ignore")
@@ -4,11 +4,8 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
- import importlib.util
8
7
  import re
9
8
  from collections import Counter
10
- from pathlib import Path
11
- from types import ModuleType
12
9
  from typing import Any
13
10
 
14
11
  SEVERITY_ORDER = {"critical": 0, "high": 1, "medium": 2, "low": 3, "informational": 4}
@@ -28,16 +25,6 @@ class ReportProjectionError(ValueError):
28
25
  """Raised when a canonical scan cannot be projected into a valid report."""
29
26
 
30
27
 
31
- def _load_script(name: str) -> ModuleType:
32
- path = Path(__file__).resolve().parent / f"{name}.py"
33
- spec = importlib.util.spec_from_file_location(f"codex_security_{name}", path)
34
- if spec is None or spec.loader is None:
35
- raise ReportProjectionError(f"could not load report helper: {path}")
36
- module = importlib.util.module_from_spec(spec)
37
- spec.loader.exec_module(module)
38
- return module
39
-
40
-
41
28
  def _text(value: Any, fallback: str) -> str:
42
29
  candidate = value if isinstance(value, str) and value.strip() else fallback
43
30
  normalized = " ".join(candidate.split())
@@ -739,11 +726,49 @@ def build_report_markdown(
739
726
  else:
740
727
  lines.extend(["", *_finding_section(number, finding)])
741
728
  else:
729
+ deferred = coverage.get("deferred", [])
730
+ no_source_review = (
731
+ coverage.get("completeness") == "partial"
732
+ and isinstance(deferred, list)
733
+ and any(
734
+ isinstance(item, dict)
735
+ and item.get("reason")
736
+ == "The configured discovery time limit elapsed before any source review completed."
737
+ for item in deferred
738
+ )
739
+ )
740
+ budget_exhausted = (
741
+ coverage.get("completeness") == "partial"
742
+ and isinstance(deferred, list)
743
+ and any(
744
+ isinstance(item, dict)
745
+ and isinstance(item.get("reason"), str)
746
+ and (
747
+ item["reason"]
748
+ == "Validation was deferred because the scan reached its cost limit."
749
+ or item["reason"].startswith(
750
+ "Validation was deferred because the scan reached its cost limit: "
751
+ )
752
+ )
753
+ for item in deferred
754
+ )
755
+ )
742
756
  lines.extend(
743
757
  [
744
758
  "### No findings",
745
759
  "",
746
- "No reportable findings survived the canonical discovery, validation, and reportability gates.",
760
+ (
761
+ "No source review completed before the configured time limit. "
762
+ "No vulnerability conclusion can be drawn."
763
+ if no_source_review
764
+ else (
765
+ "No findings were validated before the scan reached its cost limit. "
766
+ "Review the deferred candidates in Open Questions And Follow Up."
767
+ if budget_exhausted
768
+ else "No reportable findings survived the canonical discovery, validation, "
769
+ "and reportability gates."
770
+ )
771
+ ),
747
772
  ]
748
773
  )
749
774
  if hardening_portfolio_path is not None:
@@ -826,12 +851,7 @@ def generate_report_markdown(
826
851
  findings: dict[str, Any],
827
852
  coverage: dict[str, Any],
828
853
  ) -> bytes:
829
- markdown = build_report_markdown(manifest, findings, coverage)
830
- validator = _load_script("validate_report_format")
831
- errors = validator.validate_report(markdown)
832
- if errors:
833
- raise ReportProjectionError("generated report failed validation: " + "; ".join(errors))
834
- return markdown.encode("utf-8")
854
+ return build_report_markdown(manifest, findings, coverage).encode("utf-8")
835
855
 
836
856
 
837
857
  def main() -> int:
@@ -213,6 +213,11 @@ def parse_args(description: str) -> argparse.Namespace:
213
213
  complete_scan.add_argument("--cost-json")
214
214
  complete_scan.add_argument("--thread-id")
215
215
 
216
+ complete_budget_exhausted_scan = subparsers.add_parser("complete-budget-exhausted-scan")
217
+ complete_budget_exhausted_scan.add_argument("--scan-id", required=True)
218
+ complete_budget_exhausted_scan.add_argument("--cost-json", required=True)
219
+ complete_budget_exhausted_scan.add_argument("--message")
220
+
216
221
  cancel_scan = subparsers.add_parser("cancel-scan")
217
222
  cancel_scan.add_argument("--scan-id", required=True)
218
223
  cancel_scan.add_argument("--thread-id")