-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Packetbeat: Handle ports and IPv6 in Host header #14215
Conversation
@@ -95,6 +96,8 @@ func synthesizeFullURL(u *ecs.Url, port int64) string { | |||
host := u.Domain | |||
if port != 80 { | |||
host = net.JoinHostPort(u.Domain, strconv.Itoa(int(u.Port))) | |||
} else if strings.IndexByte(u.Domain, ':') != -1 { | |||
host = "[" + u.Domain + "]" |
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.
This is necessary because Golang's net/url package expects u.Domain already surrounded with square brackets when it's an IPv6, but surrounds it for you when you use net.JoinHostPort
above.
Also checking for a :
character to determine if the host its an IPv6 address is what the url package does internally.
@@ -701,6 +707,24 @@ func parseCookieValue(raw string) string { | |||
return raw | |||
} | |||
|
|||
func extractHostHeader(header string) (host string, port int) { |
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.
This whole function can be replaced by url.Hostname()
and url.Port()
but those don't handles the case where an IPv6 address is not surrounded by brackets.
jenkins, test this |
When an IPv6 address is used as host for a connection to port 80 the address in the URL won't be surrounded by square brackets which is against RFC3986.
The HTTP parser in Packetbeat wasn't properly handling the hostname and port from "Host:" header, generating wrong "destination.domain" and "url.full" fields.
30e470f
to
129aaa0
Compare
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.
Nice fix. This explains some of the *.domain
values I was seeing.
The HTTP parser in Packetbeat wasn't properly handling the hostname and port from "Host:" header, generating wrong "destination.domain" and "url.full" fields. (cherry picked from commit 6acde25)
The HTTP parser in Packetbeat wasn't properly handling the hostname and port from "Host:" header, generating wrong "destination.domain" and "url.full" fields.
…elastic#14232) The HTTP parser in Packetbeat wasn't properly handling the hostname and port from "Host:" header, generating wrong "destination.domain" and "url.full" fields. (cherry picked from commit e4bcff8)
The http parser in Packetbeat is not correctly populating events when the host header contains a port number and/or an IPv6 address:
For "Host: elasticsearch:9200":
For "Host: [::1]":
- "destination.domain": "[::1]" "url.full": "http://[::1]/"
For "Host: [::1]:9200":