#22227: fix(security): harden gateway auth — audit logging, pairing, mode validation
gateway
size: S
Cluster:
Security Enhancements and Fixes
## Summary
- **CRITICAL-1**: Add audit logging to loopback request classification in `isLocalDirectRequest()` to detect potential auth bypass when gateway is LAN-bound
- **CRITICAL-2**: Remove silent auto-approval of device pairing for local clients — all pairing now requires explicit user confirmation
- **CRITICAL-3**: Block auth mode "none" on non-loopback binds at startup (defense-in-depth against untyped JSON config)
## Test plan
- [ ] Verify gateway startup rejects `auth.mode=none` on LAN bind
- [ ] Verify device pairing always prompts for confirmation (no silent auto-approve for local clients)
- [ ] Verify loopback requests emit `[SECURITY AUDIT]` log line
- [ ] `pnpm check` passes
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Hardens gateway authentication with three defense-in-depth security improvements: adds audit logging for loopback request classification to detect potential auth bypass, removes silent auto-approval of device pairing for local clients requiring explicit user confirmation for all pairing requests, and blocks `auth.mode=none` on non-loopback binds at startup.
- **CRITICAL-1** (auth.ts:116-121): audit logging detects loopback requests classified as local/trusted, helping identify potential auth bypass when gateway is LAN-bound
- **CRITICAL-2** (message-handler.ts:656-676): removed automatic pairing approval for local clients — all device pairing now requires explicit user confirmation, preventing co-located processes from pairing without authorization
- **CRITICAL-3** (server-runtime-config.ts:111-119): prevents `auth.mode=none` on non-loopback binds, providing defense-in-depth against untyped JSON config smuggling insecure auth mode
Minor style issue: comment on line 112 is inaccurate (type actually includes `"none"`) and type cast on line 114 is unnecessary but harmless.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk — implements critical security hardening for gateway authentication
- Three well-scoped security improvements with clear defense-in-depth benefits. The changes are additive (audit logging), restrictive (blocking insecure configs), and correctness-focused (removing unsafe auto-approval). Only minor style issues with an inaccurate comment and unnecessary type cast that don't affect functionality. No breaking changes to secure configurations.
- No files require special attention — all changes are security improvements
<sub>Last reviewed commit: c877c51</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#7654: feat(security): zero-trust localhost auth with DNS rebinding protec...
by joncode · 2026-02-03
81.6%
#21697: fix(gateway): unblock local spawn pairing and gated private-LAN ws
by rjuanluis · 2026-02-20
81.3%
#22712: fix(gateway): auto-approve all device pairing for localhost connect...
by NewdlDewdl · 2026-02-21
81.2%
#14197: fix(security): harden browser API auth, token comparisons, and hook...
by leecarollyn-gif · 2026-02-11
80.7%
#21964: Security: harden gateway and plugin trust boundaries
by Elormyevu · 2026-02-20
80.6%
#21326: Security/UI: harden Control UI gatewayUrl URL overrides
by bmendonca3 · 2026-02-19
80.4%
#22381: Security/Gateway: block cross-origin silent auto-pairing in auth mo...
by bmendonca3 · 2026-02-21
80.3%
#22766: fix(security): enable gateway auth rate limiting by default (CWE-307)
by brandonwise · 2026-02-21
79.9%
#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
by mdanassaif · 2026-02-17
79.9%
#23690: fix(gateway): subagent sessions fail with pairing required on loopb...
by yinghaosang · 2026-02-22
79.8%