Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 Causes IPAddr::InvalidAddressError #1210

Closed
alexreisner opened this issue Aug 1, 2017 · 5 comments
Closed

IPv6 Causes IPAddr::InvalidAddressError #1210

alexreisner opened this issue Aug 1, 2017 · 5 comments
Labels

Comments

@alexreisner
Copy link
Owner

The Geocoder::Request#geocoder_remove_port_from_addresses method expects IPv4 addresses. When passed an IPv6 address, it incorrectly tries to remove the port by splitting on :. The syntax for specifying a port with an IPv6 address is specified in RFC 3986. An example:

[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:80
@alexreisner alexreisner added the bug label Aug 1, 2017
alexreisner referenced this issue Aug 1, 2017
* Create methods removing port from ip addresses; Add test

* Update geocoder_reject_non_ipv4_addresses; Add more tests
alexreisner added a commit that referenced this issue Jan 10, 2018
Handle IPv6 addresses when removing port numbers in request.location. Closes #1210
zacviandier pushed a commit to teezily/geocoder that referenced this issue Feb 9, 2018
Handle IPv6 addresses when removing port numbers in request.location. Closes alexreisner#1210
@vbyno
Copy link

vbyno commented Mar 27, 2019

@alexreisner , I have doubts this is an issue. At least, Geocoder.search returns empty-like results if we search by ipv6 address without passing the port. Check out:

Geocoder.search("3ffe:1900:4545:3:200:f8ff:fe21:67cf", ip_address: true)

 => 
[#<Geocoder::Result::Ipstack:0x00007fa592d9d700 @data={"ip"=>"3ffe:1900:4545:3:200:f8ff:fe21:67cf", "type"=>"ipv6", "continent_code"=>nil, "continent_name"=>nil, "country_code"=>nil, "country_name"=>nil, "region_code"=>nil, "region_name"=>nil, "city"=>nil, "zip"=>nil, "latitude"=>nil, "longitude"=>nil, "location"=>{"geoname_id"=>nil, "capital"=>nil, "languages"=>nil, "country_flag"=>nil, "country_flag_emoji"=>nil, "country_flag_emoji_unicode"=>nil, "calling_code"=>nil, "is_eu"=>false}, "time_zone"=>{"id"=>nil, "current_time"=>nil, "gmt_offset"=>nil, "code"=>nil, "is_daylight_saving"=>nil}, "currency"=>{"code"=>nil, "name"=>nil, "plural"=>nil, "symbol"=>nil, "symbol_native"=>nil}, "connection"=>{"asn"=>nil, "isp"=>nil}}, @cache_hit=true>]

^ Almost all the values are nil.

Lets try to pass a port:

Geocoder.search("[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:80")

 => [#<Geocoder::Result::Bing:0x00007fa592e5fad0 @data={"__type"=>"Location:http://schemas.microsoft.com/search/local/ws/rest/v1", "bbox"=>[49.51723861694336, 5.899119853973389, 49.521400451660156, 5.915890216827393], "name"=>"4545, Luxembourg", "point"=>{"type"=>"Point", "coordinates"=>[49.51892852783203, 5.900562763214111]}, "address"=>{"adminDistrict"=>"Luxembourg", "adminDistrict2"=>"Esch-Sur-Alzette", "countryRegion"=>"Luxembourg", "formattedAddress"=>"4545, Luxembourg", "locality"=>"Differdange", "postalCode"=>"4545"}, "confidence"=>"Medium", "entityType"=>"Postcode1", "geocodePoints"=>[{"type"=>"Point", "coordinates"=>[49.51892852783203, 5.900562763214111], "calculationMethod"=>"Rooftop", "usageTypes"=>["Display"]}], "matchCodes"=>["Ambiguous", "UpHierarchy"]}, @cache_hit=true>, #<Geocoder::Result::Bing:0x00007fa592e5f940 @data={"__type"=>"Location:http://schemas.microsoft.com/search/local/ws/rest/v1", "bbox"=>[48.11943817138672, 22.053539276123047, 48.160980224609375, 22.176729202270508], "name"=>"4545, Hungary", "point"=>{"type"=>"Point", "coordinates"=>[48.14020919799805, 22.104604721069336]}, "address"=>{"adminDistrict"=>"Szabolcs-Szatmár-Bereg", "countryRegion"=>"Hungary", "formattedAddress"=>"4545, Hungary", "locality"=>"Gyulaháza", "postalCode"=>"4545"}, "confidence"=>"Medium", "entityType"=>"Postcode1", "geocodePoints"=>[{"type"=>"Point", "coordinates"=>[48.14020919799805, 22.104604721069336], "calculationMethod"=>"Rooftop", "usageTypes"=>["Display"]}], "matchCodes"=>["Ambiguous", "UpHierarchy"]}, @cache_hit=true>, #<Geocoder::Result::Bing:0x00007fa592e5f7b0 @data={"__type"=>"Location:http://schemas.microsoft.com/search/local/ws/rest/v1", "bbox"=>[34.78843846040784, 32.955047797637405, 34.79616389554919, 32.96759014181572], "name"=>"4545, Cyprus", "point"=>{"type"=>"Point", "coordinates"=>[34.792301177978516, 32.96131896972656]}, "address"=>{"adminDistrict"=>"Limassol (Lemesos)", "countryRegion"=>"Cyprus", "formattedAddress"=>"4545, Cyprus", "locality"=>"Korfi", "postalCode"=>"4545"}, "confidence"=>"Medium", "entityType"=>"Postcode1", "geocodePoints"=>[{"type"=>"Point", "coordinates"=>[34.792301177978516, 32.96131896972656], "calculationMethod"=>"Rooftop", "usageTypes"=>["Display"]}], "matchCodes"=>["Ambiguous", "UpHierarchy"]}, @cache_hit=true>, #<Geocoder::Result::Bing:0x00007fa592e5f620 @data={"__type"=>"Location:http://schemas.microsoft.com/search/local/ws/rest/v1", "bbox"=>[38.80263137817383, -77.11997985839844, 38.99617004394531, -76.90933227539062], "name"=>"200, DC", "point"=>{"type"=>"Point", "coordinates"=>[38.91005325317383, -77.01530456542969]}, "address"=>{"adminDistrict"=>"DC", "countryRegion"=>"United States", "formattedAddress"=>"200, DC", "postalCode"=>"200"}, "confidence"=>"Low", "entityType"=>"Postcode2", "geocodePoints"=>[{"type"=>"Point", "coordinates"=>[38.91005325317383, -77.01530456542969], "calculationMethod"=>"Rooftop", "usageTypes"=>["Display"]}], "matchCodes"=>["UpHierarchy"]}, @cache_hit=true>, #<Geocoder::Result::Bing:0x00007fa592e5f490 @data={"__type"=>"Location:http://schemas.microsoft.com/search/local/ws/rest/v1", "bbox"=>[49.57175064086914, 1.3797999620437622, 50.370609283447266, 3.2027599811553955], "name"=>"Somme", "point"=>{"type"=>"Point", "coordinates"=>[49.959415435791016, 2.2719779014587402]}, "address"=>{"adminDistrict"=>"Hauts-de-France", "adminDistrict2"=>"Somme", "countryRegion"=>"France", "formattedAddress"=>"Somme"}, "confidence"=>"Low", "entityType"=>"AdminDivision2", "geocodePoints"=>[{"type"=>"Point", "coordinates"=>[49.959415435791016, 2.2719779014587402], "calculationMethod"=>"Rooftop", "usageTypes"=>["Display"]}], "matchCodes"=>["UpHierarchy"]}, @cache_hit=true>] 

What do you think about this? Should it work with pure ip_address as it works with port?

@alexreisner
Copy link
Owner Author

@vbyno Good question. Currently, the port is not stripped before this sort of query happens, only when deriving the user's IP address in a controller. I'm hesitant to always strip it out, because it would make it impossible to do a query for an IP address that included a port, which someone might want to do. Does that make sense?

@vbyno
Copy link

vbyno commented Mar 28, 2019

@alexreisner , it looks like my mistake. I thought Geocoder.search("[...]:80") returns correct results, but it doesn't. For example, this is Canada ip: 2607:fea8:1360:f7d:dce7:b7f0:e0b6:1014. and the result of Geocoder.search("[2607:fea8:1360:f7d:dce7:b7f0:e0b6:1014]:80") is Switzerland (it uses Bing search). Although, Geocoder.search("2607:fea8:1360:f7d:dce7:b7f0:e0b6:1014") works fine and uses ip_stack search as expected.

@alexreisner
Copy link
Owner Author

@vbyno you're right. Can you open a new issue to discuss? I'd call it: IP Address Not Detected for IPv6 with Port

@vbyno
Copy link

vbyno commented Mar 28, 2019

@alexreisner , Sure! Here is the issue #1396. If any additional clarification is needed, I will provide it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants