@openai/codex-security 0.1.5 → 0.1.7

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 (94) hide show
  1. package/README.md +89 -8
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +24 -1
  4. package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  6. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  7. package/_bundled_plugin/preflight/capability-profiles.toml +0 -57
  8. package/_bundled_plugin/references/config-preflight.md +1 -1
  9. package/_bundled_plugin/references/final-report.md +15 -7
  10. package/_bundled_plugin/references/scan-artifacts.md +11 -9
  11. package/_bundled_plugin/references/scan-contract.md +3 -1
  12. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +42 -0
  13. package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +100 -0
  14. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +181 -0
  15. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +166 -0
  16. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +120 -0
  17. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +83 -0
  18. package/_bundled_plugin/schemas/tools/review-items.schema.json +80 -0
  19. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +572 -0
  20. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +18 -0
  21. package/_bundled_plugin/scripts/deep_scan_config.py +11 -3
  22. package/_bundled_plugin/scripts/deep_scan_workbench.py +153 -133
  23. package/_bundled_plugin/scripts/finalize_scan_contract.py +21 -0
  24. package/_bundled_plugin/scripts/generate_in_scope_files.py +134 -0
  25. package/_bundled_plugin/scripts/workbench_cli.py +33 -1
  26. package/_bundled_plugin/scripts/workbench_db.py +127 -117
  27. package/_bundled_plugin/scripts/workbench_feedback.py +2 -0
  28. package/_bundled_plugin/scripts/workbench_native_indexes.py +5 -49
  29. package/_bundled_plugin/scripts/workbench_progress.py +86 -3
  30. package/_bundled_plugin/scripts/workbench_remediation.py +19 -1
  31. package/_bundled_plugin/scripts/workbench_scan_history.py +7 -1
  32. package/_bundled_plugin/scripts/workbench_scan_start.py +11 -5
  33. package/_bundled_plugin/scripts/workbench_scan_usage.py +557 -0
  34. package/_bundled_plugin/scripts/workbench_schema.py +501 -0
  35. package/_bundled_plugin/scripts/workbench_validation.py +117 -13
  36. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -4
  37. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +34 -28
  38. package/_bundled_plugin/skills/finding-discovery/SKILL.md +1 -1
  39. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +11 -8
  40. package/_bundled_plugin/skills/security-scan/SKILL.md +16 -9
  41. package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +26 -14
  42. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +1 -1
  43. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  44. package/_bundled_plugin/skills/validation/SKILL.md +5 -5
  45. package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +145 -227
  46. package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +53 -68
  47. package/dist/api.d.ts +33 -7
  48. package/dist/api.d.ts.map +1 -1
  49. package/dist/api.js +361 -48
  50. package/dist/api.js.map +1 -1
  51. package/dist/auth.js +1 -1
  52. package/dist/auth.js.map +1 -1
  53. package/dist/cli.d.ts +3 -2
  54. package/dist/cli.d.ts.map +1 -1
  55. package/dist/cli.js +477 -40
  56. package/dist/cli.js.map +1 -1
  57. package/dist/config.d.ts +29 -0
  58. package/dist/config.d.ts.map +1 -1
  59. package/dist/config.js +47 -2
  60. package/dist/config.js.map +1 -1
  61. package/dist/cost.d.ts +7 -0
  62. package/dist/cost.d.ts.map +1 -1
  63. package/dist/cost.js +349 -18
  64. package/dist/cost.js.map +1 -1
  65. package/dist/index.d.ts +3 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.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 +3 -0
  71. package/dist/multiscan.js.map +1 -1
  72. package/dist/runtime.d.ts +16 -0
  73. package/dist/runtime.d.ts.map +1 -1
  74. package/dist/runtime.js +540 -25
  75. package/dist/runtime.js.map +1 -1
  76. package/dist/scan-activity.d.ts +13 -0
  77. package/dist/scan-activity.d.ts.map +1 -0
  78. package/dist/scan-activity.js +319 -0
  79. package/dist/scan-activity.js.map +1 -0
  80. package/dist/scan-dashboard.d.ts +47 -0
  81. package/dist/scan-dashboard.d.ts.map +1 -0
  82. package/dist/scan-dashboard.js +444 -0
  83. package/dist/scan-dashboard.js.map +1 -0
  84. package/dist/scan-history-renderer.d.ts.map +1 -1
  85. package/dist/scan-history-renderer.js +4 -1
  86. package/dist/scan-history-renderer.js.map +1 -1
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/dist/version.js.map +1 -1
  90. package/dist/worker-progress.d.ts +7 -0
  91. package/dist/worker-progress.d.ts.map +1 -1
  92. package/dist/worker-progress.js +68 -0
  93. package/dist/worker-progress.js.map +1 -1
  94. package/package.json +3 -3
