fix(mcp): skip loopback and IPv6 private IPs in getClientIp#2875
Merged
fahreddinozcan merged 2 commits intoJul 6, 2026
Merged
Conversation
Extract getClientIp into lib/client-ip.ts and extend the private/local IP filter to cover 127.0.0.0/8, 169.254.0.0/16, ::1, fe80::/10, and fc00::/7 when walking X-Forwarded-For. Proxies that prepend loopback or health-check addresses no longer pollute mcp-client-ip analytics. Fixes upstash#2874
Anchor the fe80::/10 and fc00::/7 regexes to full 4-digit first hextets so abbreviated hextets like fe8::1 or fc::1 are no longer misclassified as private. Match IPv6 loopback in any textual form (0::1, 0:0:0:0:0:0:0:1), add CGNAT (100.64.0.0/10) to the skip list, and add a patch changeset.
fahreddinozcan
approved these changes
Jul 6, 2026
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
Extend
getClientIpprivate/local IP filtering so reverse proxies that prepend loopback or health-check addresses no longer pollutemcp-client-ipanalytics.Fixes #2874
Motivation
getClientIpalready skipped RFC1918 ranges when walkingX-Forwarded-For, but still accepted loopback (127.*), IPv4 link-local (169.254.*), and common IPv6 private ranges. A header like127.0.0.1, 8.8.8.8incorrectly returned127.0.0.1instead of the public client IP.Changes
getClientIpintopackages/mcp/src/lib/client-ip.tsisPrivateOrLocalIp()covering RFC1918,127.0.0.0/8,169.254.0.0/16,::1,fe80::/10, andfc00::/7index.tswithout changing fallback behavior when all forwarded IPs are privatepackages/mcp/test/client-ip.test.tsTests
cd packages/mcp npx vitest run npx tsc --noEmit npx eslint src/lib/client-ip.ts src/index.ts test/client-ip.test.tsNotes
remoteAddresshandling is unchanged (noX-Forwarded-Forpath)