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

Copyberryc5b792635b56
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 ab75c8f07..1748672d9 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 8c10ea772..9ebcb5673 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/deep_scan_workbench.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/deep_scan_workbench.py
index 75c3cd043..def3de4f7 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/deep_scan_workbench.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/deep_scan_workbench.py
@@ -15,13 +15,14 @@ from typing import Any, Callable
sys.path.insert(0, str(Path(__file__).resolve().parent))
from deep_scan_config import resolve_deep_scan_config
from filesystem_identity import serialize_filesystem_identity
+from workbench.handoff import require_current_continuation
from workbench_target import (
directory_content_digest,
directory_snapshot_regular_file_count,
git_revision,
worktree_content_digest,
)
-from workbench_validation import optional_text, require_current_continuation, require_uuid
+from workbench_validation import optional_text, require_uuid
DEEP_SCAN_WORKER_KINDS = ("setup", "discovery", "dedup")
DEEP_SCAN_WORKER_STATUSES = ("queued", "running", "succeeded", "failed", "canceled")
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 d2fa6a9ac..79702c04d 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
@@ -52,6 +52,7 @@ from finalize_scan_contract import (
write_scan_local_bytes,
)
from finding_preview import bounded_finding_details
+from workbench import handoff
from workbench_cli import parse_args
from workbench_constants import (
ARTIFACTS,
@@ -95,11 +96,8 @@ from workbench_target import (
from workbench_target_state import backfill_security_targets, ensure_security_target
from workbench_validation import (
optional_text,
- require_current_continuation,
- require_handoff_claim_token,
require_occurrence,
require_uuid,
- validate_handoff_delivery_thread,
)
FINDING_ARTIFACT_DIRECTORIES_LIMIT = 80
@@ -1622,7 +1620,7 @@ def complete_scan_locked(
return scan_context(connection, scan["id"])
if scan["status"] != "running":
raise SystemExit("Only a running scan can be completed.")
- require_current_continuation(
+ handoff.require_current_continuation(
scan,
claim_token,
error_message="Scan completion is owned by another continuation.",
@@ -1657,7 +1655,7 @@ def complete_scan_locked(
if scan["status"] != "running":
raise SystemExit("Only a running scan can be completed.")
deep_scan.require_deep_scan_ready_for_parent_completion(connection, scan)
- require_current_continuation(
+ handoff.require_current_continuation(
scan,
claim_token,
error_message="Scan completion is owned by another continuation.",
@@ -1709,7 +1707,7 @@ def fail_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[
return scan_context(connection, scan["id"])
if scan["status"] == "complete":
raise SystemExit("A completed scan cannot be marked failed.")
- require_current_continuation(
+ handoff.require_current_continuation(
scan,
args.claim_token,
error_message="Scan failure is owned by another continuation.",
@@ -1783,160 +1781,6 @@ def cancel_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dic
return workspace_state(connection, scan["workspace_id"])
-def claim_handoff_delivery(
- connection: sqlite3.Connection, args: argparse.Namespace
-) -> dict[str, Any]:
- scan_id = require_uuid(args.scan_id, "scan-id")
- claim_token = require_handoff_claim_token(args.claim_token)
- timestamp = now()
- with connection:
- scan = require_scan(connection, scan_id)
- if scan["handoff_status"] != "pending" or scan["handoff_claim_token"] == claim_token:
- return workspace_state(connection, scan["workspace_id"])
- updated = connection.execute(
- """
- UPDATE scans
- SET handoff_claimed_at = ?, handoff_claim_token = ?,
- continuation_thread_id = CASE
- WHEN handoff_claim_token IS NULL THEN continuation_thread_id
- ELSE NULL
- END,
- deep_scan_owner_thread_id = CASE
- WHEN handoff_claim_token IS NULL THEN deep_scan_owner_thread_id
- ELSE NULL
- END,
- updated_at = ?
- WHERE id = ? AND handoff_status = 'pending'
- AND (
- handoff_claim_token IS NULL
- OR (
- ? = 1
- AND (handoff_claimed_at IS NULL OR handoff_claimed_at <= ?)
- )
- )
- """,
- (
- timestamp,
- claim_token,
- timestamp,
- scan["id"],
- int(args.take_over_stale),
- stale_claim_before(),
- ),
- )
- if updated.rowcount != 1:
- return workspace_state(connection, scan["workspace_id"])
- return workspace_state(connection, scan["workspace_id"])
-
-
-def release_handoff_delivery(
- connection: sqlite3.Connection, args: argparse.Namespace
-) -> dict[str, Any]:
- scan_id = require_uuid(args.scan_id, "scan-id")
- claim_token = require_handoff_claim_token(args.claim_token)
- timestamp = now()
- with connection:
- scan = require_scan(connection, scan_id)
- connection.execute(
- """
- UPDATE scans
- SET handoff_claimed_at = NULL, handoff_claim_token = NULL,
- continuation_thread_id = NULL, deep_scan_owner_thread_id = NULL,
- updated_at = ?
- WHERE id = ? AND handoff_status = 'pending'
- AND handoff_claim_token = ?
- """,
- (timestamp, scan["id"], claim_token),
- )
- return workspace_state(connection, scan["workspace_id"])
-
-
-def attach_scan_continuation_thread(
- connection: sqlite3.Connection, args: argparse.Namespace
-) -> dict[str, Any]:
- scan_id = require_uuid(args.scan_id, "scan-id")
- claim_token = require_handoff_claim_token(args.claim_token)
- thread_id = optional_text(args.thread_id, maximum=512)
- if thread_id is None:
- raise SystemExit("Codex Security continuation thread ID is required.")
- connection.execute("BEGIN IMMEDIATE")
- try:
- timestamp = now()
- scan = require_scan(connection, scan_id)
- if scan["handoff_claim_token"] != claim_token:
- raise SystemExit("Codex Security continuation thread claim token does not match.")
- if scan["continuation_thread_id"] is not None:
- if scan["continuation_thread_id"] != thread_id:
- raise SystemExit(
- "Codex Security scan continuation is owned by another continuation."
- )
- connection.commit()
- return workspace_state(connection, scan["workspace_id"])
- updated = connection.execute(
- """
- UPDATE scans
- SET continuation_thread_id = ?,
- deep_scan_owner_thread_id = CASE
- WHEN mode = 'deep' THEN ? ELSE deep_scan_owner_thread_id
- END,
- updated_at = ?
- WHERE id = ? AND continuation_thread_id IS NULL
- AND handoff_claim_token = ?
- """,
- (thread_id, thread_id, timestamp, scan["id"], claim_token),
- )
- if updated.rowcount != 1:
- raise SystemExit("Codex Security continuation thread could not be attached.")
- connection.commit()
- except BaseException:
- connection.rollback()
- raise
- return workspace_state(connection, scan["workspace_id"])
-
-
-def mark_handoff_delivered(
- connection: sqlite3.Connection, args: argparse.Namespace
-) -> dict[str, Any]:
- scan_id = require_uuid(args.scan_id, "scan-id")
- claim_token = require_handoff_claim_token(args.claim_token)
- thread_id = optional_text(args.thread_id, maximum=512)
- connection.execute("BEGIN IMMEDIATE")
- try:
- timestamp = now()
- scan = require_scan(connection, scan_id)
- if thread_id is not None:
- workspace = require_workspace(connection, scan["workspace_id"])
- validate_handoff_delivery_thread(
- scan["continuation_thread_id"] or workspace["thread_id"],
- thread_id,
- claim_token,
- )
- if scan["handoff_status"] == "delivered":
- if scan["handoff_claim_token"] != claim_token:
- raise SystemExit(
- "Codex Security handoff delivery is owned by another continuation."
- )
- connection.commit()
- return workspace_state(connection, scan["workspace_id"])
- updated = connection.execute(
- """
- UPDATE scans
- SET handoff_status = 'delivered', handoff_claimed_at = NULL,
- updated_at = ?
- WHERE id = ? AND handoff_status = 'pending'
- AND handoff_claim_token = ?
- """,
- (timestamp, scan["id"], claim_token),
- )
- if updated.rowcount != 1:
- raise SystemExit("Codex Security handoff delivery could not be recorded.")
- connection.commit()
- except BaseException:
- connection.rollback()
- raise
- return workspace_state(connection, scan["workspace_id"])
-
-
def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
close_reason = args.close_reason
if args.status == "open" and close_reason is not None:
@@ -3713,13 +3557,39 @@ def main() -> None:
elif args.command == "fail-scan":
result = fail_scan(connection, args)
elif args.command == "mark-handoff-delivered":
- result = mark_handoff_delivered(connection, args)
+ result = handoff.mark_handoff_delivered(
+ connection,
+ args,
+ now=now,
+ require_scan=require_scan,
+ require_workspace=require_workspace,
+ workspace_state=workspace_state,
+ )
elif args.command == "claim-handoff-delivery":
- result = claim_handoff_delivery(connection, args)
+ result = handoff.claim_handoff_delivery(
+ connection,
+ args,
+ now=now,
+ require_scan=require_scan,
+ stale_claim_before=stale_claim_before,
+ workspace_state=workspace_state,
+ )
elif args.command == "release-handoff-delivery":
- result = release_handoff_delivery(connection, args)
+ result = handoff.release_handoff_delivery(
+ connection,
+ args,
+ now=now,
+ require_scan=require_scan,
+ workspace_state=workspace_state,
+ )
elif args.command == "attach-scan-continuation-thread":
- result = attach_scan_continuation_thread(connection, args)
+ result = handoff.attach_scan_continuation_thread(
+ connection,
+ args,
+ now=now,
+ require_scan=require_scan,
+ workspace_state=workspace_state,
+ )
elif args.command == "set-finding-triage":
result = set_finding_triage(connection, args)
elif args.command == "request-finding-remediation":
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 1a0f9f6f4..30f66c03f 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
@@ -7,8 +7,9 @@ from pathlib import Path
from typing import Any, Callable
sys.path.insert(0, str(Path(__file__).resolve().parent))
+from workbench.handoff import require_current_continuation
from workbench_constants import PHASES
-from workbench_validation import require_current_continuation, require_uuid
+from workbench_validation import require_uuid
def reportable_count(
diff --git a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_validation.py b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_validation.py
index 248db837a..b4dbd5393 100644
--- a/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_validation.py
+++ b/sdk/python/src/openai_codex_security/_bundled_plugin/scripts/workbench_validation.py
@@ -6,8 +6,6 @@ import argparse
import sqlite3
import uuid
-RECOVERY_HANDOFF_TOKEN_PREFIX = "recovery_"
-
def require_uuid(value: str, label: str) -> str:
try:
@@ -37,44 +35,6 @@ def require_occurrence(connection: sqlite3.Connection, occurrence_id: str) -> sq
return row
-def require_handoff_claim_token(value: str) -> str:
- recovery_token = value.startswith(RECOVERY_HANDOFF_TOKEN_PREFIX)
- token = value.removeprefix(RECOVERY_HANDOFF_TOKEN_PREFIX) if recovery_token else value
- normalized = require_uuid(token, "claim-token")
- return f"{RECOVERY_HANDOFF_TOKEN_PREFIX}{normalized}" if recovery_token else normalized
-
-
-def require_current_continuation(
- scan: sqlite3.Row,
- claim_token: str | None,
- *,
- error_message: str,
-) -> None:
- if (
- scan["handoff_status"] == "delivered"
- and scan["handoff_claim_token"] is None
- and claim_token is None
- ):
- return
- if claim_token is None:
- raise SystemExit(error_message)
- if scan["handoff_claim_token"] != require_handoff_claim_token(claim_token):
- raise SystemExit(error_message)
-
-
-def validate_handoff_delivery_thread(
- owning_thread_id: str | None,
- requesting_thread_id: str,
- claim_token: str,
-) -> None:
- if owning_thread_id != requesting_thread_id and not claim_token.startswith(
- RECOVERY_HANDOFF_TOKEN_PREFIX
- ):
- raise SystemExit(
- "A scan handoff can only be marked delivered from its owning Codex thread."
- )
-
-
def main() -> None:
argparse.ArgumentParser(description=__doc__).parse_args()