-
Notifications
You must be signed in to change notification settings - Fork 522
Path does not match the request if contains encoded url #1428
Comments
Unescaping |
@CesarBS can you please explain why by design |
The Are you trying to access the raw request target exactly as the server saw it? There is a way to do that but we strongly recommend users don't do it. |
Thanks for the reply; I'm using a middleware for Hmac authentication and I'm using the full URL as part of the signature hash. Being the original URL on the client: So yes, I "need" the raw URL as the client and the server should be able to have access to the same string for hashing. I could just trim some data from the hash, but I did not appreciate it would have been difficult to have matching URL between client/server. |
This is how you get the raw target: httpContext.Features.Get<IHttpRequestFeature>().RawTarget |
FYI @UnoSD, the client does not transmit the original url in the request. ASP.NET has to approximate it by re-assembling the fields that the client does send. E.g. the request line contains path and query, the Host header contains the host and port, and the scheme is implied by the connection protocol. Also, any intermediate (e.g. proxy) may alter these fields. You can't reliably reproduce the full raw url that the client requested, only something that should be semantically equivalent. |
Thank you both; @Tratcher the requests will be always coming from the local machine so it should be fine, but since there is no guarantee the server can match the URL I might drop this from the signature. |
I opened this issue on the aspnet/HttpAbstractions repository as the
HttpRequestFeature.Path
property was returning an unescaped:
which was originally a %3A in my request's URL:http://localhost:5000/secrets/http%3A%2F%2Fwww.g
->/secrets/http:%252F%252Fwww.g
The double escaping is generated in the
Path
property, but I have been advised the un-escaping of the %3A is happening in Kestrel/WebListener and I believe it is a bug. I am happy to help fixing it if you could point me in the right direction of the code.The text was updated successfully, but these errors were encountered: