Repository navigation
fix(data): harden Windows WAL/SHM sidecars before SQLite writes them (#1559) - #1611
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…ect (#1559) Signed-off-by: deepslit <731369471@qq.com>
…ver delete them (#1559) Run the pre-create and harden pass for -wal/-shm a second time after PRAGMA journal_mode = WAL and before apply_migrations, so sidecars that another connection's last close removed after the first pass are recreated empty and owner-only before SQLite writes to them. On a fresh database the first migration write is what creates the sidecars, so the pass pre-creates them rather than only hardening existing files. Drop the empty-sidecar cleanup on a failed open: a -wal can hold another connection's committed frames, and a size check cannot be made atomic with the unlink. An empty owner-only sidecar is reused by SQLite on the next open.
…ation (#1559) Creating an empty file and restricting it with icacls afterwards left a window in which the file carried its directory's inherited ACL; a handle another account opened then keeps working after the ACL changes and reads what SQLite later writes. winsec.create_owner_only_file creates the file with CreateFileW, CREATE_NEW and a protected DACL granting only the current user, the same ACL harden_files_once applies, without following a symlink. A new gflow.db and the pre-created -wal/-shm use it; harden_files_once stays as the second line. A failed sidecar create now logs data_store_sidecar_create_failed instead of file_acl_failed.
…back window (#1559) Declare argtypes and restype for CloseHandle and ConvertStringSecurityDescriptorToSecurityDescriptorW so a handle value above 2**31 is passed as a HANDLE instead of raising ctypes.ArgumentError. Add a test that create_owner_only_file refuses a dangling symlink at the target name without creating the link target, and state in SECURITY.md that the plain-create fallback for a new gflow.db reopens the inherited-ACL window.
Move the ctypes CreateFileW body into gflow_cli._win_owner_only, which winsec.create_owner_only_file delegates to after resolving the user SID, and exclude that native glue from the coverage metric: the Linux runner that measures coverage cannot reach it, while the Windows CI job runs the real-ACL tests against it. Cover the store's Windows branches with tests that pretend to be Windows and stub the owner-only create and the ACL pass: the call order around connect and the WAL pragma, the plain-create fallback and its log event, the existing-file refusal, and a sidecar lost to a concurrent create. Cover the winsec delegate the same way.
e4c5ca8 to
cbef85a
Compare
|
Evidence. No Flow surface (local SQLite files). Windows ACL tests: Reviews. CodeRabbit: rate limited; the two earlier CodeRabbit findings on #1566 are addressed (second hardening pass; no deletion of sidecars). |
Takes over #1566 by @deepslit, whose commit is kept with its authorship.
Problem
On Windows, SQLite creates
gflow.db-walandgflow.db-shmduringconnectand the first writes. Until the second hardening pass inDataStore.open, those files carry the parent directory's inherited ACL. WithGFLOW_CLI_DB_PATHin a shared directory, another account can open a handle in that window, and Windows keeps honouring a handle opened before the ACL is tightened (#1559).Fix
sqlite3.connect, absent-waland-shmfiles beside the database are created empty with an exclusive create (no dangling-symlink follow) and hardened owner-only; SQLite reuses existing sidecar files (measured: same file identity throughconnect,journal_mode = WALand the first write, fresh and reopened).PRAGMA journal_mode = WALand before migrations, so a sidecar removed by another connection's close is recreated restricted before the first write. The pass after migrations is kept.Tests
test_open_hardens_windows_sidecars_before_sqlite_connects(red without the fix:gflow.db-walmissing).test_open_restricts_sidecars_a_concurrent_close_removed_before_first_write[fresh|reopen](red before the second pass: file missing / inheritedEveryone:(I)(R)).test_failed_open_never_deletes_a_sidecar.tests/data+tests/auth/test_windows_acl.py: 237 passed, 13 skipped (Windows). Twelve local gates green.No Flow surface: local SQLite files only; the Windows ACL tests are the evidence.
Closes #1559
🤖 Generated with Claude Code
Summary by CodeRabbit