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

Request-target should not be URL decoded #12

Closed
dieterde opened this issue Aug 25, 2020 · 5 comments
Closed

Request-target should not be URL decoded #12

dieterde opened this issue Aug 25, 2020 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation spec The functionality deviates from the spec and needs to be changed
Milestone

Comments

@dieterde
Copy link

There should be an additional (small) fix. Why is the requestUri URL decoded? It's not necessary, if the URL is encoded it should be taken this way otherwise the verification process fails.

So this is the change:
var requestForSigning = new HttpRequestForSigning { Method = httpRequestMessage.Method, RequestUri = httpRequestMessage.RequestUri.IsAbsoluteUri ? httpRequestMessage.RequestUri.PathAndQuery : httpRequestMessage.RequestUri.OriginalString.Split('#')[0] };

Originally posted by @dieterde in #10 (comment)

@dieterde dieterde changed the title Request-target should not be URL decoded. Request-target should not be URL decoded Aug 25, 2020
@DavidLievrouw
Copy link
Owner

Well, it's a little more complicated than that. The .NET Uri class has a tendency to encode and decode, depending which property or method you use. The decoding is there to get a common baseline: If the signer and the receiver both agree to decode before starting, there is no issue with encoding.

But it's definitely valid to retain the original string when creating the composed string to hash.

I will investigate further.

@DavidLievrouw DavidLievrouw self-assigned this Aug 25, 2020
DavidLievrouw pushed a commit that referenced this issue Aug 25, 2020
…d signature string + add some covering tests.

Still need to validate when using in a running web application.
DavidLievrouw pushed a commit that referenced this issue Aug 25, 2020
…codes the uri, in the way that a server would receive it, no matter if the client encodes it or not.
@DavidLievrouw
Copy link
Owner

DavidLievrouw commented Aug 25, 2020

As a suggestion, I switched it: Request URIs are now encoded for the signature, instead of decoded.

Why?

Servers have no way of knowing the original string that was used to sign. Whether it was encoded or not.
For .NET specifically, when ASP.NET Core or Owin receives a request, the URI is encoded in the authentication handler. So it seems to me that it's a safe bet to encode it, because that's the way most receivers will interpret it. .NET or anything else.

I also aligned it to use the same URL encoding that System.Net.HttpClient uses (the System.Uri class), when sending requests:
RFC 3986

Let me know if this meets your needs.

@DavidLievrouw
Copy link
Owner

Created #13 to make this behavior configurable.

@DavidLievrouw DavidLievrouw added documentation Improvements or additions to documentation spec The functionality deviates from the spec and needs to be changed labels Aug 29, 2020
@DavidLievrouw
Copy link
Owner

Released in v5.0.1.

@DavidLievrouw
Copy link
Owner

Also see here:
w3c-ccg/http-signatures#26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation spec The functionality deviates from the spec and needs to be changed
Projects
None yet
Development

No branches or pull requests

2 participants