#22766: fix(security): enable gateway auth rate limiting by default (CWE-307)
gateway
size: S
trusted-contributor
## Summary
Enable gateway authentication rate limiting by default whenever shared-secret auth is configured (`gateway.auth.token` or `gateway.auth.password`).
Previously, rate limiting only applied when `gateway.auth.rateLimit` was explicitly set, leaving token/password auth vulnerable to brute-force attempts by default.
## Changes
- Add `resolveGatewayAuthRateLimitConfig()` helper (`src/gateway/auth-rate-limit-config.ts`)
- returns `undefined` when no shared secret auth is configured
- returns explicit `gateway.auth.rateLimit` values when provided
- otherwise returns default config object so `createAuthRateLimiter()` applies secure defaults
- Wire resolver into `startGatewayServer()` (`src/gateway/server.impl.ts`)
- Add unit tests (`src/gateway/auth-rate-limit-config.test.ts`)
## Security impact
- Closes default-on brute-force gap for gateway token/password auth (CWE-307)
- Maintains backward compatibility for explicit `gateway.auth.rateLimit` tuning
## Validation
- `pnpm exec vitest run src/gateway/auth-rate-limit-config.test.ts src/gateway/auth-rate-limit.test.ts`
Closes #14137
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Closes a CWE-307 brute-force gap by enabling gateway auth rate limiting by default whenever shared-secret auth (`token` or `password`) is configured, rather than requiring explicit `gateway.auth.rateLimit` configuration.
- Adds `resolveGatewayAuthRateLimitConfig()` helper that returns a `RateLimitConfig` with `undefined` fields (letting `createAuthRateLimiter()` apply its safe defaults) when shared-secret auth is active, and `undefined` (no limiter) when it isn't
- Wires the resolver into `startGatewayServer()` replacing the previous direct config read
- Preserves backward compatibility: explicit `gateway.auth.rateLimit` values still take precedence
- Import reordering in `server.impl.ts` is cosmetic (alphabetical sort), no imports added or removed beyond the new resolver
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it adds a secure default without breaking existing configurations.
- The change is small, well-scoped, and purely additive in terms of security posture. The new resolver correctly matches auth mode to credential presence, preserves explicit user config, and the existing rate limiter creation path is unchanged. Import reordering is cosmetic. Tests cover all meaningful branches. No regressions or logical errors identified.
- No files require special attention.
<sub>Last reviewed commit: 75ec00d</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16963: fix: enable auth rate limiting by default
by StressTestor · 2026-02-15
89.1%
#23355: Gateway: fail closed on untrusted proxy headers
by bmendonca3 · 2026-02-22
79.9%
#22227: fix(security): harden gateway auth — audit logging, pairing, mode v...
by novalis133 · 2026-02-20
79.9%
#19937: fix(gateway): validate token/password auth modes and isolate gatewa...
by NewdlDewdl · 2026-02-18
79.3%
#7654: feat(security): zero-trust localhost auth with DNS rebinding protec...
by joncode · 2026-02-03
78.8%
#21326: Security/UI: harden Control UI gatewayUrl URL overrides
by bmendonca3 · 2026-02-19
78.2%
#16881: fix(gateway): enable auth rate limiting by default
by Limitless2023 · 2026-02-15
78.1%
#19885: test(gateway,browser): isolate tests from ambient OPENCLAW_GATEWAY_...
by NewdlDewdl · 2026-02-18
77.4%
#21120: Security/Gateway: guard dangerous HTTP /tools/invoke re-enables
by bmendonca3 · 2026-02-19
76.9%
#23364: Gateway: add risk-ack interlock for dangerous Control UI flags
by bmendonca3 · 2026-02-22
76.8%