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

fix(plugin): open read-only SQLite databases from Windows UNC paths (#1648)

wj972b3f344ea4
diff --git a/plugins/codex-security/scripts/snapshot_sqlite.py b/plugins/codex-security/scripts/snapshot_sqlite.py
index 0678d4bda..2f39f0509 100644
--- a/plugins/codex-security/scripts/snapshot_sqlite.py
+++ b/plugins/codex-security/scripts/snapshot_sqlite.py
@@ -6,6 +6,7 @@ from __future__ import annotations
import argparse
import sqlite3
from pathlib import Path
+from urllib.parse import quote
def main() -> None:
@@ -19,7 +20,8 @@ def main() -> None:
if destination.exists() and destination.samefile(source):
parser.error(f"Destination must not be the same file as source: {destination}")
destination.parent.mkdir(parents=True, exist_ok=True)
- with sqlite3.connect(f"{source.as_uri()}?mode=ro", uri=True) as source_connection:
+ source_uri = f"file:{quote(str(source), safe='')}?mode=ro"
+ with sqlite3.connect(source_uri, uri=True) as source_connection:
with sqlite3.connect(destination) as destination_connection:
source_connection.backup(destination_connection)
destination.chmod(0o600)
diff --git a/plugins/codex-security/scripts/workbench_scan_usage.py b/plugins/codex-security/scripts/workbench_scan_usage.py
index 685ced3df..35089c5f1 100644
--- a/plugins/codex-security/scripts/workbench_scan_usage.py
+++ b/plugins/codex-security/scripts/workbench_scan_usage.py
@@ -13,6 +13,7 @@ from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Mapping
+from urllib.parse import quote
TOKEN_FIELDS = {
"input_tokens": "inputTokens",
@@ -256,7 +257,7 @@ def _discover_rollout_sessions(
warnings: set[str],
) -> tuple[list[RolloutSession], set[str]]:
database = sqlite3.connect(
- state_database.as_uri() + "?mode=ro",
+ f"file:{quote(str(state_database), safe='')}?mode=ro",
uri=True,
timeout=STATE_DATABASE_TIMEOUT_SECONDS,
)
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 9131f16e9..dff9d0171 100644
--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
@@ -323,6 +323,22 @@ def test_sqlite_snapshot_includes_uncheckpointed_wal_rows(tmp_path: Path) -> Non
assert connection.execute("SELECT value FROM records").fetchone() == ("sealed",)
[email protected](os.name != "nt", reason="requires Win32 extended-length paths")
+def test_sqlite_snapshot_reads_windows_extended_length_source(tmp_path: Path) -> None:
+ source = tmp_path / "source.sqlite3"
+ snapshot = tmp_path / "snapshot.sqlite3"
+ with sqlite3.connect(source) as connection:
+ connection.execute("CREATE TABLE records (value TEXT NOT NULL)")
+ connection.execute("INSERT INTO records VALUES ('sealed')")
+ subprocess.run(
+ [sys.executable, str(SNAPSHOT_SCRIPT), "\\\\?\\" + str(source), str(snapshot)],
+ check=True,
+ )
+ with sqlite3.connect(snapshot) as connection:
+ assert connection.execute("SELECT value FROM records").fetchone() == ("sealed",)
+
+
@pytest.mark.parametrize("alias_kind", ["same", "symlink", "hardlink"])
def test_sqlite_snapshot_rejects_destination_aliasing_source(
tmp_path: Path, alias_kind: str