Filed by the auto-audit routine. Dimension: tests. Severity: medium.
What
The test at packages/middleware/src/index.test.ts:372 is titled "uses x-forwarded-for header for client key", but ThrottleMiddleware.handle() calls clientIp(req) (line 186 of index.ts) which reads only req.ip - not the x-forwarded-for header. The test constructs a request via makeReq({ headers: { 'x-forwarded-for': '10.0.0.1, 192.168.1.1' } }) which inherits the makeReq default of ip: '127.0.0.1'. Both calls in the test use the same req.ip (127.0.0.1), so the second call is blocked - but because of the IP default, not because of the forwarded-for header. The x-forwarded-for header is completely ignored.
Where
packages/middleware/src/index.test.ts:372 (test case "uses x-forwarded-for header for client key")
Why it matters
The test gives false confidence that ThrottleMiddleware processes the x-forwarded-for header for rate-limit keying. It does not: IP resolution is fully delegated to server-hono's extractIp(), which sets req.ip. A developer reading the test might believe raw header processing is tested when it is not. If someone later modifies clientIp() to read raw headers directly (bypassing the server adapter's trusted-proxy logic), no existing test would catch the regression.
Suggested direction
Rename or replace the test. The correct behavior to document is: "ThrottleMiddleware keys by req.ip, which is set by the server adapter (server-hono's extractIp()), not by the middleware itself." One correct test: when req.ip is explicitly absent, all requests key to 'unknown' and share one bucket (already partially covered by the "warns once" test). Another: when two requests have different req.ip values, they use separate buckets.
audit:auto - package @rudderjs/middleware - cycle 2026-06-23
What
The test at
packages/middleware/src/index.test.ts:372is titled "uses x-forwarded-for header for client key", butThrottleMiddleware.handle()callsclientIp(req)(line 186 ofindex.ts) which reads onlyreq.ip- not thex-forwarded-forheader. The test constructs a request viamakeReq({ headers: { 'x-forwarded-for': '10.0.0.1, 192.168.1.1' } })which inherits themakeReqdefault ofip: '127.0.0.1'. Both calls in the test use the samereq.ip(127.0.0.1), so the second call is blocked - but because of the IP default, not because of the forwarded-for header. The x-forwarded-for header is completely ignored.Where
packages/middleware/src/index.test.ts:372(test case "uses x-forwarded-for header for client key")Why it matters
The test gives false confidence that
ThrottleMiddlewareprocesses thex-forwarded-forheader for rate-limit keying. It does not: IP resolution is fully delegated to server-hono'sextractIp(), which setsreq.ip. A developer reading the test might believe raw header processing is tested when it is not. If someone later modifiesclientIp()to read raw headers directly (bypassing the server adapter's trusted-proxy logic), no existing test would catch the regression.Suggested direction
Rename or replace the test. The correct behavior to document is: "ThrottleMiddleware keys by
req.ip, which is set by the server adapter (server-hono'sextractIp()), not by the middleware itself." One correct test: whenreq.ipis explicitly absent, all requests key to'unknown'and share one bucket (already partially covered by the "warns once" test). Another: when two requests have differentreq.ipvalues, they use separate buckets.audit:auto - package @rudderjs/middleware - cycle 2026-06-23