Skip to content

Commit 2b794d4

Browse files
CryptoJonesAaron K. Clarkclaude
authored
chore(rate-limit): use req.socket instead of deprecated req.connection (#287)
The fallback IP lookup in \`keyByAuthKeyOrIp\` reached for \`req.connection.remoteAddress\` when \`req.ip\` was unset. Node has marked \`request.connection\` deprecated since 13.x as a legacy alias for \`request.socket\` — same value, different name. Switch to \`req.socket.remoteAddress\` so the keygen doesn't carry a warning- class accessor. Behavior is identical; the existing unit tests (which inject a plain \`{ ip }\` object) still pass without modification because they never reach the fallback branch. 760 tests still pass. Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fd1a7c4 commit 2b794d4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

app/middleware/rate-limit-key.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ function keyByAuthKeyOrIp(req /*, res */) {
4343
// /56 network prefix (the helper's default). Fall back to
4444
// 'unknown' when no source IP is available (e.g. unit-test
4545
// fixtures or non-IP transports).
46-
const ip = req.ip || (req.connection && req.connection.remoteAddress);
46+
//
47+
// `req.socket.remoteAddress` is the modern accessor — Node has
48+
// marked `req.connection` deprecated (legacy alias for socket)
49+
// since 13.x. Same value, future-proof name.
50+
const ip = req.ip || (req.socket && req.socket.remoteAddress);
4751
if (!ip) return 'ip:unknown';
4852
return 'ip:' + ipKeyGenerator(ip);
4953
}

0 commit comments

Comments
 (0)