#16963: fix: enable auth rate limiting by default
gateway
stale
size: XS
## Summary
- Auth rate limiter was only created when explicitly configured, leaving the gateway unprotected by default
- Changed to always create a rate limiter with sensible defaults unless explicitly set to `enabled: false`
- Added `enabled` boolean to `GatewayAuthRateLimitConfig` type for explicit opt-out
- Added tests for default and empty config scenarios
Fixes #16876
## Test plan
- [x] Test rate limiter created with no config (default protection)
- [x] Test rate limiter created with empty config object
- [x] Existing rate limiter tests still pass
- [x] Full test suite passes (`pnpm test:fast`, `pnpm check`)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a security gap (#16876) where the gateway auth rate limiter was only created when `gateway.auth.rateLimit` was explicitly configured, leaving gateways unprotected by default against brute-force auth attempts.
- **`src/gateway/server.impl.ts`**: Inverts the rate limiter creation logic from opt-in to opt-out. The limiter is now always created with sensible defaults (10 attempts, 60s window, 5min lockout) unless `rateLimit.enabled` is explicitly set to `false`. Passing `undefined` config to `createAuthRateLimiter()` correctly triggers all default values.
- **`src/config/types.gateway.ts`**: Adds `enabled?: boolean` to `GatewayAuthRateLimitConfig` for explicit opt-out.
- **`src/gateway/auth-rate-limit.test.ts`**: Adds two regression tests covering no-config and empty-config scenarios.
The change is minimal and well-targeted. All downstream consumers already handle `rateLimiter` as optional (`AuthRateLimiter | undefined`), so the behavioral change is safe.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it closes a security gap with minimal, well-tested changes.
- The change is a 3-file, 27-line addition that flips rate limiter creation from opt-in to opt-out. The logic is straightforward (`=== false` check), the `createAuthRateLimiter` function already handles `undefined` config with sensible defaults, all downstream consumers handle the limiter as optional, and regression tests cover the key scenarios. No risk of breakage for existing configurations.
- No files require special attention.
<sub>Last reviewed commit: 92a9a99</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22766: fix(security): enable gateway auth rate limiting by default (CWE-307)
by brandonwise · 2026-02-21
89.1%
#16881: fix(gateway): enable auth rate limiting by default
by Limitless2023 · 2026-02-15
81.2%
#19937: fix(gateway): validate token/password auth modes and isolate gatewa...
by NewdlDewdl · 2026-02-18
78.2%
#19885: test(gateway,browser): isolate tests from ambient OPENCLAW_GATEWAY_...
by NewdlDewdl · 2026-02-18
77.0%
#12802: fix(gateway): default unscoped operator connections to read-only
by yubrew · 2026-02-09
76.7%
#17705: fix(gateway): allow trusted-proxy auth to bypass device-pairing gates
by dashed · 2026-02-16
76.7%
#21529: Gateway: allow node health and throttle repeated unauthorized role ...
by doomsday616 · 2026-02-20
76.6%
#22227: fix(security): harden gateway auth — audit logging, pairing, mode v...
by novalis133 · 2026-02-20
76.4%
#23355: Gateway: fail closed on untrusted proxy headers
by bmendonca3 · 2026-02-22
76.4%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
76.4%