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

Allow less strict host header parsing to handle non-RFC2396 compliant host headers #1284

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

gavinbunney
Copy link
Contributor

@gavinbunney gavinbunney commented Aug 19, 2022

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.

@gavinbunney gavinbunney marked this pull request as ready for review August 19, 2022 17:52
if (uri.getHost() != null) {
return new Pair<>(uri.getHost(), uri.getPort());
}
} catch (URISyntaxException ignored) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 🪨

@artgon
Copy link
Contributor

artgon commented Aug 19, 2022

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.

@gavinbunney
Copy link
Contributor Author

gavinbunney commented Aug 19, 2022

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.

@artgon Gated this behind a property zuul.HttpRequestMessage.host.header.strict.validation which defaults to true so it can be selected disabled as needed

@gavinbunney gavinbunney requested a review from artgon August 19, 2022 19:45
@gavinbunney gavinbunney changed the title Improve uri parsing to better handle non-RFC2396 compliant host headers Allow less strict host header parsing to handle non-RFC2396 compliant host headers Aug 19, 2022

@After
public void resetConfig() {
config.clearProperty("zuul.HttpRequestMessage.host.header.strict.validation");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice trick!

@gavinbunney gavinbunney merged commit 28f57b6 into master Aug 19, 2022
@gavinbunney gavinbunney deleted the gavin/uri-parsing branch August 19, 2022 22:52
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

Successfully merging this pull request may close these issues.

2 participants