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

X-Forwarded-For header should be processed last-to-first to prevent IP spoofing #2232

Closed
santif opened this issue Feb 11, 2020 · 0 comments
Closed

Comments

@santif
Copy link

santif commented Feb 11, 2020

Description

X-Forwarded-For header should be processed last-to-first to prevent IP spoofing, as explained in this post. It would be needed to set up IP addresses of known proxies to be ignored.

Current implementation

In context.go:

func (c *Context) ClientIP() string {
	if c.engine.ForwardedByClientIP {
		clientIP := c.requestHeader("X-Forwarded-For")
		clientIP = strings.TrimSpace(strings.Split(clientIP, ",")[0])
		if clientIP == "" {
			clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
		}
		if clientIP != "" {
			return clientIP
		}
	}
	...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants