pbojinov / request-ip

A Node.js module for retrieving a request's IP address on the server.
https://npmjs.com/package/request-ip
MIT License
830 stars 102 forks source link

add removal of start/end brackets around IPv6 addresses #89

Open delfuego opened 1 year ago

delfuego commented 1 year ago

Many proxies (e.g., IIS) add start/end brackets around IPv6 addresses in the X-Forwarded-For header, which prevents request-ip from being able to see them there since that fails the is.ip IPv6 regex test; this removes them if they're there.

This uses functions that have been in Javascript since time immemorial (string.startsWith, string.endsWith, string.substring), and all tests continue to pass.