fix: handle private IP addresses gracefully in geo lookups#63
Merged
Conversation
5 tasks
Previously, looking up private/reserved IP addresses (10.x.x.x, 172.16-31.x.x, 192.168.x.x, 127.0.0.1, etc.) via the ip= query parameter would cause error logs because MaxMind databases don't contain data for these addresses. Changes: - Add is_private_ip() function to detect RFC1918, loopback, link-local, and IPv6 private/reserved address ranges - Modify geoip_lookup() to skip MaxMind DB lookup for private IPs and return default values directly - Update country_lookup() to return empty strings instead of nil for missing country data This prevents unnecessary error logs like: "Error with Geo DB: not found" "Error with ASN DB: not found" Fixes handling for endpoints: - /v1/ip/country?ip=... - /v1/ip/country.json?ip=... - /v1/ip/country.js?ip=... - /v1/ip/country/full?ip=... - /v1/ip/geo.json?ip=... - /v1/ip/geo.js?ip=...
jloh
force-pushed
the
fix/private-ip-handling
branch
from
February 8, 2026 06:20
4075bf7 to
7874b2f
Compare
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
ip=query parameteris_private_ip()function to detect RFC1918, loopback, link-local, and IPv6 private address rangesProblem
Previously, looking up private IP addresses via query parameters (e.g.,
/v1/ip/geo.json?ip=10.10.123.190) would cause error logs:This is because MaxMind databases don't contain data for private/reserved addresses.
Solution
Add
is_private_ip()function that detects:Modify
geoip_lookup()to skip MaxMind lookup for private IPs and return default values directlyUpdate
country_lookup()to return empty strings instead of nil for missing country data (prevents nil concatenation errors)Affected Endpoints
All endpoints using
ip=query parameter:/v1/ip/country?ip=.../v1/ip/country.json?ip=.../v1/ip/country.js?ip=.../v1/ip/country/full?ip=.../v1/ip/geo.json?ip=.../v1/ip/geo.js?ip=...Test plan
is_private_ip()function (tests 19-24)