Repository navigation
Restrict Windows Named Pipe to an owner-only DACL and fail loudly on squat - #2612
Merged
Merged
Conversation
…squat
nodespaced's Named Pipe on Windows was created with the default DACL
(reachable by any local principal) and first_pipe_instance(false),
so a malicious local process could pre-create/squat the pipe name
before the daemon started, intercepting or tampering with gRPC
traffic. This breaks the ADR-052 trust model, which treats OS
socket/pipe permission as the entire local authorization boundary --
the Unix path already enforces the equivalent with bind_uds_owner_only
(0o600).
Add owner_only_security_attributes(): builds a SECURITY_ATTRIBUTES via
an SDDL descriptor (O:{sid}D:P(A;;GA;;;{sid})) granting the current
user's real SID -- and only that SID -- access, with no ACE for any
other principal. create_owner_only_pipe() wraps
ServerOptions::create_with_security_attributes_raw with this DACL, and
claims the pipe name once via first_pipe_instance(true) before the
accept loop starts (failing the whole serve_grpc/serve_headless call
if the name is already owned), then serves subsequent instances with
first_pipe_instance(false) as before.
Verified on real Windows 11 hardware via a standalone cargo binary
(same approach as the #1452 CLI fix, since the full nodespaced binary
needs libclang for nlp-engine which isn't available there): the live
pipe handle's security descriptor, read back via GetSecurityInfo, has
the current user as owner and exactly one DACL ACE with no other
principal; a second first_pipe_instance(true) claim against an
already-owned name fails with ERROR_ACCESS_DENIED, confirming the
squat-prevention path. No second real user account exists on that
machine, so true cross-user connect denial was not verified end to
end -- only that the DACL attached to the live object is the
restrictive one intended.
Closes #1498
Co-Authored-By: Claude Sonnet 5 <[email protected]>
4 tasks
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
nodespacedcreated its Named Pipe with the default DACL andfirst_pipe_instance(false)— reachable by any local principal, and squattable by a malicious process that pre-creates the pipe name before the daemon starts. This violated the ADR-052 trust model, which treats OS socket/pipe permission as the entire local authorization boundary (the Unix path already enforces the equivalent viabind_uds_owner_only's0o600).owner_only_security_attributes()— builds aSECURITY_ATTRIBUTESvia an SDDL descriptor (O:{sid}D:P(A;;GA;;;{sid})) that sets the owner to the current user's real SID and grants that same SID — and only that SID — access. No ACE forEveryone/Authenticated Users/any other principal, so they're implicitly denied.create_owner_only_pipe(name, first_instance), which wrapsServerOptions::create_with_security_attributes_rawwith that DACL. The instance that claims the pipe name now does so withfirst_pipe_instance(true)before the accept loop starts —serve_grpc/serve_headlessfail loudly at startup if the name is already owned/squatted — and every subsequent instance in the accept loop (serving the next client after the current one disconnects) usesfirst_pipe_instance(false), since that flag only ever succeeds for the very first instance of a name.serve_headless,serve_grpc) now share this helper instead of duplicating the oldServerOptions::new().first_pipe_instance(false).create(&name)call with its "SECURITY GAP" comment.#[cfg(all(test, windows))]test module (pipe_permission_tests) covering: the SID lookup, DACL construction, claiming an unused name, a secondfirst_pipe_instance(true)claim failing against an already-owned name, normal serial-reconnect (first_pipe_instance(false)) still working, and a live-handle DACL readback assertion (owner + exactly one ACE + no other principal).Real Windows verification
The full
nodespacedbinary can't build on the available Windows 11 box (nolibclangfornodespace-nlp-engine'sllama-cpp-sys-2bindgen), so — same approach as the #1452 CLI fix (PR #2610) — I extracted the exact code above into a standalonecargo new --binscratch project (onlytokio+windows-sysdeps, no heavy crates) and validated it for real over SSH on the actual machine. Two builds were done: an iterative dev build, and a verbatim copy-paste of the final production code (lines 207–398 ofpackages/daemon/src/main.rs, unmodified) to rule out any transcription drift between the two.1. DACL is genuinely attached to the live pipe handle (read back via
GetSecurityInfo+ConvertSecurityDescriptorToStringSecurityDescriptorW— the same Win32 APIicacls/Get-Aclthemselves use):(
FA=FILE_ALL_ACCESS, the object-type-specific right Windows resolvesGENERIC_ALLinto for a pipe/file object when it constructs the descriptor — expected, not a discrepancy.)2.
first_pipe_instance(true)genuinely rejects a pre-squatted name (the exact attack scenario from the issue: a process pre-creates the pipe, then the legitimate daemon start attempts to claim it):3. Normal serial-reconnect flow still works once the name is legitimately claimed:
4.
icacls/Get-Aclas external tooling: attempted both against the live pipe path.icacls \\.\pipe\<name>returnedERROR_PIPE_BUSY(231) against a single not-yet-.connect()-ed instance, and PowerShell'sGet-Acldoesn't resolve\\.\pipe\UNC-style paths through its default FileSystem provider at all (Cannot find path ... FileSystem::\\.\pipe\...). Both are real, environment-level limitations of those specific tools against a single live pipe instance, not something the fix could route around — the programmaticGetSecurityInfoquery above uses the identical underlying Win32 API and is authoritative.5. The exact production code, copied verbatim (not retyped), compiles and passes on the real machine:
Honest verification gap: this Windows box has only one real usable local account (
tomar) — no second real user account exists to test true cross-user connect denial end to end (i.e. actually attempting to open the pipe as a genuinely different Windows identity and observingERROR_ACCESS_DENIED). What was verified, directly and programmatically, is that the security descriptor attached to the live kernel object is exactly the restrictive one intended (current user as owner, exactly one ACE, no ACE for any other principal) — which is the same descriptor the OS access-check evaluates against any other principal's connection attempt. Creating a second account on this physical machine was out of scope (a prior session's attempt to install system software there was explicitly blocked pending human sign-off; the same reasoning applies to provisioning a new user account, so I didn't attempt it).Test plan
bun run test:all— clean, zero failures (frontend, scripts, skill, full Rust workspace includingnodespace-daemon's existing Unix-side tests)bun run quality:fix— clean (eslint/svelte-check/tsc/cargo fmt/cargo clippy --all-targets -- -D warnings -D clippy::unused-async, all zero warnings)cargo check -p nodespace-daemonon macOS (validates everything except the#[cfg(windows)]code, which is necessarily excluded on this host)scripts/test-gate.ts) passed in full, includingcargo build --bin nodespacedandtest:e2e, rebased onto currentmainCloses #1498
🤖 Generated with Claude Code