Skip to content

Restrict Windows Named Pipe to an owner-only DACL and fail loudly on squat - #2612

Merged
mstomar125 merged 1 commit into
mainfrom
issue-1498-windows-pipe-acl
Sep 14, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-1498-windows-pipe-acl

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

  • On Windows, nodespaced created its Named Pipe with the default DACL and first_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 via bind_uds_owner_only's 0o600).
  • Adds owner_only_security_attributes() — builds a SECURITY_ATTRIBUTES via 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 for Everyone/Authenticated Users/any other principal, so they're implicitly denied.
  • Adds create_owner_only_pipe(name, first_instance), which wraps ServerOptions::create_with_security_attributes_raw with that DACL. The instance that claims the pipe name now does so with first_pipe_instance(true) before the accept loop starts — serve_grpc/serve_headless fail 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) uses first_pipe_instance(false), since that flag only ever succeeds for the very first instance of a name.
  • Both Windows server loops (serve_headless, serve_grpc) now share this helper instead of duplicating the old ServerOptions::new().first_pipe_instance(false).create(&name) call with its "SECURITY GAP" comment.
  • Updates the file-level ADR-052 trust-model doc comment to describe the new Windows guarantee instead of the open gap.
  • Adds a #[cfg(all(test, windows))] test module (pipe_permission_tests) covering: the SID lookup, DACL construction, claiming an unused name, a second first_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 nodespaced binary can't build on the available Windows 11 box (no libclang for nodespace-nlp-engine's llama-cpp-sys-2 bindgen), so — same approach as the #1452 CLI fix (PR #2610) — I extracted the exact code above into a standalone cargo new --bin scratch project (only tokio + windows-sys deps, 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 of packages/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 API icacls/Get-Acl themselves use):

== pipe name: \\.\pipe\nodespace-pipe-acl-test-3176
== current user SID: S-1-5-21-1987453910-4036614234-2231979812-1001

--- TEST 1: DACL is actually attached to the created pipe ---
created first instance with owner-only DACL + first_pipe_instance(true): OK
live handle security descriptor (SDDL): O:S-1-5-21-1987453910-4036614234-2231979812-1001D:P(A;;FA;;;S-1-5-21-1987453910-4036614234-2231979812-1001)
owner is current user: true; has ALLOW ACE for current user SID only: true; total ACE count in DACL: 1 (expected 1); no Everyone/Authenticated-Users/other-principal ACE: true

(FA = FILE_ALL_ACCESS, the object-type-specific right Windows resolves GENERIC_ALL into 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):

--- TEST 2: first_pipe_instance(true) rejects a pre-squatted name ---
squatter pre-created \\.\pipe\nodespace-pipe-acl-test-squat-3176: OK (simulating a malicious pre-existing pipe)
legitimate first_pipe_instance(true) create FAILED as expected: Access is denied. (os error 5) (raw os error: Some(5))

3. Normal serial-reconnect flow still works once the name is legitimately claimed:

--- TEST 3: normal serial-reconnect flow still works after the first claim ---
second instance on the already-claimed name with first_pipe_instance(false): OK

4. icacls/Get-Acl as external tooling: attempted both against the live pipe path. icacls \\.\pipe\<name> returned ERROR_PIPE_BUSY (231) against a single not-yet-.connect()-ed instance, and PowerShell's Get-Acl doesn'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 programmatic GetSecurityInfo query 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:

   Compiling pipe-acl-scratch v0.1.0 (C:\dev\pipe-acl-scratch)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.15s
     Running `target\debug\pipe-acl-scratch.exe`
== pipe name: \\.\pipe\nodespace-pipe-acl-prodcheck-15036
== current user SID: S-1-5-21-1987453910-4036614234-2231979812-1001
created first instance with owner-only DACL + first_pipe_instance(true): OK
squatter pre-created \\.\pipe\nodespace-pipe-acl-prodcheck-squat-15036: OK
legitimate first_pipe_instance(true) against squatted name: FAILED as expected
Production-code verification build: all checks passed.

running 6 tests
test pipe_permission_tests::current_user_sid_string_returns_a_real_sid ... ok
test pipe_permission_tests::owner_only_security_attributes_builds_a_non_null_descriptor ... ok
test pipe_permission_tests::create_owner_only_pipe_claims_an_unused_name ... ok
test pipe_permission_tests::create_owner_only_pipe_first_instance_false_succeeds_after_the_name_is_claimed ... ok
test pipe_permission_tests::create_owner_only_pipe_first_instance_true_fails_against_an_already_owned_name ... ok
test pipe_permission_tests::owner_only_dacl_is_actually_attached_to_the_live_pipe_handle ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

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 observing ERROR_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 including nodespace-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-daemon on macOS (validates everything except the #[cfg(windows)] code, which is necessarily excluded on this host)
  • Real Windows 11 hardware verification (see above) — DACL construction, live-handle readback, squat-prevention, and normal-reconnect all confirmed with real command + output evidence, including a verbatim copy of the shipped production code
  • Pre-push gate (scripts/test-gate.ts) passed in full, including cargo build --bin nodespaced and test:e2e, rebased onto current main

Closes #1498

🤖 Generated with Claude Code

…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]>
@mstomar125
mstomar125 merged commit 74d97a1 into main Sep 14, 2026
@mstomar125
mstomar125 deleted the issue-1498-windows-pipe-acl branch September 14, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows Named Pipe has no ACL and is squattable

1 participant