-
Notifications
You must be signed in to change notification settings - Fork 462
httpsec: handle client ip with multiple http headers #1796
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks for this 👍
// none is present, it returns the first valid IP address present, possibly | ||
// being a local IP address. The remote address, when valid, is used as fallback | ||
// when no IP address has been found at all. | ||
func ClientIP(hdrs map[string][]string, hasCanonicalMIMEHeaderKeys bool, remoteAddr string) (remoteIP, clientIP instrumentation.NetaddrIP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: maybe we can rename hasCanonicalMIMEHeaderKeys
to something a bit shorter?
Something like hasCanonicalHeaders
or even just canonicalHeaders
?
No strong opinion there so I'm also fine leaving it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, but now this is validated I won't change it 😅
let's do this when we move it into go-appsec-internals
What does this PR do?
Update the client IP algorithm to now handle the presence of multiple IP-related HTTP headers. To do so, the IP-related HTTP headers we want to handle are now ordered and the first client IP found among them is the one returned.
Motivation
The former implementation was a temporary version to gather data and feedback on how users use those IP-related HTTP headers. We found that:
Read more about this at https://datadoghq.atlassian.net/wiki/spaces/APS/pages/2118779066/Client+IP+addresses+resolution
Describe how to test/QA your changes
Reviewer's Checklist
Triage
milestone is set.