🪤 fix: Avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 False Positive#12333
Merged
Conversation
express-rate-limit v8 calls keyGenerator.toString() and throws ERR_ERL_KEY_GEN_IPV6 if the source contains the literal substring "req.ip" without "ipKeyGenerator". When packages/api compiles req?.ip to older JS targets, the output contains "req.ip", triggering the heuristic. Bracket notation (req?.['ip']) produces identical runtime behavior but never emits the literal "req.ip" substring regardless of compilation target. Closes #12321
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the removePorts rate-limiter key generator to avoid an express-rate-limit v8 false positive (ERR_ERL_KEY_GEN_IPV6) caused by TypeScript downlevel output containing the literal substring req.ip.
Changes:
- Replace
req?.ipwith bracket-notation accessreq?.['ip']to prevent emitted JS from containingreq.ip. - Expand the function doc comment to document why bracket notation is required for
express-rate-limitv8 compatibility.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add a test that verifies removePorts.toString() does not contain "req.ip", guarding against reintroduction of the ERR_ERL_KEY_GEN_IPV6 false positive. Fix a misleading test description and remove a redundant type annotation on a trivially-inferred local.
1 task
jcbartle
pushed a commit
to jcbartle/LibreChat
that referenced
this pull request
May 11, 2026
danny-avila#12333) * fix: avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 false positive express-rate-limit v8 calls keyGenerator.toString() and throws ERR_ERL_KEY_GEN_IPV6 if the source contains the literal substring "req.ip" without "ipKeyGenerator". When packages/api compiles req?.ip to older JS targets, the output contains "req.ip", triggering the heuristic. Bracket notation (req?.['ip']) produces identical runtime behavior but never emits the literal "req.ip" substring regardless of compilation target. Closes danny-avila#12321 * fix: add toString regression test and clean up redundant annotation Add a test that verifies removePorts.toString() does not contain "req.ip", guarding against reintroduction of the ERR_ERL_KEY_GEN_IPV6 false positive. Fix a misleading test description and remove a redundant type annotation on a trivially-inferred local.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
express-rate-limitv8 callskeyGenerator.toString()and throwsERR_ERL_KEY_GEN_IPV6if the source contains the literal substringreq.ipwithoutipKeyGenerator. Whenpackages/apicompilesreq?.ipto older JS targets, the output containsreq.ip, triggering the heuristic.req?.['ip']) produces identical runtime behavior but never emits the literalreq.ipsubstring regardless of compilation target.Follow-up to #12319.
Test plan
removePortstests pass (including new.toString()regression guard)req['ip']— noreq.ipsubstring inremovePorts.toString()express-rate-limitv8 heuristic simulation:Would trigger ERR_ERL_KEY_GEN_IPV6: false