I make use of the client-ip
HTTP header that comes into Netlify functions on the event.headers
object.
Recently, I started noticing that instead of getting valid, external ip addresses, I was only getting internal private IPs, like 10.64.0.97
.
After a little digging around, I found the problem. When the function is requested using www.
(which is my primary domain under “Domain settings”), I get an incorrect internal private IP. But when the function is requested without the www.
, I get the correct external IP address.
So, it seems like Netlify is redirecting the function HTTP request, and in the process, discarding the true client-ip
address.
I made a temporary function that just spits out HTML with the value of event.headers['client-ip']
. You can see the different results by hitting these two links:
no www, correct IP
www, incorrect IP
Please note, those addresses are identical EXCEPT for the www
. Also, the link that is NOT working correctly is the one corresponding to what I have set as my primary domain in the Netlify admin. So, right now, this means, that to get correct IP addresses, I have to make HTTP requests to my functions at my bare domain, which is not my primary domain, and oddly is not being redirected. Hopefully that makes sense.
Here’s a screenshot of my domain settings:
The netlify site id is en-evans
.
Thanks in advance for any help!