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

Issue #7250 - Update HostHeaderCustomizer for empty Host + no authority #7251

Closed
wants to merge 8 commits into from

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Dec 9, 2021

Signed-off-by: Joakim Erdfelt [email protected]

@joakime
Copy link
Contributor Author

joakime commented Dec 9, 2021

There is an argument that we should not be setting or caring about the authority.

If we get a request like ...

GET foo:///12345 HTTP/1.1
Host:
Connection: close

That is a request without a declared authority, as specified by https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
The foo scheme could have an implied authority as well.

For example file:///path/to/bar is a file scheme which says the implied authority is "localhost" (See https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2)

If we reach a webapp in the above request that does HttpServletRequest.sendRedirect("/bar"), what does that mean to the Location: response header?
What about the HttpServletRequest.getServerName() ? (oddly, we get HttpServletRequest.getRequestURL() correct in the above example)

Question still remaining, do we force the Host header, even in the "empty host header" scenario?

@joakime joakime marked this pull request as draft December 10, 2021 20:51
@joakime
Copy link
Contributor Author

joakime commented Dec 10, 2021

Needs more tests for bad Host values.

Example:

Host: ":"
Host: ":43"
Host: -
Host: *
Host: -:88
Host: *.company.com

Should these be fixed by HostHeaderCustomizer as well? or treated as 400 Bad Request?
I'm kinda leaning towards 400 Bad Request, and having the new RejectNoAuthorityCustomizer renamed to RejectInvalidAuthorityCustomizer which also handles oddball authorities like above? WDYT?

We'll also need a new module for this new customizer.

@joakime joakime marked this pull request as ready for review December 10, 2021 23:06
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

I'd really REALLY prefer not to make any changes to HttpURI.

Instead focus on making a really good RejectInvalidAuthorityCustomizer that will solve the main concern of this PR.

Then by all means tweak the other Customizers to make them do a better job in the edge cases, but they don't need to be perfect if we have a good RIAC

Comment on lines +61 to +64
// Host must start with alpha-numeric.
int c = host.codePointAt(0);
if (!Character.isLetterOrDigit(c))
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about IPv6, which can start with '['

Copy link
Contributor Author

Choose a reason for hiding this comment

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

handled in different path, and in uncommited code i mentioned.

@Override
public void customize(Connector connector, HttpConfiguration channelConfig, Request request)
{
if (!isValidAuthority(request.getHttpURI()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? Don't we just care that there is an Authority in eitehr the URI or Host header (and if both then they match)?
Or has this been handled for us already and any Host header already copied over to the URI authority?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handled differently now, in HostPort.

String hostHeaderValue = request.getHeader("Host");

// No Host Header
if (request.getHttpVersion().getVersion() != HttpVersion.HTTP_1_1.getVersion() &&
Copy link

Choose a reason for hiding this comment

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

This can cause NPE, isn't it? request.getHttpVersion() can return null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The request shouldn't reach this customizer then, as I would expect the request to fail well before the customizers have been called.

@joakime joakime marked this pull request as draft December 14, 2021 12:43
@joakime
Copy link
Contributor Author

joakime commented Dec 14, 2021

This PR will be split into separate PRs.

@joakime joakime closed this Dec 16, 2021
@jetty jetty deleted a comment from abahl Dec 16, 2021
@joakime joakime deleted the jetty-9.4.x-no-host-customizer branch March 29, 2022 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HostHeaderCustomizer doesn't address empty Host header value with no authority set
3 participants