fix(security): restrict Windows private files to the current user - #148
fix(security): restrict Windows private files to the current user#148raymondginger2018-sudo wants to merge 1 commit into
Conversation
On Windows, POSIX mode bits are ignored, so credentials.json and other private state inherited the permissive profile ACL (Authenticated Users typically gets Modify). An attacker with a foothold could read API keys from a file that only the process *thought* was private. - private_storage._restrict_windows_acl: removes inherited ACEs with icacls /inheritance:r, then grants the current user exclusive full control (/grant:r <user>:F). Best-effort like POSIX chmod. - _windows_identity: resolves DOMAIN\user via whoami (machine or domain). - open_private_file now applies the ACL on Windows (previously skipped). - harden_private_tree walks and repairs ACLs on Windows too (previously bailed out early). - icacls/whoami output decoded as mbcs (Windows OEM codepage) to avoid UnicodeDecodeError on CJK systems. Adds tests/test_private_storage_windows.py: directory, file, and current-user grant assertions (skipped on POSIX).
|
Merged as
It is also intermittent — the same tree passed the Windows job on the PR branch and failed on There is a second issue worth folding in: with the Windows early-return removed from Two changes would make me comfortable merging this:
The underlying point stands — POSIX mode bits are ignored on Windows and |
On Windows, POSIX mode bits are ignored, so
credentials.jsonand other private state inherited the permissive profile ACL (Authenticated Users typically gets Modify). An attacker with a foothold could read API keys from a file the process thought was private.Fix
private_storage._restrict_windows_acl: removes inherited ACEs (icacls /inheritance:r) then grants the current user exclusive full control (/grant:r <user>:F). Best-effort, mirroring POSIX chmod semantics._windows_identity: resolves the fully-qualified principal viawhoami.open_private_filenow applies the ACL on Windows (previously skipped the whole branch).harden_private_treewalks and repairs ACLs on Windows too (previously bailed out early).mbcs(OEM codepage) to avoid UnicodeDecodeError on CJK systems.Tests
tests/test_private_storage_windows.py: directory restricted, file restricted, current-user grant retained. Runs on Windows only; skipped on POSIX.