fix(server): use ipKeyGenerator for IPv6-safe rate-limit key generation and remove duplicate interface method

This commit is contained in:
Sparsh 2026-05-05 21:53:19 +05:30
parent 1290973cb3
commit e5eb9eabb4
2 changed files with 2 additions and 21 deletions

View file

@ -346,25 +346,6 @@ export interface ScopeResolver {
*/
loadResolutionConfig?(repoPath: string): Promise<unknown> | unknown;
/**
* Optional one-shot loader for cross-file import-resolution config
* (e.g. tsconfig path aliases for TypeScript, go.mod paths for Go,
* composer.json autoload for PHP). The orchestrator calls this once
* per workspace pass with the repo root and threads the result into
* every subsequent `resolveImportTarget` call as the
* `resolutionConfig` parameter.
*
* Languages that don't need any per-workspace config leave this
* undefined; the orchestrator threads `undefined` to
* `resolveImportTarget` in that case. Returning `null` is also
* supported and equivalent to "no config available".
*
* May be sync or async the orchestrator awaits the result. The
* shape is opaque to the orchestrator (`unknown`); the per-language
* `resolveImportTarget` casts it to the language's expected shape.
*/
loadResolutionConfig?(repoPath: string): Promise<unknown> | unknown;
/**
* Per-scope binding-merge precedence. The shared finalize pass
* collects bindings from multiple sources (local declarations,

View file

@ -19,7 +19,7 @@
*/
import path from 'node:path';
import rateLimit, { type RateLimitRequestHandler } from 'express-rate-limit';
import rateLimit, { ipKeyGenerator, type RateLimitRequestHandler } from 'express-rate-limit';
import type { Request } from 'express';
/**
@ -151,7 +151,7 @@ export function createRouteLimiter(opts?: RouteLimiterOverrides): RateLimitReque
standardHeaders: 'draft-7',
legacyHeaders: false,
passOnStoreError: true,
keyGenerator: (req: Request) => req.ip ?? req.socket?.remoteAddress ?? 'unknown',
keyGenerator: (req: Request) => ipKeyGenerator(req.ip ?? req.socket?.remoteAddress ?? ''),
message: { error: 'Too many requests, please try again later.' },
...opts,
});