-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow less strict host header parsing to handle non-RFC2396 compliant host headers #1284
Conversation
if (uri.getHost() != null) { | ||
return new Pair<>(uri.getHost(), uri.getPort()); | ||
} | ||
} catch (URISyntaxException ignored) { } |
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.
Debug logging?
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.
Added 🪨
} catch (URISyntaxException ignored) { } | ||
|
||
// fallback to using a colon split | ||
// valid IPv6 addresses would have been handled already so any colon is safely assumed a port separator |
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.
What if it's an invalid IPv6 address?
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.
There is a fallback below that detects more than 1 colon (e.g. a non-bracketed IPv6 address) which will throw an exception
try { | ||
parsedPort = Integer.parseInt(components[1]); | ||
} catch (NumberFormatException ignored) { | ||
// ignore failing to parse port numbers and fallback to default port |
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.
Debug logging?
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.
Added 🪨
I'm not convinced that we want this to be our default functionality. If we do want to allow it, there can be a feature flag that enables it. |
14ac79c
to
c7c882d
Compare
@artgon Gated this behind a property |
c7c882d
to
954c6aa
Compare
|
||
@After | ||
public void resetConfig() { | ||
config.clearProperty("zuul.HttpRequestMessage.host.header.strict.validation"); |
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 trick!
The URI parsing changes done in #747 better handled IPv6 addresses, however it introduces issues when host headers contain non-RFC2396 compliant hostnames (for example any
_
or^
or url-encoded characters).This PR adds a less strict validation fallback to split-style parsing of the host header when the URI default parsing fails.