Skip to content

🪤 fix: Avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 False Positive#12333

Merged
danny-avila merged 2 commits into
devfrom
fix/rate-limiter-ipv6-keygen
Mar 20, 2026
Merged

🪤 fix: Avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 False Positive#12333
danny-avila merged 2 commits into
devfrom
fix/rate-limiter-ipv6-keygen

Conversation

@danny-avila

@danny-avila danny-avila commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • 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.

Follow-up to #12319.

Test plan

  • All 20 removePorts tests pass (including new .toString() regression guard)
  • Compiled output confirmed: req['ip'] — no req.ip substring in removePorts.toString()
  • express-rate-limit v8 heuristic simulation: Would trigger ERR_ERL_KEY_GEN_IPV6: false

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
Copilot AI review requested due to automatic review settings March 20, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?.ip with bracket-notation access req?.['ip'] to prevent emitted JS from containing req.ip.
  • Expand the function doc comment to document why bracket notation is required for express-rate-limit v8 compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/api/src/utils/ports.ts
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.
@danny-avila danny-avila changed the title fix: avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 false positive 🪤 fix: Avoid express-rate-limit v8 ERR_ERL_KEY_GEN_IPV6 False Positive Mar 20, 2026
@danny-avila danny-avila changed the base branch from main to dev March 20, 2026 16:25
@danny-avila danny-avila linked an issue Mar 20, 2026 that may be closed by this pull request
1 task
@danny-avila danny-avila merged commit 594d947 into dev Mar 20, 2026
7 checks passed
@danny-avila danny-avila deleted the fix/rate-limiter-ipv6-keygen branch March 20, 2026 16:32
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ERR_ERL_KEY_GEN_IPV6 on startup with custom keyGenerator

2 participants