mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-23 00:41:36 +00:00
fix(server): restore IPv6 /56 comment and fix rate-limit fallback bucket
ipKeyGenerator('') returned '' as the rate-limit key when both req.ip and
req.socket?.remoteAddress were undefined, silently merging all anonymous
requests into an empty-string bucket instead of the intended 'unknown' sentinel.
Switch to a conditional: only call ipKeyGenerator when an IP is present,
otherwise fall back to 'unknown'. Restores the IPv6 /56 normalisation
comment dropped in aa36869 (see issue #1360).
This commit is contained in:
parent
fb7c8e4283
commit
170a625438
1 changed files with 7 additions and 1 deletions
|
|
@ -151,7 +151,13 @@ export function createRouteLimiter(opts?: RouteLimiterOverrides): RateLimitReque
|
|||
standardHeaders: 'draft-7',
|
||||
legacyHeaders: false,
|
||||
passOnStoreError: true,
|
||||
keyGenerator: (req: Request) => ipKeyGenerator(req.ip ?? req.socket?.remoteAddress ?? ''),
|
||||
keyGenerator: (req: Request) => {
|
||||
// Pass through ipKeyGenerator so IPv6 addresses are normalised to their /56
|
||||
// subnet — without this, each IPv6 address gets its own counter and the limit
|
||||
// is trivially bypassed (#1360).
|
||||
const ip = req.ip ?? req.socket?.remoteAddress;
|
||||
return ip ? ipKeyGenerator(ip) : 'unknown';
|
||||
},
|
||||
message: { error: 'Too many requests, please try again later.' },
|
||||
...opts,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue