#19389: Fix #2248: Allow insecure auth bypass when device signature validation fails
gateway
size: M
Cluster:
Device Auth and Security Fixes
## Problem
`gateway.controlUi.allowInsecureAuth: true` doesn't prevent device signature validation, preventing fallback to password/token auth as documented.
## Root Cause
Gateway validates device signatures and rejects stale signatures without falling back to password/token authentication when `allowInsecureAuth` is enabled.
## Solution
When `allowInsecureAuth` is enabled AND shared auth (password/token) is available, skip device auth entirely by setting `device = null`.
## Files Modified
- `src/gateway/server/ws-connection/message-handler.ts`
- `src/gateway/server/ws-connection/message-handler.bug-2248.test.ts` (new test file)
## Test Coverage
Test suite includes:
- Control UI with allowInsecureAuth and stale device signature
- Token auth fallback
- Behavior when allowInsecureAuth is disabled
- Behavior when no shared auth is provided
- Shared auth priority verification
All tests passing ✅
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes issue #2248 where `gateway.controlUi.allowInsecureAuth: true` was not working as documented because stale device signatures were being rejected before the fallback to password/token auth could occur. The fix adds a `skipDeviceAuthForInsecure` flag that sets `device = null` early in the handshake when `allowInsecureAuth` is enabled and shared auth credentials are present, causing the rest of the device-auth validation block to be skipped.
**Key findings:**
- **Logic change is minimal and largely correct** — the one-line change to `message-handler.ts` fixes the described bug. The final `if (!authOk)` guard (line 651) ensures connections with invalid credentials are still rejected, so there is no direct authentication bypass.
- **Device auth is bypassed based on credential *presence*, not validity** — `hasSharedAuth` is evaluated before any credential validation occurs. When `allowInsecureAuth: true`, any connection that includes any non-empty token or password value (even an incorrect one) will have device validation stripped from the auth flow. This weakens defense-in-depth: an observer who knows `allowInsecureAuth` is configured can force the server into the password/token-only code path without knowing valid credentials. The bypass ideally should only activate once `sharedAuthOk` is confirmed valid (i.e., after `authorizeGatewayConnect`).
- **The new test file provides no real regression coverage** — all five tests make trivial assertions on plain JavaScript objects they just constructed; none of them import or invoke `attachGatewayWsMessageHandler`. The tests would pass even if the fix in `message-handler.ts` were fully reverted. A proper test should follow the pattern already established in `src/gateway/server.auth.e2e.test.ts` (e.g., the "stale device identity when device auth is disabled" test at line 688) but using `allowInsecureAuth: true` and a stale device signature paired with a valid shared secret.
<h3>Confidence Score: 2/5</h3>
- The production logic change is small and not a direct auth bypass, but the bypass decision is made before credential validity is confirmed and the accompanying tests provide no real regression coverage.
- Score reflects two concerns: (1) the device-auth bypass is gated on credential *presence* rather than *validity*, which weakens defense-in-depth even though the final authOk check still rejects invalid credentials; (2) the test suite is entirely non-functional — every assertion is trivially true regardless of what the handler code does, so there is no automated protection against regressions in this fix.
- Pay close attention to `src/gateway/server/ws-connection/message-handler.ts` (lines 348–350, the bypass decision timing) and `src/gateway/server/ws-connection/message-handler.bug-2248.test.ts` (tests do not exercise real handler code).
<sub>Last reviewed commit: 1c216f9</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17705: fix(gateway): allow trusted-proxy auth to bypass device-pairing gates
by dashed · 2026-02-16
84.7%
#17378: fix(gateway): allow dangerouslyDisableDeviceAuth with trusted-proxy...
by ar-nadeem · 2026-02-15
84.4%
#17605: fix: preserve scopes when disableControlUiDeviceAuth is enabled
by MisterGuy420 · 2026-02-16
83.2%
#20089: fix(gateway): preserve control-ui scopes when dangerouslyDisableDev...
by vashkartik · 2026-02-18
82.0%
#17572: fix: make dangerouslyDisableDeviceAuth bypass device identity checks
by gitwithuli · 2026-02-15
81.4%
#19937: fix(gateway): validate token/password auth modes and isolate gatewa...
by NewdlDewdl · 2026-02-18
81.4%
#19885: test(gateway,browser): isolate tests from ambient OPENCLAW_GATEWAY_...
by NewdlDewdl · 2026-02-18
81.1%
#16310: fix(ws-connection): skip device pairing when client authenticates w...
by nawinsharma · 2026-02-14
79.8%
#23361: Gateway: reject scope assertions without identity binding
by bmendonca3 · 2026-02-22
79.4%
#15722: fix: prefer explicit token over stored device token for remote gate...
by 0xPotatoofdoom · 2026-02-13
79.3%