OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(snapshot): reject a destination that aliases the source database (#1138)
yi111fec09c87836c
diff --git a/plugins/codex-security/scripts/snapshot_sqlite.py b/plugins/codex-security/scripts/snapshot_sqlite.pyindex fc0982644..0678d4bda 100644--- a/plugins/codex-security/scripts/snapshot_sqlite.py+++ b/plugins/codex-security/scripts/snapshot_sqlite.py@@ -15,6 +15,9 @@ def main() -> None:args = parser.parse_args()source = args.source.expanduser().resolve(strict=True)destination = args.destination.expanduser().absolute()+ # SQLite backup cannot make progress when both connections use the same file.+ 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:with sqlite3.connect(destination) as destination_connection:diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.pyindex cf89867f9..1adafa983 100644--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py@@ -90,6 +90,38 @@ def test_sqlite_snapshot_includes_uncheckpointed_wal_rows(tmp_path: Path) -> Nonassert connection.execute("SELECT value FROM records").fetchone() == ("sealed",)[email protected]("alias_kind", ["same", "symlink", "hardlink"])+def test_sqlite_snapshot_rejects_destination_aliasing_source(+ tmp_path: Path, alias_kind: str+) -> None:+ source = tmp_path / "source.sqlite3"+ with sqlite3.connect(source) as connection:+ connection.execute("CREATE TABLE records (value TEXT NOT NULL)")+ connection.execute("INSERT INTO records VALUES ('sealed')")+ connection.commit()+ destination = source+ if alias_kind != "same":+ destination = tmp_path / "alias.sqlite3"+ if alias_kind == "symlink":+ try:+ destination.symlink_to(source)+ except OSError as error:+ pytest.skip(f"creating a symbolic link requires host support: {error}")+ else:+ destination.hardlink_to(source)+ completed = subprocess.run(+ [sys.executable, str(SNAPSHOT_SCRIPT), str(source), str(destination)],+ capture_output=True,+ text=True,+ timeout=60,+ check=False,+ )+ assert completed.returncode == 2+ assert "same file as source" in completed.stderr+ with sqlite3.connect(source) as connection:+ assert connection.execute("SELECT value FROM records").fetchone() == ("sealed",)++def test_windows_completion_lock_retries_and_unlocks(tmp_path: Path) -> None:namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_db")completion_lock = namespace["scan_completion_lock"]