-
Notifications
You must be signed in to change notification settings - Fork 523
Handle requests that use an absolute URI as the request path #666
Comments
It looks like the first request is valid (https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 outdated RFC, but I assume this hasn't changed), but Kestrel is putting the full URL (e.g. “http://localhost:5000/” instead of “/”) in This causes the following exception to be thrown from PathString when some middleware (presumably Routing) tries to access HttpContext.Request.Path: System.ArgumentException: The path in 'value' must start with '/'. The uncaught exception then results in a 500 response. |
Yeah, that format is only used with proxies which is why nobody has run into it yet. |
So for a request for a full URL we should check if it matches one of the addresses Kestrel is listening on, otherwise we should fail. Would a 400 be appropriate for this situation? |
I don't think we're ready for that level of validation. We don't check the host header either. Just ignore the scheme and host. |
Moving to Backlog. cc @muratg |
Assigning @natemcmaster for further investigation. Please sync up with @CesarBS for his latest findings. |
@natemcmaster The partial fix was to set Path, PathBase and QueryString to string.Empty if the first character of the raw target wasn't '/'. In the case of this request, the first character of raw target is 'h'. If you change the raw request in Program.cs to the following and check Path and QueryString, you'll see both are empty, so it isn't fully fixed.
|
Ah, I see. So we fixed the server doesn't crash, but we still want to parse the request URI into the http context |
I'm not sure we do. The absolute URI format is only valid in specific scenarios like proxies. |
I would test what other servers like IIS, nginx and maybe node do. If they all have consistent behavior, we should match it. |
Given:
IIS logs: cs-uri-stem = /abc, cs-host = localhost Given:
IIS logs: cs-uri-stem = /abc, cs-host = localhost |
What if the request line and host header (or scheme) disagree? |
Sending this request to
IIS: nginx: node: |
Ok. Can you summarize the relevant sections of the HTTP spec? |
Terms: From RFC 7230, Section 5.3.2 "absolute-form"
From RFC 7230, Section 5.4 "Host"
From RFC 7230, Section 5.5 "Effective request URI"
Otherwise, a server constructs the "effective request URI" from a combination of server configuration, request-target, and headers. What is Host and request-target differ? RFC 7230 warns that this may occur -- accidentally or maliciously -- but does not provide guidance on whether this should be an error or not. All section 5.5 says is
|
Given this, I think Kestrel should continue to accept these requests, but we should start pulling the path out of the absolute URI instead of falling back to |
An absolute-form request URI has a start line in form: "GET http://host/path HTTP/1.1". RFC 7230 section 5.3.2 stipulates that servers should allow absolute-form request URIs. This change will handles requests using absolute-form. The scheme and authority section of the absolute URI are ignored, but will still appear in IHttpRequestFeature.RawTarget. Resolves #666
An absolute-form request URI has a start line in form: "GET http://host/path HTTP/1.1". RFC 7230 section 5.3.2 stipulates that servers should allow absolute-form request URIs. This change will handles requests using absolute-form. The scheme and authority section of the absolute URI are ignored, but will still appear in IHttpRequestFeature.RawTarget. Resolves #666
An absolute-form request URI has a start line in form: "GET http://host/path HTTP/1.1". RFC 7230 section 5.3.2 stipulates that servers should allow absolute-form request URIs. This change will handles requests using absolute-form. The scheme and authority section of the absolute URI are ignored, but will still appear in IHttpRequestFeature.RawTarget. Resolves #666
An absolute-form request URI has a start line in form: "GET http://host/path HTTP/1.1". RFC 7230 section 5.3.2 stipulates that servers should allow absolute-form request URIs. This change will handles requests using absolute-form. The scheme and authority section of the absolute URI are ignored, but will still appear in IHttpRequestFeature.RawTarget. Resolves #666
Kestrel returns
HTTP/1.1 500 Internal Server Error
when the request has a complete request URI.Sample app - HelloWorldMvc
Program.cs
project.json
The text was updated successfully, but these errors were encountered: