-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
📝 [Proposal]: Add Helpers for Internal IP Ranges #2930
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
@xEricL I'm looking into this. I also found an issue, the more ranges you add to that list the longer a request takes. |
@gaby Thank you for taking an interest in this. I just want to clarify that the IP ranges I provided was not a complete list. There are also:
There are a lot more ranges defined in RFC6890, RFC4291 and RFC4193. What are your thoughts on simply adding another option to net/ip has nice helper functions for detecting address types, such as ip.IsPrivate() (added in Go 1.16).
// Note: These are the same ranges enabled by default when configuring an IP extractor in Echo.
// https://github.com/labstack/echo/blob/master/ip.go#L174
func (*DefaultCtx) isInternalHost(ip net.IP) bool {
return ip.IsLoopback() || ip.IsPrivate() || ip.IsLinkLocalUnicast()
} and then use it in func (c *DefaultCtx) IsProxyTrusted() bool {
...
ip := c.fasthttp.RemoteIP()
if c.app.config.TrustInternalIPs && c.isInternalHost(ip) { return true }
if _, trusted := c.app.config.trustedProxiesMap[ip.String()]; trusted {
return true
}
...
} This seems to be a much better approach than my initial idea of adding constants for each individual range. I didn't realize there were so many to consider when I first opened this request. It might even have better performance compared to adding the equivalent IP ranges to the |
@xEricL Yeah, that approach makes sense, let me do some benchmarks. Ibwant to make sure lookup times are consistent. |
Feature Proposal Description
Currently, adding loopback, link-local, and private network addresses to the
fiber.Config.TrustedProxies
list requires us to manually add those ranges. Since web apps are commonly deployed behind reverse proxies, it would be helpful to have a simple way of adding these ranges without needing to search them up.When configuring trusted proxies in Echo framework, the setup is a bit different:
In Fiber, an equivalent setup would look something like
Although I prefer Fiber's method of using an array of strings, it would be nice to have constants like:
This would allow developers to use
They don't necessarily need to be constants. We could add a new config option to
fiber.Config
instead:This would be far easier, but at the cost of allowing developers to cherry pick individual ranges. Those cases are probably rare though, which might be why Echo's helper functions for these ranges default to true.
Alignment with Express API
Express.js allows developers to set trusted proxy settings using pre-defined subnets:
HTTP RFC Standards Compliance
n/a (this is a quality of life improvement)
API Stability
IP address ranges don't change.
Feature Examples
Checklist:
The text was updated successfully, but these errors were encountered: