Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

Sync from Copyberry

Copyberry5ca0c7d4fe9b
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/mcp-app.html.br b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/mcp-app.html.br
index 6b33838d8..9b0542f1e 100644
Binary files a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/mcp-app.html.br and b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/mcp-app.html.br differ
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-000 b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-000
index 67bccce3e..d12435b90 100644
Binary files a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-000 and b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-000 differ
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-001 b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-001
index f3ddfb59c..3cf4531b5 100644
Binary files a/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-001 and b/sdk/python/src/openai_codex_security/_bundled_plugin/mcp/server.mjs.br.part-001 differ
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_cli.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_cli.py
index e81db3094..1c855b180 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_cli.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_cli.py
@@ -17,6 +17,7 @@ from workbench_constants import (
FINDING_STATUSES,
FINDINGS_PAGE_MAX,
MODES,
+ PHASE_PROGRESS_UNITS,
PHASES,
REMEDIATION_UPDATE_STATES,
)
@@ -142,6 +143,9 @@ def parse_args(description: str) -> argparse.Namespace:
update_progress = subparsers.add_parser("update-progress")
update_progress.add_argument("--scan-id", required=True)
update_progress.add_argument("--phase", choices=PHASES)
+ update_progress.add_argument("--phase-items-total", type=non_negative_int)
+ update_progress.add_argument("--phase-items-completed", type=non_negative_int)
+ update_progress.add_argument("--phase-progress-unit", choices=PHASE_PROGRESS_UNITS)
update_progress.add_argument("--review-items-total", type=non_negative_int)
update_progress.add_argument("--review-items-completed", type=non_negative_int)
update_progress.add_argument("--reportable-findings-count", type=non_negative_int)
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_constants.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_constants.py
index a98848387..3a34b5901 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_constants.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_constants.py
@@ -5,6 +5,14 @@ import argparse
MODES = ("diff", "standard", "deep")
DIFF_TARGET_KINDS = ("working_tree", "commit", "range")
PHASES = ("preflight", "threat_model", "discovery", "validation", "attack_path", "reporting")
+PHASE_PROGRESS_UNITS = (
+ "checks",
+ "threat_surfaces",
+ "review_receipts",
+ "candidate_findings",
+ "validated_findings",
+ "report_artifacts",
+)
FINDING_STATUSES = ("open", "closed")
FINDING_CLOSE_REASONS = ("already_fixed", "wont_fix", "false_positive")
REMEDIATION_STATES = (
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_db.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_db.py
index d9a5674cf..b3432bb99 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_db.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_db.py
@@ -81,7 +81,7 @@ from workbench_scan_start import (
scan_diff_identity,
scan_target_identity,
)
-from workbench_schema import MIGRATIONS
+from workbench_schema import MIGRATIONS, normalize_pre_release_migrations, sql_statements
from workbench_source_excerpt import finding_source_excerpt
from workbench_target import (
clean_worktree_content_digest,
@@ -286,7 +286,7 @@ def apply_migrations(connection: sqlite3.Connection) -> None:
)
"""
)
- normalize_pre_release_migrations(connection)
+ normalize_pre_release_migrations(connection, now())
applied = {
row["version"] for row in connection.execute("SELECT version FROM schema_migrations")
}
@@ -307,69 +307,6 @@ def apply_migrations(connection: sqlite3.Connection) -> None:
raise
-def normalize_pre_release_migrations(connection: sqlite3.Connection) -> None:
- migration = connection.execute(
- "SELECT name FROM schema_migrations WHERE version = 2"
- ).fetchone()
- if migration is None or migration["name"] != "finding management schema":
- return
-
- legacy_versions = {
- row["version"]: row["name"]
- for row in connection.execute(
- "SELECT version, name FROM schema_migrations WHERE version BETWEEN 2 AND 5"
- )
- }
- expected = {
- 2: "finding management schema",
- 3: "scan handoff delivery claims",
- 4: "finding remediation action claims",
- 5: "scan target snapshot digests",
- }
- for version, name in legacy_versions.items():
- if expected.get(version) != name:
- raise SystemExit(
- "The Codex Security database has an unsupported pre-release migration history."
- )
-
- connection.execute(
- "DELETE FROM schema_migrations WHERE version = 5 AND name = ?",
- (expected[5],),
- )
- for old_version, new_version in ((4, 5), (3, 4), (2, 3)):
- connection.execute(
- "UPDATE schema_migrations SET version = ? WHERE version = ? AND name = ?",
- (new_version, old_version, expected[old_version]),
- )
- add_column_if_missing(connection, "workspaces", "capability_preflight_json", "TEXT")
- add_column_if_missing(connection, "scans", "target_snapshot_digest", "TEXT")
- connection.execute(
- "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
- (2, "persist capability preflight summaries", now()),
- )
-
-
-def add_column_if_missing(
- connection: sqlite3.Connection, table: str, column: str, definition: str
-) -> None:
- columns = {row["name"] for row in connection.execute(f"PRAGMA table_info({table})")}
- if column not in columns:
- connection.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
-
-
-def sql_statements(script: str) -> list[str]:
- statements: list[str] = []
- buffer = ""
- for line in script.splitlines():
- buffer = f"{buffer}\n{line}".strip()
- if sqlite3.complete_statement(buffer):
- statements.append(buffer)
- buffer = ""
- if buffer:
- raise ValueError("Incomplete SQLite migration statement.")
- return statements
-
-
def reject_nonstandard_json_number(value: str) -> None:
raise ValueError(f"invalid JSON number {value}")
@@ -1802,10 +1739,12 @@ def complete_scan_locked(
connection.execute(
"""
UPDATE scan_progress
- SET reportable_findings_count = ?, updated_at = ?
+ SET reportable_findings_count = ?, phase_items_total = ?,
+ phase_items_completed = ?, phase_progress_unit = 'report_artifacts',
+ updated_at = ?
WHERE scan_id = ?
""",
- (finding_count, timestamp, scan["id"]),
+ (finding_count, len(artifacts), len(artifacts), timestamp, scan["id"]),
)
updated = connection.execute(
"""
@@ -3066,6 +3005,11 @@ def scan_result(
"worklistRows": progress["review_items_total"],
},
"phase": scan["phase"],
+ "phaseProgress": {
+ "completed": progress["phase_items_completed"],
+ "total": progress["phase_items_total"],
+ "unit": progress["phase_progress_unit"],
+ },
"reviewPass": progress["deep_review_pass"],
"status": "canceled" if scan["canceled_at"] else scan["status"],
"updatedAt": progress["updated_at"],
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_progress.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_progress.py
index 30f66c03f..1f30ce8f2 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_progress.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_progress.py
@@ -47,6 +47,38 @@ def update_progress(
).fetchone()
if args.phase is not None and PHASES.index(args.phase) < PHASES.index(scan["phase"]):
raise SystemExit("Scan progress cannot move to an earlier phase.")
+ next_phase = args.phase or scan["phase"]
+ phase_changed = next_phase != scan["phase"]
+ phase_total = 0 if phase_changed else progress["phase_items_total"]
+ phase_completed = 0 if phase_changed else progress["phase_items_completed"]
+ phase_unit = None if phase_changed else progress["phase_progress_unit"]
+ if args.phase_items_total is not None:
+ phase_total = args.phase_items_total
+ if args.phase_items_completed is not None:
+ phase_completed = args.phase_items_completed
+ if args.phase_progress_unit is not None:
+ phase_unit = args.phase_progress_unit
+ if phase_completed > phase_total:
+ raise SystemExit("Completed phase items cannot exceed total phase items.")
+ if phase_total > 0 and phase_unit is None:
+ raise SystemExit("Phase progress with a nonzero total requires a progress unit.")
+ if not phase_changed:
+ if (
+ args.phase_items_total is not None
+ and args.phase_items_total < progress["phase_items_total"]
+ ):
+ raise SystemExit("Phase item total cannot decrease within a phase.")
+ if (
+ args.phase_items_completed is not None
+ and args.phase_items_completed < progress["phase_items_completed"]
+ ):
+ raise SystemExit("Completed phase items cannot decrease within a phase.")
+ if (
+ args.phase_progress_unit is not None
+ and progress["phase_progress_unit"] is not None
+ and args.phase_progress_unit != progress["phase_progress_unit"]
+ ):
+ raise SystemExit("Phase progress unit cannot change within a phase.")
updates: list[str] = []
values: list[Any] = []
for column, value in (
@@ -107,6 +139,15 @@ def update_progress(
"UPDATE scan_progress SET updated_at = ? WHERE scan_id = ?",
(timestamp, scan["id"]),
)
+ connection.execute(
+ """
+ UPDATE scan_progress
+ SET phase_items_total = ?, phase_items_completed = ?,
+ phase_progress_unit = ?, updated_at = ?
+ WHERE scan_id = ?
+ """,
+ (phase_total, phase_completed, phase_unit, timestamp, scan["id"]),
+ )
connection.commit()
except BaseException:
connection.rollback()
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_schema.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_schema.py
index ec295ffae..3cd2786b7 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_schema.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_schema.py
@@ -1,6 +1,7 @@
"""SQLite schema history for the Codex Security workbench."""
import argparse
+import sqlite3
MIGRATIONS = (
(
@@ -505,9 +506,116 @@ MIGRATIONS = (
);
""",
),
+ (
+ 20,
+ "phase-specific scan progress",
+ """
+ ALTER TABLE scan_progress
+ ADD COLUMN phase_items_total INTEGER NOT NULL DEFAULT 0
+ CHECK (phase_items_total >= 0);
+
+ ALTER TABLE scan_progress
+ ADD COLUMN phase_items_completed INTEGER NOT NULL DEFAULT 0
+ CHECK (phase_items_completed >= 0 AND phase_items_completed <= phase_items_total);
+
+ ALTER TABLE scan_progress
+ ADD COLUMN phase_progress_unit TEXT CHECK (
+ phase_progress_unit IS NULL OR phase_progress_unit IN (
+ 'checks',
+ 'threat_surfaces',
+ 'review_receipts',
+ 'candidate_findings',
+ 'validated_findings',
+ 'report_artifacts'
+ )
+ );
+ """,
+ ),
)
+def normalize_pre_release_migrations(connection: sqlite3.Connection, timestamp: str) -> None:
+ phase_progress_migration = connection.execute(
+ "SELECT name FROM schema_migrations WHERE version = 12"
+ ).fetchone()
+ if (
+ phase_progress_migration is not None
+ and phase_progress_migration["name"] == "phase-specific scan progress"
+ ):
+ target_migration = connection.execute(
+ "SELECT name FROM schema_migrations WHERE version = 20"
+ ).fetchone()
+ if target_migration is not None:
+ raise SystemExit(
+ "The Codex Security database has an unsupported pre-release migration history."
+ )
+ connection.execute(
+ "UPDATE schema_migrations SET version = 20 WHERE version = 12 AND name = ?",
+ ("phase-specific scan progress",),
+ )
+
+ migration = connection.execute(
+ "SELECT name FROM schema_migrations WHERE version = 2"
+ ).fetchone()
+ if migration is None or migration["name"] != "finding management schema":
+ return
+
+ legacy_versions = {
+ row["version"]: row["name"]
+ for row in connection.execute(
+ "SELECT version, name FROM schema_migrations WHERE version BETWEEN 2 AND 5"
+ )
+ }
+ expected = {
+ 2: "finding management schema",
+ 3: "scan handoff delivery claims",
+ 4: "finding remediation action claims",
+ 5: "scan target snapshot digests",
+ }
+ for version, name in legacy_versions.items():
+ if expected.get(version) != name:
+ raise SystemExit(
+ "The Codex Security database has an unsupported pre-release migration history."
+ )
+
+ connection.execute(
+ "DELETE FROM schema_migrations WHERE version = 5 AND name = ?",
+ (expected[5],),
+ )
+ for old_version, new_version in ((4, 5), (3, 4), (2, 3)):
+ connection.execute(
+ "UPDATE schema_migrations SET version = ? WHERE version = ? AND name = ?",
+ (new_version, old_version, expected[old_version]),
+ )
+ add_column_if_missing(connection, "workspaces", "capability_preflight_json", "TEXT")
+ add_column_if_missing(connection, "scans", "target_snapshot_digest", "TEXT")
+ connection.execute(
+ "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)",
+ (2, "persist capability preflight summaries", timestamp),
+ )
+
+
+def add_column_if_missing(
+ connection: sqlite3.Connection, table: str, column: str, definition: str
+) -> None:
+ columns = {row["name"] for row in connection.execute(f"PRAGMA table_info({table})")}
+ if column not in columns:
+ connection.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
+
+
+def sql_statements(script: str) -> list[str]:
+ statements: list[str] = []
+ buffer = ""
+ for line in script.splitlines():
+ buffer = f"{buffer}\n{line}".strip()
+ if sqlite3.complete_statement(buffer):
+ statements.append(buffer)
+ buffer = ""
+ if buffer:
+ raise ValueError("Incomplete SQLite migration statement.")
+ return statements
+
+
def main() -> None:
argparse.ArgumentParser(description=__doc__).parse_args()