-
Notifications
You must be signed in to change notification settings - Fork 1.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
Introduce HttpCompliance.MISMATCHED_AUTHORITY
#9312
Conversation
+ Checks if provided Host authority matches an absolute target-uri authority + Default is to reject with 400 Bad Request + Optional HttpCompliance to disable this check. Signed-off-by: Joakim Erdfelt <[email protected]>
+ use example.org (instead of example.net) + fix tests that are now failing due to enforcement of absolute target-uri authority and provided Host header Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
@gregw this needs more attention. I added an Some of the flavors of rules around this ...
The wording has changed over the years here. RFC9112 - Section 3.2 - Request Target https://www.rfc-editor.org/rfc/rfc9112#section-3.2
RFC7230 - Section 5.4 - Host https://www.rfc-editor.org/rfc/rfc7230#section-5.4 It says ...
and ...
Which is kind of in line with RFC 2616 RFC 2616 - Section 5.2 - The Resource Identified by a Request https://www.rfc-editor.org/rfc/rfc2616#section-5.2
|
@@ -1037,22 +1038,32 @@ else if (_endOfContent == EndOfContent.CHUNKED_CONTENT) | |||
LOG.warn("Encountered multiple `Host` headers. Previous `Host` header already seen as `{}`, new `Host` header has appeared as `{}`", _parsedHost, _valueString); | |||
checkViolation(DUPLICATE_HOST_HEADERS); | |||
} | |||
if (!MISMATCHED_AUTHORITY.isAllowedBy(_complianceMode)) | |||
{ | |||
HttpURI httpURI = HttpURI.build().uri(_method == null ? null : _method.toString(), _uri.toString()); |
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.
We really don't want to go to the effort here build a HttpURI
here, only to throw it away and then in fact we have already started building the exact same HttpURI
in org.eclipse.jetty.server.HttpChannelOverHttp#startRequest
.
Option A) is to change the RequestHandler signature to
public interface RequestHandler extends HttpHandler
{
/**
* This is the method called by parser when the HTTP request line is parsed
*
* @param method The method
* @param uri The raw bytes of the URI.
* @param version the http version in use
* @deprecated use {@link #startRequest(String, HttpURI, HttpVersion)}
*/
@Deprecated
default void startRequest(String method, String uri, HttpVersion version)
{}
/**
* This is the method called by parser when the HTTP request line is parsed
*
* @param method The method
* @param uri The raw bytes of the URI.
* @param version the http version in use
*/
default void startRequest(String method, HttpURI uri, HttpVersion version)
{
startRequest(method, uri.toString(), version);
}
}
We can then have a recycled HttpURI.Mutable in the parser and build the URI there, so it is available.
Option B) is to move this check to HttpChannelOverHttp
I think option A is OK. Let me do some experiments and I may have a diff for you....
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.
@joakime I have created branch jetty-10-9312-HttpParser-HttpURI
that has this updated signature.
The only issue is that the field is a Mutable, and we take it as an Immutable as we call startRequest... and that immutable is not available when you need to do this check. So perhaps we need yet another field to remember the immutable?
Currently, I'm thinking we don't want big changes in 9, 10 or 11. Thus perhaps we just add a check in the In 12, we can have a think about changing the parser API so that it creates the HttpURI once and only once, rather than doing the mix in that is currently done in setMetaData to combine the URI and host authority. |
@gregw I agree that doing it in |
closed in favour of #9343 |
Signed-off-by: Joakim Erdfelt [email protected]