Skip to content

Socket peer authentication on the in-app browser's cua socket (cua board #95) - #7

Merged
SSFSKIM merged 10 commits into
masterfrom
95-socket-peer-auth
Oct 10, 2026
Merged

SSFSKIM merged 10 commits into
masterfrom
95-socket-peer-auth

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

MAWS side of SSFSKIM/cua#95 (socket peer authentication). The spec lives in the cua repository: docs/doperpowers/specs/2026-10-09-maws-socket-peer-auth-design.md on SSFSKIM/cua branch spec/socket-peer-auth-95, opened as the companion cua PR. Merge this PR first. The cua PR merges after it.

What changes

The per-session cua socket, <userData>/browser/cua/<appSessionId>.sock, now checks every peer when it connects, before it reads a byte or sends the hello. It admits a peer only if two things hold. The peer runs as MAWS's user. And it descends from the session's engine process instance: the session.status pid, stored with its start time and re-checked every time. Before this change, any same-user process that named the path got every cua primitive.

  • native/peer-auth/ is a small N-API addon: one C file over LOCAL_PEERPID, getpeereid and proc_pidinfo. Its darwin-arm64 prebuild is committed, rebuilt by scripts/build-peer-auth.sh (pnpm build:peer-auth), and is byte-identical to cua's copy. electron-builder.yml copies it to Resources/peer-auth.
  • src/main/browser/cua/peer.ts holds the loader and the ancestry policy. A peer is refused for one of five reasons: module_unavailable, peer_unavailable, uid_mismatch, no_root or not_descendant. The peer is read again after the ancestry walk, and a peer whose start time is later than the accept is refused.
  • src/main/browser/cua/index.ts:
    • The server uses pauseOnConnect and the socket file is 0600.
    • A peer that arrives before the engine's first status waits up to 3 s for it.
    • A refused peer is destroyed and writes one log line with its pid and reason.
    • If the addon is missing, every peer is refused. It does not fall back to accepting.
    • inspect() gains peerModule and a per-session refused count.
  • src/main/browser/index.ts feeds every known session's session.status pid to engineProcess.
  • An e2e seam, trustRoot, exists only in main under MAWS_E2E=1. There is no IPC change and no version slot moves.
  • e2e:browser-cua gains scene 6 (an orphaned same-user connector is refused before the hello) and scene 7 (a stub engine's own child is admitted on the real status.pid path). e2e/smoke.spec.ts asserts peerModule === 'loaded' in the packaged app.
  • The tracker's E13 row is amended, not closed. It now states the boundary and the accepted residual: engine descendants, configuration-injected code, the SIGUSR1 inspector routes and the supervisor token route.

Validation Evidence

  • Typecheck and lint: pnpm typecheck && pnpm lint exit 0 (M2 executor; re-run by the whole-branch reviewer at 5178d7f).

  • Unit tests: pnpm test gave 11033 passed and 3 failed at 36cea2a. The failures are in the tracker's known-flaky src/main/sessions/pause-take-over.pty.test.ts and in one remote-runner grandchild-cancel case. Both files pass alone, 27/27. Focused suites (peer, admission, cua/index, browser/index) gave 65/65 at the branch head.

  • e2e browser-cua: pnpm e2e:browser-cua at 5178d7f gave 7 passed (33.6s), exit 0. Scene 6 is "an orphaned connector is refused, the trusted host keeps its connection"; scene 7 is "the connector its engine starts hears the hello, on the engine's pid from the session's status".

  • e2e browser: pnpm e2e:browser gave 8 passed (M2).

  • Packaged: pnpm build:app && pnpm e2e:packaged at 5178d7f gave 61 passed, 140 skipped (4.0m), exit 0. That run includes the smoke assertion peerModule === 'loaded', and dist/mac-arm64/MAWS.app/Contents/Resources/peer-auth/peer-auth.node is present.

  • Addon identity: diff of the two repositories' native/peer-auth/peer-auth.c prints nothing, and cmp of the two prebuilds prints nothing. SHA-256 is 5c94d2b4… for the source and 9de92f2c… for the prebuild. A reviewer rebuilt the addon from source with the script's flags and got the same bytes.

  • Reviews: each milestone was reviewed by reviewer-medium and the whole branch by reviewer-high, all on opus. Every verdict was correct. The two P3 findings are fixed: the shell quoting in the e2e scenes (8ab7258) and the PR-number placeholder in the tracker row (filled after this PR opened).

  • After the SIGUSR1 follow-up and the merge of master 8f43ab9 (at 0a0214e, every e2e group run through the quiet wrapper, MAWS_E2E_QUIET=1):

    • typecheck and lint exit 0.
    • pnpm test gave 11446 passed (at 0b6ea59); the only failure was the known pty flake, which passes alone.
    • src/main/hosts plus detached.test.ts gave 134/134.
    • build:app exit 0.
    • e2e:packaged gave 64 passed, 142 skipped, including sigusr1.spec.
    • e2e:supervisor:packaged gave 1 passed.
    • e2e:browser-cua gave 7/7.
  • Follow-up review: reviewer-medium on opus found a P2 (a false pass while 9229 is held) and a P3 (the supervisor's startup window). Both are fixed in 0a0214e.

SIGUSR1 in MAWS main and the supervisor (2026-10-10, the spec owner's decision)

The spec asked whether MAWS main answers SIGUSR1. It does: dev and packaged main, and the detached supervisor (the app binary run as Node), each opened an inspector on 127.0.0.1:9229. That route goes around this check entirely. This branch now closes it:

  • Main: a no-op process.on('SIGUSR1', () => {}) beside guardStdio in src/main/index.ts. The remaining window is process start until that line runs, after the module bodies are evaluated; main cannot take a flag.
  • Supervisor: spawned with --disable-sigusr1 (src/main/hosts/detached-transport.ts), so it is closed from exec, and the listener stays at its entry.
  • Tests:
    • e2e/sigusr1.spec.ts (dev and packaged) signals a main process the case launched itself, because Playwright's --inspect=0 would mask the result.
    • The packaged supervisor spec signals its own supervisor and asserts the flag on its command line.
    • Both specs fail up front if 127.0.0.1:9229 is already held, and both reject any inspector line in main's stderr or the supervisor's host.log.
    • Both failed before the fix (9229 opened) and pass after.
  • Still MAWS-wide decisions in the tracker: the fuses EnableNodeCliInspectArguments, EnableNodeOptionsEnvironmentVariable and OnlyLoadAppFromAsar.

Tracker

The E13 row is unchanged from master, because P2-F edits rows by script. The amendment is one new dated row appended at the end of docs/tech-debt-tracker.md, naming the row it amends (2026-10-08, E13, "Security note: the cookie-jar…"), cua board #95 and this PR.

Residue

  • The Electron fuses EnableNodeCliInspectArguments, EnableNodeOptionsEnvironmentVariable and OnlyLoadAppFromAsar. These are MAWS-wide decisions; the SIGUSR1 route itself is closed on this branch.
  • The supervisor's 0600 token file (src/engine-host/detached.ts). Any same-user process can read it and take over the supervisor and the session's engine. This is a MAWS-wide authorization question.
  • --strict-mcp-config or narrower --setting-sources for the engine launch. Configuration-injected hooks and MCP servers are admitted as engine descendants. Changing that is a charter decision against §4.1's launch line.
  • The remote-runner grandchild-cancel flake. It failed once in a full pnpm test run under load and passes alone. It is not yet in the tracker.

…ted darwin-arm64 prebuild, scripts/build-peer-auth.sh, node-api-headers), the loader and policy in src/main/browser/cua/peer.ts with Acceptance 1 and 2, the extraResources entry
…nConnect, 0600, the session's engine as a process-instance root from every status, a 3 s wait for it, refusal destroyed unread with one log line, fail closed without the addon), inspect() gains peerModule and per-session refused, the MAWS_E2E trustRoot seam, Acceptance 3 and 4 unit tests, browser-cua scenes 6 (orphan refused) and 7 (a stub engine's child let in), the packaged peerModule assertion, the SIGUSR1 finding in the tracker's E13 row
… to the shell as arguments (the orphan's sh -c) or quoted as plugin-cli-stub.ts quotes them (the engine wrapper), never pasted inside quotes
…both sockets now enforce, the accepted residual in the spec's words, the SIGUSR1 and supervisor-token routes, the follow-ups that remain)
…isor install a no-op SIGUSR1 listener at their entries, so a same-user kill -USR1 opens no Node inspector (a route around the cua socket's peer check); e2e/sigusr1.spec.ts signals a main the case starts itself (dev or packaged), the packaged supervisor spec signals its supervisor
…endment (cua board #95, MAWS PR #7) as a new dated row at the end, with SIGUSR1 in MAWS main and the supervisor closed by the 2026-10-10 listener
…able-sigusr1 (closed from exec on, the listener kept); both SIGUSR1 checks fail while 127.0.0.1:9229 is taken and reject any inspector line in main's stderr and the supervisor's host.log; the new tracker row names main's remaining startup window
@SSFSKIM
SSFSKIM merged commit a82d821 into master Oct 10, 2026
SSFSKIM added a commit that referenced this pull request Oct 10, 2026
…52 amendment (socket peer authentication by process ancestry), the P1 ledger's §6 clause for native/peer-auth and its §5 row's inert field, the charter's §19 line
SSFSKIM added a commit that referenced this pull request Oct 10, 2026
cua #103 e2e: the 380 px human-control case trusts the test process before connecting as the fake host (PR #7 and #9 crossed)
SSFSKIM added a commit that referenced this pull request Oct 19, 2026
…act resolves as a handle, so a UUID-shaped handle reads back and collides as any handle does
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.

1 participant