feat(companion): Phase 2 loopback endpoint security core (pure request-guard)
Add lib/companion-loopback-guard.mjs — a pure, I/O-free request-decision core (verifyLoopbackRequest) enforcing gate §4 loopback controls 1,2,3,5,6,8 at the request-decision level, plus rate-state helpers and a constant-time token comparator. No socket is bound: the gate's "DOES NOT approve" list still forbids opening a local HTTP listener, so the bind is deferred to Phase 5 behind an explicit gate (mirrors how Phase 1 shipped pure, tested decision logic).
Security properties (all fail-closed): strict Host allowlist + loopback-only check (DNS-rebinding defense), cross-site Origin/Sec-Fetch-Site rejection with no wildcard CORS / no Origin reflection, constant-time bearer-token compare, sliding-window rate limit ordered to bound brute-force without enabling a budget-exhaustion DoS, no ambient authority (verdict is the only output), note body never read (prompt-injection cannot alter the decision), and no token/JWT/ note body in any reason, return value, or thrown error.
7-tier test suite (test/companion-loopback-guard-*.test.mjs, 102 cases, green): unit, integration, e2e, stress, data-integrity, performance, and the security centerpiece (missing/wrong token, DNS-rebinding, cross-origin, rate-limit, no ambient authority, note-body-as-data, no-secret-in-output, global fail-closed).
docs/COMPANION-APP-PHASE-2-LOOPBACK-SECURITY.md records the accepted design, the adversarial threat model -> control mapping, the guard contract, and what Phase 5 must do to bind the socket safely.
Refs: gate §4, §10, §13; Phase 1 adapter seam.
Semantic Changes
44 symbols
0 comments
muse hub commit comment sha256:edea42a90bef97963a66d35a47cb95a157c8b8469f11c4be01cedcfb9e0701ad --body "your comment"
No comments yet. Be the first to start the discussion.