@@ -4,7 +4,7 @@ import argparse
4
4
  import sqlite3
5
5
  import sys
6
6
  from collections import Counter
7
- from collections.abc import Callable, Iterator
7
+ from collections.abc import Iterator
8
8
  from itertools import islice
9
9
  from pathlib import Path
10
10
  from typing import Any
@@ -19,14 +19,12 @@ from workbench_validation import bounded_output_text
19
19
  def list_global_findings(
20
20
  connection: sqlite3.Connection,
21
21
  args: argparse.Namespace,
22
- *,
23
- read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
24
22
  ) -> dict[str, Any]:
25
23
  limit = min(args.limit, FINDINGS_PAGE_MAX)
26
24
  query = args.query.strip().casefold() if args.query else ""
27
25
  findings = (
28
26
  row
29
- for row in _active_findings(connection, read_coverage)
27
+ for row in _indexed_findings(connection)
30
28
  if (args.target_id is None or row["target_id"] == args.target_id)
31
29
  and (args.severity is None or row["severity"] == args.severity)
32
30
  and (args.status is None or row["status"] == args.status)
@@ -72,23 +70,8 @@ def list_global_findings(
72
70
  }
73
71
 
74
72
 
75
- def _active_findings(
76
- connection: sqlite3.Connection,
77
- read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
78
- ) -> Iterator[sqlite3.Row]:
79
- completed_scans_by_target: dict[str, list[sqlite3.Row]] = {}
80
- for scan in connection.execute(
81
- """
82
- SELECT *
83
- FROM scans
84
- WHERE status = 'complete' AND seal_manifest_digest IS NOT NULL
85
- ORDER BY started_at DESC, id DESC
86
- """
87
- ):
88
- completed_scans_by_target.setdefault(scan["target_id"], []).append(scan)
89
-
90
- coverage_by_scan_id: dict[str, dict[str, Any]] = {}
91
- rows = connection.execute(
73
+ def _indexed_findings(connection: sqlite3.Connection) -> Iterator[sqlite3.Row]:
74
+ yield from connection.execute(
92
75
  """
93
76
  WITH ranked_findings AS (
94
77
  SELECT
@@ -97,7 +80,6 @@ def _active_findings(
97
80
  occurrences.severity,
98
81
  occurrences.created_at,
99
82
  scans.id AS scan_id,
100
- scans.started_at AS scan_started_at,
101
83
  scans.target_id,
102
84
  targets.current_path AS target_path,
103
85
  scans.scope,
@@ -146,35 +128,11 @@ def _active_findings(
146
128
  selected_findings.occurrence_id
147
129
  """,
148
130
  )
149
- for row in rows:
150
- resolved = False
151
- for scan in completed_scans_by_target.get(row["target_id"], ()):
152
- if (scan["started_at"], scan["id"]) <= (
153
- row["scan_started_at"],
154
- row["scan_id"],
155
- ):
156
- break
157
- coverage = coverage_by_scan_id.get(scan["id"])
158
- if coverage is None:
159
- coverage = read_coverage(scan)
160
- coverage_by_scan_id[scan["id"]] = coverage
161
- if scan_history.scan_covers_path(
162
- scan,
163
- target_id=row["target_id"],
164
- path=row["location_path"],
165
- coverage=coverage,
166
- ):
167
- resolved = True
168
- break
169
- if not resolved:
170
- yield row
171
131
 
172
132
 
173
133
  def list_repositories(
174
134
  connection: sqlite3.Connection,
175
135
  args: argparse.Namespace | None = None,
176
- *,
177
- read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
178
136
  ) -> dict[str, Any]:
179
137
  scans = scan_history.list_scans(connection)["scans"]
180
138
  scans_by_id = {scan["scanId"]: scan for scan in scans}
@@ -190,9 +148,7 @@ def list_repositories(
190
148
  latest_scan_by_target.setdefault(row["target_id"], scans_by_id[row["id"]])
191
149
 
192
150
  open_findings_by_target = Counter(
193
- row["target_id"]
194
- for row in _active_findings(connection, read_coverage)
195
- if row["status"] == "open"
151
+ row["target_id"] for row in _indexed_findings(connection) if row["status"] == "open"
196
152
  )
197
153
  targets = {row["id"]: row for row in connection.execute("SELECT * FROM security_targets")}
198
154
  repositories = [
@@ -10,7 +10,7 @@ from typing import Any, Callable
10
10
  sys.path.insert(0, str(Path(__file__).resolve().parent))
11
11
  from workbench.handoff import require_current_continuation
12
12
  from workbench_constants import PHASES
13
- from workbench_validation import require_uuid
13
+ from workbench_validation import optional_text, require_uuid, user_text
14
14
 
15
15
  MAX_PREFLIGHT_ISSUES_JSON_BYTES = 64 * 1024
16
16
  MAX_PREFLIGHT_ISSUES = 32
@@ -77,6 +77,86 @@ def reportable_count(
77
77
  return count
78
78
 
79
79
 
80
+ def update_context(
81
+ connection: sqlite3.Connection,
82
+ args: argparse.Namespace,
83
+ *,
84
+ now: Callable[[], str],
85
+ require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
86
+ require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row],
87
+ scan_context: Callable[[sqlite3.Connection, str], dict[str, Any]],
88
+ ) -> dict[str, Any]:
89
+ scan_id = require_uuid(args.scan_id, "scan-id")
90
+ context = user_text(args.user_context)
91
+ connection.execute("BEGIN IMMEDIATE")
92
+ try:
93
+ scan = require_scan(connection, scan_id)
94
+ if scan["status"] != "running" or scan["canceled_at"] is not None:
95
+ raise SystemExit("Only a running scan can update context.")
96
+ workspace = require_workspace(connection, scan["workspace_id"])
97
+ if args.workspace_id is not None:
98
+ if args.claim_token is not None:
99
+ raise SystemExit("claim-token is only valid with thread-id.")
100
+ if require_uuid(args.workspace_id, "workspace-id") != workspace["id"]:
101
+ raise SystemExit("This scan does not belong to the selected workspace.")
102
+ else:
103
+ thread_id = optional_text(args.thread_id, maximum=512)
104
+ owning_thread_id = scan["continuation_thread_id"] or workspace["thread_id"]
105
+ if thread_id is None or thread_id != owning_thread_id:
106
+ raise SystemExit("This scan does not belong to the current Codex thread.")
107
+ require_current_continuation(
108
+ scan,
109
+ args.claim_token,
110
+ error_message="Scan context updates are owned by another continuation.",
111
+ )
112
+ timestamp = now()
113
+ connection.execute(
114
+ "UPDATE scans SET user_context = ?, updated_at = ? WHERE id = ?",
115
+ (context, timestamp, scan["id"]),
116
+ )
117
+ if args.workspace_id is not None:
118
+ connection.execute(
119
+ "UPDATE workspaces SET user_context = ?, updated_at = ? WHERE id = ?",
120
+ (context, timestamp, workspace["id"]),
121
+ )
122
+ else:
123
+ connection.execute(
124
+ "UPDATE workspaces SET updated_at = ? WHERE id = ?",
125
+ (timestamp, workspace["id"]),
126
+ )
127
+ connection.commit()
128
+ except BaseException:
129
+ connection.rollback()
130
+ raise
131
+ return scan_context(connection, scan_id)
132
+
133
+
134
+ def update(
135
+ connection: sqlite3.Connection,
136
+ args: argparse.Namespace,
137
+ now: Callable[[], str],
138
+ require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
139
+ require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row],
140
+ scan_context: Callable[[sqlite3.Connection, str], dict[str, Any]],
141
+ ) -> dict[str, Any]:
142
+ if args.command == "update-scan-context":
143
+ return update_context(
144
+ connection,
145
+ args,
146
+ now=now,
147
+ require_scan=require_scan,
148
+ require_workspace=require_workspace,
149
+ scan_context=scan_context,
150
+ )
151
+ return update_progress(
152
+ connection,
153
+ args,
154
+ now=now,
155
+ require_scan=require_scan,
156
+ scan_context=scan_context,
157
+ )
158
+
159
+
80
160
  def update_progress(
81
161
  connection: sqlite3.Connection,
82
162
  args: argparse.Namespace,
@@ -86,6 +166,8 @@ def update_progress(
86
166
  scan_context: Callable[[sqlite3.Connection, str], dict[str, Any]],
87
167
  ) -> dict[str, Any]:
88
168
  scan_id = require_uuid(args.scan_id, "scan-id")
169
+ model = optional_text(args.model, maximum=200)
170
+ reasoning_effort = optional_text(args.reasoning_effort, maximum=32)
89
171
  serialized_preflight_issues = preflight_issues_json(args.preflight_issues_json)
90
172
  connection.execute("BEGIN IMMEDIATE")
91
173
  try:
@@ -189,10 +271,11 @@ def update_progress(
189
271
  updated = connection.execute(
190
272
  """
191
273
  UPDATE scans
192
- SET phase = COALESCE(?, phase), updated_at = ?
274
+ SET phase = COALESCE(?, phase), model = COALESCE(?, model),
275
+ reasoning_effort = COALESCE(?, reasoning_effort), updated_at = ?
193
276
  WHERE id = ? AND status = 'running'
194
277
  """,
195
- (args.phase, timestamp, scan["id"]),
278
+ (args.phase, model, reasoning_effort, timestamp, scan["id"]),
196
279
  )
197
280
  if updated.rowcount != 1:
198
281
  raise SystemExit("Only a running scan can update progress.")
@@ -5,15 +5,33 @@ from __future__ import annotations
5
5
  import argparse
6
6
  import sqlite3
7
7
  import sys
8
- from datetime import datetime, timezone
8
+ from datetime import datetime, timedelta, timezone
9
9
  from pathlib import Path
10
10
  from typing import Any
11
11
 
12
12
  # Some plugin hosts launch Python with safe-path isolation enabled.
13
13
  sys.path.insert(0, str(Path(__file__).resolve().parent))
14
+ from workbench_constants import CLAIM_LEASE_SECONDS, DELIVERED_ACTION_LEASE_SECONDS
14
15
  from workbench_validation import require_occurrence, require_uuid
15
16
 
16
17
 
18
+ def remediation_claim_is_active(remediation: sqlite3.Row) -> bool:
19
+ if remediation["pending_action_claim_token"] is None:
20
+ return False
21
+ delivered_at = remediation["pending_action_delivered_at"]
22
+ claimed_at = delivered_at or remediation["pending_action_claimed_at"]
23
+ if not isinstance(claimed_at, str):
24
+ return True
25
+ try:
26
+ parsed = datetime.fromisoformat(claimed_at)
27
+ if parsed.tzinfo is None:
28
+ return True
29
+ except ValueError:
30
+ return True
31
+ lease_seconds = DELIVERED_ACTION_LEASE_SECONDS if delivered_at else CLAIM_LEASE_SECONDS
32
+ return parsed > datetime.now(timezone.utc) - timedelta(seconds=lease_seconds)
33
+
34
+
17
35
  def register_cancel_finding_remediation_request(subparsers: Any) -> None:
18
36
  parser = subparsers.add_parser("cancel-finding-remediation-request")
19
37
  parser.add_argument("--occurrence-id", required=True)
@@ -5,12 +5,16 @@ import fnmatch
5
5
  import json
6
6
  import os
7
7
  import sqlite3
8
+ import sys
8
9
  from pathlib import Path, PurePosixPath
9
10
  from typing import Any, Callable
10
11
  from urllib.parse import urlsplit
11
12
 
13
+ # Some plugin hosts launch Python with safe-path isolation enabled.
14
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
12
15
  from report_projection import SEVERITY_ORDER
13
16
  from workbench_constants import FINDINGS_PAGE_MAX
17
+ from workbench_scan_usage import stored_scan_cost_fields
14
18
  from workbench_target import git_output
15
19
 
16
20
 
@@ -221,10 +225,11 @@ def list_scans(
221
225
  {
222
226
  "completedAt": row["completed_at"],
223
227
  "continuationThreadId": row["continuation_thread_id"],
224
- **({"cost": json.loads(row["cost_json"])} if row["cost_json"] else {}),
228
+ **stored_scan_cost_fields(row["cost_json"]),
225
229
  "findingCount": row["finding_count"],
226
230
  "handoffStatus": row["handoff_status"],
227
231
  "mode": row["mode"],
232
+ "model": row["model"],
228
233
  "parentScanId": row["parent_scan_id"],
229
234
  "progress": {
230
235
  "candidates": {"reportable": row["reportable_findings_count"]},
@@ -238,6 +243,7 @@ def list_scans(
238
243
  "updatedAt": row["progress_updated_at"],
239
244
  },
240
245
  "recipeAvailable": row["recipe_json"] is not None,
246
+ "reasoningEffort": row["reasoning_effort"],
241
247
  "scanDir": row["scan_dir"],
242
248
  "scanId": row["id"],
243
249
  "scope": row["scope"],
@@ -22,6 +22,7 @@ from workbench_target import (
22
22
  git_revision,
23
23
  worktree_content_digest,
24
24
  )
25
+ from workbench_validation import optional_text, user_text
25
26
 
26
27
 
27
28
  def safe_segment(value: str) -> str:
@@ -161,10 +162,13 @@ def insert_running_scan(
161
162
  scope_file_count: int,
162
163
  timestamp: str,
163
164
  handoff_status: str = "pending",
165
+ model: str | None = None,
166
+ reasoning_effort: str | None = None,
164
167
  scan_dir: Path | None = None,
165
168
  ) -> str:
166
169
  revision = target_identity[0]
167
170
  native_scan = scan_dir is None
171
+ user_context = user_text(workspace["user_context"])
168
172
  if scan_dir is None:
169
173
  scan_dir = Path(
170
174
  tempfile.mkdtemp(
@@ -178,10 +182,10 @@ def insert_running_scan(
178
182
  id, workspace_id, target_id, target_path, target_revision, target_snapshot_digest,
179
183
  target_device, target_inode, scope, mode, user_context,
180
184
  deep_scan_owner_thread_id, diff_target_kind, diff_base_revision,
181
- diff_head_revision, diff_content_digest, target_summary, scan_dir, status, phase,
182
- handoff_status, started_at, created_at, updated_at
183
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', 'preflight',
184
- ?, ?, ?, ?)
185
+ diff_head_revision, diff_content_digest, target_summary, scan_dir, model,
186
+ reasoning_effort, status, phase, handoff_status, started_at, created_at, updated_at
187
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
188
+ 'running', 'preflight', ?, ?, ?, ?)
185
189
  """,
186
190
  (
187
191
  scan_id,
@@ -191,7 +195,7 @@ def insert_running_scan(
191
195
  *target_identity,
192
196
  scope,
193
197
  workspace["default_mode"],
194
- workspace["user_context"],
198
+ user_context,
195
199
  workspace["thread_id"] if workspace["default_mode"] == "deep" else None,
196
200
  diff_target["kind"] if diff_target else None,
197
201
  diff_target["baseRevision"] if diff_target else None,
@@ -199,6 +203,8 @@ def insert_running_scan(
199
203
  diff_target.get("contentDigest") if diff_target else None,
200
204
  target_summary,
201
205
  str(scan_dir),
206
+ optional_text(model, maximum=200),
207
+ optional_text(reasoning_effort, maximum=32),
202
208
  handoff_status,
203
209
  timestamp,
204
210
  timestamp,