Set Windows DACL on discovery directory under LOCALAPPDATA#5951
Open
stantheman0128 wants to merge 1 commit into
Open
Set Windows DACL on discovery directory under LOCALAPPDATA#5951stantheman0128 wants to merge 1 commit into
stantheman0128 wants to merge 1 commit into
Conversation
os.Chmod is advisory on NTFS, so the discovery directory under %LOCALAPPDATA% could keep inherited ACEs (Everyone, other interactive users). A local attacker who can write server.json can redirect the npipe URL and steal the discovery nonce on the next health check. On Windows, replace the directory DACL with a protected ACL granting GenericAll only to the process user and SYSTEM (create and existing-dir paths). Non-Windows keeps os.Chmod. Windows tests assert no other interactive users remain; POSIX mode assertions skip on Windows. Fixes stacklok#5217 Signed-off-by: stantheman0128 <stanshih888@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
writeServerInfoTocreates the discovery directory underxdg.StateHome(%LOCALAPPDATA%on Windows) withos.MkdirAll+os.Chmod(0700). On NTFS those POSIX modes are advisory: inherited ACEs from the parent (Everyone, other interactive users, Administrators) remain. Combined with thenpipe://discovery URL from #5201 / #5214, a local attacker who can rewriteserver.jsoncan point the nextthv servehealth check at their own pipe and capture the discovery nonce.This change sets an explicit protected DACL on Windows after
MkdirAll, granting GenericAll only to the process user and SYSTEM (with OICI soserver.jsoninherits the same restriction). Non-Windows keepsos.Chmod. Sibling paths covered: new directory create, and replace (not merge) on an existing loose directory.Fixes #5217
Type of change
Test plan
go test ./pkg/server/discovery/focused suite on Windows 11)task test-e2e)task lint-fix;tasknot installed locally;go vet ./pkg/server/discovery/clean)Verification / Evidence
HEAD bug (os.Chmod leaves Everyone):
Unit tests (Windows 11, go1.26.0):
Product path (real
%LOCALAPPDATA%viaXDG_STATE_HOME, publicdiscovery.WriteServerInfo):Before (Everyone + Administrators still on the discovery dir):
After
WriteServerInfo:go vet ./pkg/server/discovery/: clean.What was not tested
task test/task lint-fix(Task not installed on this machine; CI on ubuntu covers the package).thv servestartup rewrites viaWriteServerInfo).API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
pkg/server/discovery/discovery.gorestrictDiscoveryDirPermissionsafterMkdirAllpkg/server/discovery/permissions_windows.goSetNamedSecurityInfopkg/server/discovery/permissions_other.goos.Chmodpkg/server/discovery/permissions_windows_test.gopkg/server/discovery/discovery_test.goDoes this introduce a user-facing change?
On Windows, the discovery directory under
%LOCALAPPDATA%\...\toolhive\serveris locked down to the user that startedthvplus SYSTEM. No CLI flag or config change.Special notes for reviewers
npipe://URL.Made with Cursor