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

feat: support custom scan names (#1180)

ianw-oai09ee36f00b14
diff --git a/plugins/codex-security/mcp-app/server.ts b/plugins/codex-security/mcp-app/server.ts
index 7efaaaf31..ef6ed8870 100644
--- a/plugins/codex-security/mcp-app/server.ts
+++ b/plugins/codex-security/mcp-app/server.ts
@@ -1474,6 +1474,32 @@ export function createCodexSecurityServer(): McpServer {
},
);
+ server.registerTool(
+ "rename_codex_security_scan",
+ {
+ title: "Rename Codex Security Scan",
+ description: "App-only. Change the display name of a saved scan.",
+ inputSchema: { ...scanSchema, name: z.string() },
+ annotations: {
+ readOnlyHint: false,
+ destructiveHint: false,
+ idempotentHint: true,
+ openWorldHint: false,
+ },
+ _meta: appMeta,
+ },
+ async ({ scanId, name }) =>
+ scanActionResult(
+ await runWorkbench([
+ "rename-scan",
+ "--scan-id",
+ scanId,
+ `--name=${name}`,
+ ]),
+ "Renamed Codex Security scan.",
+ ),
+ );
+
const updateRunningScanContext = async (input: {
claimToken?: string;
scanId: string;
diff --git a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
index 9f7c55ced..f2ae81693 100644
--- a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
+++ b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
@@ -1437,6 +1437,10 @@ try {
(tool: { name: string }) =>
tool.name === "update_codex_security_scan_context_from_app",
);
+ const renameScan = toolList.result.tools.find(
+ (tool: { name: string }) => tool.name === "rename_codex_security_scan",
+ );
+ assert.deepEqual(renameScan._meta.ui.visibility, ["app"]);
const submit = toolList.result.tools.find(
(tool: { name: string }) => tool.name === "submit_codex_security_setup",
);
@@ -2542,6 +2546,24 @@ try {
assertNoError(deliveredWithoutToken);
const longUserContext = "Prioritize tenant isolation. ".repeat(120).trim();
+ const renamedScan = await testServer.callTool(92020, {
+ name: "rename_codex_security_scan",
+ arguments: { scanId, name: " - Release audit " },
+ });
+ assertNoError(renamedScan);
+ assert.deepEqual(renamedScan.result.structuredContent, {
+ scanId,
+ name: "- Release audit",
+ });
+ const reopenedScan = await testServer.callTool(92021, {
+ name: "get_codex_security_scan",
+ arguments: { scanId },
+ });
+ assertNoError(reopenedScan);
+ assert.equal(
+ reopenedScan.result.structuredContent.scan.name,
+ "- Release audit",
+ );
const updatedContext = await testServer.callTool(92010, {
name: "update_codex_security_scan_context",
arguments: { handoffClaimToken, scanId, userContext: longUserContext },
diff --git a/plugins/codex-security/scripts/workbench_cli.py b/plugins/codex-security/scripts/workbench_cli.py
index ae1db666d..9d094ad76 100644
--- a/plugins/codex-security/scripts/workbench_cli.py
+++ b/plugins/codex-security/scripts/workbench_cli.py
@@ -124,6 +124,10 @@ def parse_args(description: str) -> argparse.Namespace:
get_scan.add_argument("--scan-id", required=True)
get_scan.add_argument("--occurrence-id")
+ rename_scan = subparsers.add_parser("rename-scan")
+ rename_scan.add_argument("--scan-id", required=True)
+ rename_scan.add_argument("--name", required=True)
+
get_scan_feedback = subparsers.add_parser("get-scan-feedback")
get_scan_feedback.add_argument("--scan-id", required=True)
diff --git a/plugins/codex-security/scripts/workbench_db.py b/plugins/codex-security/scripts/workbench_db.py
index d0bc61497..87f32bc38 100644
--- a/plugins/codex-security/scripts/workbench_db.py
+++ b/plugins/codex-security/scripts/workbench_db.py
@@ -2746,6 +2746,7 @@ def scan_result(
"mode": scan["mode"],
"model": scan["model"],
"diffTarget": stored_diff_target(scan),
+ "name": scan["name"],
"progress": progress_result,
"reasoningEffort": scan["reasoning_effort"],
"remediationAvailable": remediation_available,
@@ -3320,6 +3321,10 @@ def main() -> None:
result = deep_scan.record_deep_scan_publication_failure(connection, args)
elif args.command == "get-scan":
result = scan_context(connection, args.scan_id, args.occurrence_id)
+ elif args.command == "rename-scan":
+ result = scan_history.rename_scan(
+ connection, require_scan(connection, args.scan_id), args.name
+ )
elif args.command == "get-scan-feedback":
result = get_scan_feedback(connection, require_scan(connection, args.scan_id))
elif args.command == "list-scans":
diff --git a/plugins/codex-security/scripts/workbench_scan_history.py b/plugins/codex-security/scripts/workbench_scan_history.py
index 4dde1e2c4..eaef30135 100644
--- a/plugins/codex-security/scripts/workbench_scan_history.py
+++ b/plugins/codex-security/scripts/workbench_scan_history.py
@@ -23,6 +23,15 @@ from workbench_target import git_output, require_scan_target_identity
from workbench_validation import reject_non_finite_json
+def rename_scan(connection: sqlite3.Connection, scan: sqlite3.Row, name: str) -> dict[str, Any]:
+ name = name.strip()
+ if not name:
+ raise SystemExit("Scan name cannot be empty.")
+ connection.execute("UPDATE scans SET name = ? WHERE id = ?", (name, scan["id"]))
+ connection.commit()
+ return {"scanId": scan["id"], "name": name}
+
+
def scan_recipe(scan: sqlite3.Row) -> dict[str, Any]:
if scan["recipe_json"] is None:
raise SystemExit("This scan does not have a saved launch recipe.")
@@ -254,13 +263,15 @@ def list_scans(
if args is not None and args.query:
query = args.query.strip().casefold()
if query:
+ connection.create_function("codex_security_casefold", 1, str.casefold)
clauses.append(
"(instr(lower(scans.target_path), ?) > 0 "
+ "OR instr(codex_security_casefold(COALESCE(scans.name, '')), ?) > 0 "
"OR instr(lower(COALESCE(scans.target_summary, '')), ?) > 0 "
"OR instr(lower(scans.scope), ?) > 0 "
"OR instr(lower(scans.mode), ?) > 0)"
)
- values.extend((query, query, query, query))
+ values.extend((query, query, query, query, query))
where = f"WHERE {' AND '.join(clauses)}" if clauses else ""
paginated = args is not None and (args.limit is not None or args.offset != 0)
limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX) if paginated else None
@@ -303,6 +314,7 @@ def list_scans(
"handoffStatus": row["handoff_status"],
"mode": row["mode"],
"model": row["model"],
+ "name": row["name"],
"parentScanId": row["parent_scan_id"],
"progress": {
"candidates": {"reportable": row["reportable_findings_count"]},
diff --git a/plugins/codex-security/scripts/workbench_schema.py b/plugins/codex-security/scripts/workbench_schema.py
index cbf54bf83..6b41fcbb8 100644
--- a/plugins/codex-security/scripts/workbench_schema.py
+++ b/plugins/codex-security/scripts/workbench_schema.py
@@ -867,6 +867,13 @@ MIGRATIONS = (
);
""",
),
+ (
+ 42,
+ "editable scan names",
+ """
+ ALTER TABLE scans ADD COLUMN name TEXT;
+ """,
+ ),
)
diff --git a/plugins/codex-security/tests/test_workbench_db.py b/plugins/codex-security/tests/test_workbench_db.py
index bbc11fce1..74cbe1750 100644
--- a/plugins/codex-security/tests/test_workbench_db.py
+++ b/plugins/codex-security/tests/test_workbench_db.py
@@ -919,7 +919,7 @@ def test_workbench_persists_progress_and_indexes_completed_findings(tmp_path: Pa
)
}
assert tables == EXPECTED_TABLES
- assert connection.execute("SELECT COUNT(*) FROM schema_migrations").fetchone() == (41,)
+ assert connection.execute("SELECT COUNT(*) FROM schema_migrations").fetchone() == (42,)
assert connection.execute("SELECT COUNT(*) FROM findings").fetchone() == (1,)
assert connection.execute("SELECT COUNT(*) FROM finding_locations").fetchone() == (1,)
diff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.py
index 79d976f75..456b2bd6a 100644
--- a/plugins/codex-security/tests/test_workbench_deep_scan.py
+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py
@@ -276,7 +276,7 @@ def test_existing_generation_safely_claims_and_reclaims_without_schema_migration
return claim_deep_scan_coordinator(state_dir, codex_home, scan_id)
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
- assert connection.execute("SELECT MAX(version) FROM schema_migrations").fetchone() == (41,)
+ assert connection.execute("SELECT MAX(version) FROM schema_migrations").fetchone() == (42,)
assert claim()["deepScan"]["coordinatorGeneration"] == 2
assert claim()["coordinatorDisposition"] == "observing"
expire_deep_scan_coordinator(state_dir, scan_id)
diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.py
index f99f5ae14..0d6ddd7a1 100644
--- a/plugins/codex-security/tests/test_workbench_scan_history.py
+++ b/plugins/codex-security/tests/test_workbench_scan_history.py
@@ -31,6 +31,89 @@ SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "workbench_db.py"
FINALIZER = SCRIPT.with_name("finalize_scan_contract.py")
[email protected]("complete", [False, True])
[email protected]("upgrade", [False, True])
+def test_rename_persists_without_changing_scan_results(
+ tmp_path: Path, complete: bool, upgrade: bool
+) -> None:
+ state_dir = tmp_path / "state"
+ repository = tmp_path / "repository"
+ repository.mkdir()
+ scan = create_cli_scan(state_dir, tmp_path / "scans", repository, complete=complete)
+ before = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]
+ if upgrade:
+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
+ connection.execute("ALTER TABLE scans DROP COLUMN name")
+ connection.execute("DELETE FROM schema_migrations WHERE version = 42")
+
+ renamed = run_workbench(
+ state_dir, "rename-scan", "--scan-id", scan["scanId"], "--name= Release audit "
+ )
+
+ assert renamed == {"scanId": scan["scanId"], "name": "Release audit"}
+ after = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]
+ assert after == {**before, "name": "Release audit"}
+ listed = run_workbench(state_dir, "list-scans", "--query", "release audit")["scans"]
+ assert [(item["scanId"], item["name"]) for item in listed] == [
+ (scan["scanId"], "Release audit")
+ ]
+
+
+def test_rename_rejects_blank_names(tmp_path: Path) -> None:
+ state_dir = tmp_path / "state"
+ repository = tmp_path / "repository"
+ repository.mkdir()
+ scan = create_cli_scan(state_dir, tmp_path / "scans", repository, complete=False)
+
+ blank = run_workbench(
+ state_dir, "rename-scan", "--scan-id", scan["scanId"], "--name= ", check=False
+ )
+ assert blank["returncode"] != 0
+ assert "Scan name cannot be empty" in blank["stderr"]
+ assert run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["name"] is None
+
+
+ ("name", "query"),
+ [("Évaluation", "évaluation"), ("Straße", "STRASSE"), ("Проверка", "проверка")],
+)
+def test_scan_name_search_ignores_unicode_case(tmp_path: Path, name: str, query: str) -> None:
+ state_dir = tmp_path / "state"
+ repository = tmp_path / "repository"
+ repository.mkdir()
+ scan = create_cli_scan(state_dir, tmp_path / "scans", repository, complete=False)
+ run_workbench(state_dir, "rename-scan", "--scan-id", scan["scanId"], f"--name={name}")
+
+ listed = run_workbench(state_dir, "list-scans", "--query", query)["scans"]
+
+ assert [(item["scanId"], item["name"]) for item in listed] == [(scan["scanId"], name)]
+
+
+def test_rename_does_not_reorder_scan_history(tmp_path: Path) -> None:
+ state_dir = tmp_path / "state"
+ repository = tmp_path / "repository"
+ repository.mkdir()
+ older = create_cli_scan(state_dir, tmp_path / "scans", repository)
+ newer = create_cli_scan(state_dir, tmp_path / "scans", repository)
+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
+ for scan, timestamp in ((older, "2026-08-01"), (newer, "2026-08-02")):
+ connection.execute(
+ "UPDATE scans SET started_at = ?, updated_at = ? WHERE id = ?",
+ (timestamp, timestamp, scan["scanId"]),
+ )
+ connection.execute(
+ "UPDATE scan_progress SET updated_at = ? WHERE scan_id = ?",
+ (timestamp, scan["scanId"]),
+ )
+ before = run_workbench(state_dir, "list-scans")["scans"]
+ assert [scan["scanId"] for scan in before] == [newer["scanId"], older["scanId"]]
+
+ run_workbench(state_dir, "rename-scan", "--scan-id", older["scanId"], "--name=Release audit")
+
+ after = run_workbench(state_dir, "list-scans")["scans"]
+ assert after == [before[0], {**before[1], "name": "Release audit"}]
+
+
def compare_scan_pair(
state_dir: Path,
before: dict[str, Any],
diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
index d31e7421b..b9b37909b 100644
--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
@@ -79,6 +79,7 @@ EXPECTED_MIGRATIONS = [
(39, "store dedupe checkpoint bindings in columns"),
(40, "index finding identity and comparison history"),
(41, "checkpoint finding severity assessments"),
+ (42, "editable scan names"),
]
@@ -598,7 +599,7 @@ def test_workbench_serializes_concurrent_migrations(tmp_path: Path, upgrade: boo
{"databasePath": str(state_dir / "workbench.sqlite3")},
]
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
- assert connection.execute("SELECT COUNT(*) FROM schema_migrations").fetchone() == (41,)
+ assert connection.execute("SELECT COUNT(*) FROM schema_migrations").fetchone() == (42,)
def test_workbench_retries_writer_admission_and_legacy_backfill(tmp_path: Path) -> None:
@@ -1190,7 +1191,7 @@ def test_workbench_upgrades_preexisting_database(tmp_path: Path) -> None:
connection.execute("ALTER TABLE scans DROP COLUMN handoff_claim_token")
run_workbench(state_dir, "database-info")
with sqlite3.connect(database) as connection:
- assert connection.execute("SELECT MAX(version) FROM schema_migrations").fetchone() == (41,)
+ assert connection.execute("SELECT MAX(version) FROM schema_migrations").fetchone() == (42,)
assert {row[1] for row in connection.execute("PRAGMA table_info(scans)")} >= {
"handoff_claimed_at",
"handoff_claim_token",
diff --git a/sdk/typescript/tests-ts/workbench-scan-root-alias.test.ts b/sdk/typescript/tests-ts/workbench-scan-root-alias.test.ts
index 91cc240d7..d704084cc 100644
--- a/sdk/typescript/tests-ts/workbench-scan-root-alias.test.ts
+++ b/sdk/typescript/tests-ts/workbench-scan-root-alias.test.ts
@@ -7,46 +7,50 @@ import { expect, test } from "bun:test";
import { resolvePluginPython } from "../src/runtime.js";
import { PLUGIN_ROOT } from "./plugin-root.js";
-test.skipIf(process.platform !== "win32")(
- "matches scan-root filters across Windows path aliases",
- async () => {
- const python = await resolvePluginPython();
+test("matches scan-root filters including Windows path aliases", async () => {
+ const python = await resolvePluginPython();
- const root = realpathSync(
- mkdtempSync(join(tmpdir(), "codex-security-scan-root-case-")),
+ const root = realpathSync(
+ mkdtempSync(join(tmpdir(), "codex-security-scan-root-case-")),
+ );
+ const scanRoot = join(root, "Scan History");
+ mkdirSync(scanRoot);
+ try {
+ const probe = [
+ "import argparse, json, sqlite3, sys",
+ "sys.path.insert(0, sys.argv[1])",
+ "from workbench_db import apply_migrations",
+ "import workbench_scan_history as history",
+ "connection = sqlite3.connect(':memory:')",
+ "connection.row_factory = sqlite3.Row",
+ "connection.execute('PRAGMA foreign_keys = ON')",
+ "apply_migrations(connection)",
+ "connection.execute('INSERT INTO workspaces (id, created_at, updated_at) VALUES (?, ?, ?)', ('workspace', '1', '1'))",
+ "for scan_id, scan_dir in [('scan', sys.argv[2] + '/scan'), ('sibling', sys.argv[2] + ' Other/scan')]:",
+ " connection.execute('INSERT INTO scans (id, workspace_id, target_path, target_revision, scope, mode, scan_dir, status, phase, started_at, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (scan_id, 'workspace', 'repository', 'revision', '.', 'standard', scan_dir, 'complete', 'reporting', '1', '1', '1'))",
+ " connection.execute('INSERT INTO scan_progress (scan_id, scope_file_count, review_items_completed, review_items_total, updated_at) VALUES (?, 1, 1, 1, ?)', (scan_id, '1'))",
+ "args = argparse.Namespace(repository=None, scan_root=sys.argv[3], target_id=None, mode=None, status=None, query=None, limit=None, offset=0)",
+ "print(json.dumps(history.list_scans(connection, args)))",
+ ].join("\n");
+ const result = await promisify(execFile)(
+ python,
+ [
+ "-I",
+ "-B",
+ "-c",
+ probe,
+ join(PLUGIN_ROOT, "scripts"),
+ scanRoot,
+ process.platform === "win32" ? scanRoot.toUpperCase() : scanRoot,
+ ],
+ { encoding: "utf8", timeout: 10_000, windowsHide: true },
);
- const scanRoot = join(root, "Scan History");
- mkdirSync(scanRoot);
- try {
- const probe = [
- "import argparse, json, sqlite3, sys",
- "sys.path.insert(0, sys.argv[1])",
- "import workbench_scan_history as history",
- "connection = sqlite3.connect(':memory:')",
- "connection.row_factory = sqlite3.Row",
- "connection.executescript('''",
- "CREATE TABLE scans (id TEXT, target_path TEXT, target_id TEXT, status TEXT, started_at TEXT, completed_at TEXT, continuation_thread_id TEXT, cost_json TEXT, handoff_status TEXT, mode TEXT, model TEXT, parent_scan_id TEXT, phase TEXT, recipe_json TEXT, reasoning_effort TEXT, scan_dir TEXT, scope TEXT, target_revision TEXT, target_summary TEXT, updated_at TEXT, canceled_at TEXT, completion_warnings_json TEXT);",
- "CREATE TABLE scan_progress (scan_id TEXT, reportable_findings_count INTEGER, scope_file_count INTEGER, review_items_completed INTEGER, review_items_total INTEGER, updated_at TEXT);",
- "CREATE TABLE finding_occurrences (scan_id TEXT);",
- "''')",
- "connection.execute('INSERT INTO scans VALUES (?, ?, NULL, ?, ?, NULL, NULL, NULL, NULL, ?, NULL, NULL, ?, NULL, NULL, ?, ?, NULL, NULL, ?, NULL, ?)', ('scan', 'repository', 'complete', '1', 'standard_repository', 'complete', sys.argv[2] + '/scan', '.', '1', '[]'))",
- "connection.execute('INSERT INTO scans VALUES (?, ?, NULL, ?, ?, NULL, NULL, NULL, NULL, ?, NULL, NULL, ?, NULL, NULL, ?, ?, NULL, NULL, ?, NULL, ?)', ('sibling', 'repository', 'complete', '1', 'standard_repository', 'complete', sys.argv[2] + ' Other/scan', '.', '1', '[]'))",
- "connection.execute('INSERT INTO scan_progress VALUES (?, 0, 1, 1, 1, ?)', ('scan', '1'))",
- "args = argparse.Namespace(repository=None, scan_root=sys.argv[2].upper(), target_id=None, mode=None, status=None, query=None, limit=None, offset=0)",
- "print(json.dumps(history.list_scans(connection, args)))",
- ].join("\n");
- const result = await promisify(execFile)(
- python,
- ["-I", "-B", "-c", probe, join(PLUGIN_ROOT, "scripts"), scanRoot],
- { encoding: "utf8", timeout: 10_000, windowsHide: true },
- );
- expect(result.stderr).toBe("");
- expect(JSON.parse(result.stdout)).toMatchObject({
- scans: [{ scanId: "scan" }],
- });
- } finally {
- rmSync(root, { recursive: true, force: true });
- }
- },
-);
+ expect(result.stderr).toBe("");
+ expect(JSON.parse(result.stdout)).toMatchObject({
+ scans: [{ scanId: "scan" }],
+ });
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});