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

chore(codex-security): sync public projection

faizan-oai65ede061aa9f
diff --git a/sdk/typescript/_bundled_plugin/mcp/mcp-app.html.br b/sdk/typescript/_bundled_plugin/mcp/mcp-app.html.br
index d7c1bed2b..13be7cff1 100644
Binary files a/sdk/typescript/_bundled_plugin/mcp/mcp-app.html.br and b/sdk/typescript/_bundled_plugin/mcp/mcp-app.html.br differ
diff --git a/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-000 b/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-000
index d6f20c995..43fe57244 100644
Binary files a/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-000 and b/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-000 differ
diff --git a/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-001 b/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-001
index f446239b1..2c4040052 100644
Binary files a/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-001 and b/sdk/typescript/_bundled_plugin/mcp/server.mjs.br.part-001 differ
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_cli.py b/sdk/typescript/_bundled_plugin/scripts/workbench_cli.py
index 86255caa3..e6057cc1a 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_cli.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_cli.py
@@ -14,6 +14,7 @@ from workbench_constants import (
DIFF_TARGET_KINDS,
EXPORT_FORMATS,
FINDING_CLOSE_REASONS,
+ FINDING_SEVERITIES,
FINDING_STATUSES,
FINDINGS_PAGE_MAX,
MODES,
@@ -136,8 +137,14 @@ def parse_args(description: str) -> argparse.Namespace:
get_scan.add_argument("--occurrence-id")
list_scans = subparsers.add_parser("list-scans")
+ list_scans.add_argument("--query")
+ list_scans.add_argument("--target-id")
+ list_scans.add_argument("--status", choices=("running", "complete", "failed", "canceled"))
+ list_scans.add_argument("--mode", choices=MODES)
list_scans.add_argument("--repository")
list_scans.add_argument("--scan-root")
+ list_scans.add_argument("--offset", type=non_negative_int, default=0)
+ list_scans.add_argument("--limit", type=positive_int)
register_cli_scan = subparsers.add_parser("register-cli-scan")
register_cli_scan.add_argument("--scan-dir", required=True)
@@ -152,12 +159,24 @@ def parse_args(description: str) -> argparse.Namespace:
compare_scans.add_argument("--before-scan-id", required=True)
compare_scans.add_argument("--after-scan-id", required=True)
list_global_findings = subparsers.add_parser("list-global-findings")
+ list_global_findings.add_argument("--query")
+ list_global_findings.add_argument("--severity", choices=FINDING_SEVERITIES)
+ list_global_findings.add_argument("--status", choices=FINDING_STATUSES)
+ list_global_findings.add_argument("--target-id")
list_global_findings.add_argument("--offset", type=non_negative_int, default=0)
list_global_findings.add_argument("--limit", type=positive_int, default=FINDINGS_PAGE_MAX)
- subparsers.add_parser("list-repositories")
+ list_repositories = subparsers.add_parser("list-repositories")
+ list_repositories.add_argument("--query")
+ list_repositories.add_argument("--target-id")
+ list_repositories.add_argument("--status", choices=("scanned", "not_scanned", "open_findings"))
+ list_repositories.add_argument("--offset", type=non_negative_int, default=0)
+ list_repositories.add_argument("--limit", type=positive_int)
list_findings = subparsers.add_parser("list-findings")
list_findings.add_argument("--scan-id", required=True)
+ list_findings.add_argument("--query")
+ list_findings.add_argument("--severity", choices=FINDING_SEVERITIES)
+ list_findings.add_argument("--status", choices=FINDING_STATUSES)
list_findings.add_argument("--offset", type=non_negative_int, default=0)
list_findings.add_argument("--limit", type=positive_int, default=FINDINGS_PAGE_MAX)
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_constants.py b/sdk/typescript/_bundled_plugin/scripts/workbench_constants.py
index 3a34b5901..4ddd91f3c 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_constants.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_constants.py
@@ -13,6 +13,7 @@ PHASE_PROGRESS_UNITS = (
"validated_findings",
"report_artifacts",
)
+FINDING_SEVERITIES = ("critical", "high", "medium", "low", "informational")
FINDING_STATUSES = ("open", "closed")
FINDING_CLOSE_REASONS = ("already_fixed", "wont_fix", "false_positive")
REMEDIATION_STATES = (
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_db.py b/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
index fc7fb79dc..43662f723 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
@@ -2888,9 +2888,26 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d
scan = require_scan(connection, args.scan_id)
backfill_legacy_finding_details(connection, scan)
limit = min(args.limit, FINDINGS_PAGE_MAX)
- rows = finding_occurrence_rows(connection, scan["id"], offset=args.offset, limit=limit)
+ rows = finding_occurrence_rows(
+ connection,
+ scan["id"],
+ offset=args.offset,
+ limit=limit,
+ query=args.query,
+ severity=args.severity,
+ status=args.status,
+ )
+ conditions, values = finding_occurrence_conditions(
+ scan["id"], query=args.query, severity=args.severity, status=args.status
+ )
total = connection.execute(
- "SELECT COUNT(*) FROM finding_occurrences WHERE scan_id = ?", (scan["id"],)
+ f"""
+ SELECT COUNT(*)
+ FROM finding_occurrences AS occurrences
+ LEFT JOIN finding_triage AS triage ON triage.occurrence_id = occurrences.id
+ WHERE {conditions}
+ """,
+ values,
).fetchone()[0]
next_offset = args.offset + len(rows)
return {
@@ -3039,15 +3056,35 @@ def remediation_availability(scan: sqlite3.Row) -> tuple[bool, str | None]:
def finding_occurrence_rows(
- connection: sqlite3.Connection, scan_id: str, *, offset: int, limit: int
+ connection: sqlite3.Connection,
+ scan_id: str,
+ *,
+ offset: int,
+ limit: int,
+ query: str | None = None,
+ severity: str | None = None,
+ status: str | None = None,
) -> list[sqlite3.Row]:
+ conditions, values = finding_occurrence_conditions(
+ scan_id, query=query, severity=severity, status=status
+ )
return connection.execute(
- """
- SELECT id, finding_id, title, summary, severity, confidence, remediation, details_json, created_at
- FROM finding_occurrences
- WHERE scan_id = ?
+ f"""
+ SELECT
+ occurrences.id,
+ occurrences.finding_id,
+ occurrences.title,
+ occurrences.summary,
+ occurrences.severity,
+ occurrences.confidence,
+ occurrences.remediation,
+ occurrences.details_json,
+ occurrences.created_at
+ FROM finding_occurrences AS occurrences
+ LEFT JOIN finding_triage AS triage ON triage.occurrence_id = occurrences.id
+ WHERE {conditions}
ORDER BY
- CASE severity
+ CASE occurrences.severity
WHEN 'critical' THEN 0
WHEN 'high' THEN 1
WHEN 'medium' THEN 2
@@ -3055,14 +3092,44 @@ def finding_occurrence_rows(
WHEN 'informational' THEN 4
ELSE 5
END,
- created_at,
- id
+ occurrences.created_at,
+ occurrences.id
LIMIT ? OFFSET ?
""",
- (scan_id, limit, offset),
+ (*values, limit, offset),
).fetchall()
+def finding_occurrence_conditions(
+ scan_id: str,
+ *,
+ query: str | None,
+ severity: str | None,
+ status: str | None,
+) -> tuple[str, list[str]]:
+ conditions = ["occurrences.scan_id = ?"]
+ values = [scan_id]
+ if severity is not None:
+ conditions.append("occurrences.severity = ?")
+ values.append(severity)
+ if status is not None:
+ conditions.append("COALESCE(triage.status, 'open') = ?")
+ values.append(status)
+ if query:
+ search = query.strip().casefold()
+ if search:
+ conditions.append(
+ "(instr(lower(occurrences.title), ?) > 0 "
+ "OR instr(lower(occurrences.summary), ?) > 0 "
+ "OR EXISTS ("
+ "SELECT 1 FROM finding_locations AS locations "
+ "WHERE locations.occurrence_id = occurrences.id "
+ "AND instr(lower(locations.relative_path), ?) > 0))"
+ )
+ values.extend((search, search, search))
+ return " AND ".join(conditions), values
+
+
def backfill_legacy_finding_details(connection: sqlite3.Connection, scan: sqlite3.Row) -> None:
if scan["status"] != "complete" or connection.in_transaction:
return
@@ -3591,7 +3658,7 @@ def main() -> None:
)
elif args.command == "list-repositories":
result = native_indexes.list_repositories(
- connection, read_coverage=coverage_for_comparison
+ connection, args, read_coverage=coverage_for_comparison
)
elif args.command == "list-findings":
result = list_findings(connection, args)
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_native_indexes.py b/sdk/typescript/_bundled_plugin/scripts/workbench_native_indexes.py
index 79759f0af..af424a67e 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_native_indexes.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_native_indexes.py
@@ -23,9 +23,28 @@ def list_global_findings(
read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
) -> dict[str, Any]:
limit = min(args.limit, FINDINGS_PAGE_MAX)
- rows = list(
- islice(_active_findings(connection, read_coverage), args.offset, args.offset + limit + 1)
+ query = args.query.strip().casefold() if args.query else ""
+ findings = (
+ row
+ for row in _active_findings(connection, read_coverage)
+ if (args.target_id is None or row["target_id"] == args.target_id)
+ and (args.severity is None or row["severity"] == args.severity)
+ and (args.status is None or row["status"] == args.status)
+ and (
+ not query
+ or any(
+ query in value.casefold()
+ for value in (
+ row["title"],
+ row["summary"],
+ row["target_path"],
+ row["location_path"],
+ )
+ if value is not None
+ )
+ )
)
+ rows = list(islice(findings, args.offset, args.offset + limit + 1))
has_more = len(rows) > limit
return {
"findings": [
@@ -153,6 +172,7 @@ def _active_findings(
def list_repositories(
connection: sqlite3.Connection,
+ args: argparse.Namespace | None = None,
*,
read_coverage: Callable[[sqlite3.Row], dict[str, Any]],
) -> dict[str, Any]:
@@ -175,20 +195,46 @@ def list_repositories(
if row["status"] == "open"
)
targets = {row["id"]: row for row in connection.execute("SELECT * FROM security_targets")}
+ repositories = [
+ {
+ "checkoutAvailable": Path(target["current_path"]).is_dir(),
+ "displayName": target["display_name"],
+ "latestScan": latest_scan,
+ "openFindingsCount": open_findings_by_target.get(target_id, 0),
+ "scanCount": scan_count_by_target[target_id],
+ "targetId": target_id,
+ "targetPath": target["current_path"],
+ }
+ for target_id, latest_scan in latest_scan_by_target.items()
+ if (target := targets.get(target_id)) is not None
+ ]
+ if args is None:
+ return {"repositories": repositories}
+
+ query = args.query.strip().casefold() if args.query else ""
+ repositories = [
+ repository
+ for repository in repositories
+ if (args.target_id is None or repository["targetId"] == args.target_id)
+ and args.status != "not_scanned"
+ and (args.status != "open_findings" or repository["openFindingsCount"] > 0)
+ and (
+ not query
+ or query in repository["displayName"].casefold()
+ or query in repository["targetPath"].casefold()
+ )
+ ]
+ if args.limit is None and args.offset == 0:
+ return {"repositories": repositories}
+
+ limit = min(args.limit or FINDINGS_PAGE_MAX, FINDINGS_PAGE_MAX)
+ page = repositories[args.offset : args.offset + limit]
+ next_offset = args.offset + len(page)
return {
- "repositories": [
- {
- "checkoutAvailable": Path(target["current_path"]).is_dir(),
- "displayName": target["display_name"],
- "latestScan": latest_scan,
- "openFindingsCount": open_findings_by_target.get(target_id, 0),
- "scanCount": scan_count_by_target[target_id],
- "targetId": target_id,
- "targetPath": target["current_path"],
- }
- for target_id, latest_scan in latest_scan_by_target.items()
- if (target := targets.get(target_id)) is not None
- ]
+ "repositories": page,
+ "limit": limit,
+ "nextOffset": next_offset if next_offset < len(repositories) else None,
+ "offset": args.offset,
}
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_scan_history.py b/sdk/typescript/_bundled_plugin/scripts/workbench_scan_history.py
index 794439910..712575228 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_scan_history.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_scan_history.py
@@ -7,6 +7,8 @@ import sqlite3
from pathlib import Path, PurePosixPath
from typing import Any, Callable
+from workbench_constants import FINDINGS_PAGE_MAX
+
def list_workspace_scans(
connection: sqlite3.Connection,
@@ -74,7 +76,34 @@ def list_scans(
prefix = scan_root.rstrip(os.sep) + os.sep
clauses.append("(scans.scan_dir = ? OR substr(scans.scan_dir, 1, ?) = ?)")
values.extend((scan_root, len(prefix), prefix))
+ if args is not None and args.target_id:
+ clauses.append("scans.target_id = ?")
+ values.append(args.target_id)
+ if args is not None and args.mode:
+ clauses.append("scans.mode = ?")
+ values.append(args.mode)
+ if args is not None and args.status:
+ if args.status == "canceled":
+ clauses.append("scans.canceled_at IS NOT NULL")
+ else:
+ clauses.append("scans.status = ? AND scans.canceled_at IS NULL")
+ values.append(args.status)
+ if args is not None and args.query:
+ query = args.query.strip().casefold()
+ if query:
+ clauses.append(
+ "(instr(lower(scans.target_path), ?) > 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))
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
+ pagination = "LIMIT ? OFFSET ?" if paginated else ""
+ if limit is not None:
+ values.extend((limit + 1, args.offset))
rows = connection.execute(
f"""
SELECT
@@ -97,10 +126,11 @@ def list_scans(
MAX(scans.updated_at, progress.updated_at) DESC,
scans.started_at DESC,
scans.id
+ {pagination}
""",
values,
).fetchall()
- return {
+ result = {
"scans": [
{
"completedAt": row["completed_at"],
@@ -131,9 +161,18 @@ def list_scans(
"targetSummary": row["target_summary"],
"updatedAt": max(row["updated_at"], row["progress_updated_at"]),
}
- for row in rows
+ for row in rows[:limit]
]
}
+ if limit is not None:
+ result.update(
+ {
+ "limit": limit,
+ "nextOffset": args.offset + limit if len(rows) > limit else None,
+ "offset": args.offset,
+ }
+ )
+ return result
def compare_scans(