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

Take port into account for the signature #55

Merged
merged 1 commit into from
Mar 8, 2022

Conversation

michivi
Copy link
Contributor

@michivi michivi commented Mar 2, 2022

Description

This PR instructs the servant-hmac-auth client code to take the remote HTTP port into account in the generated HMAC signatures for the following cases:

  • Targeted http port other than 80
  • Targeted https port other than 443

Technical details

The HMAC signature takes into account both the Host http header and the requested URL (from host to query string and everything in between, including any non-standard port).

Before that PR, the client code actually only took the host into account, both for the always-overwritten Host header and for the URL used for the signature. This would work if the client application targets a remote endpoint on a standard port (80 for http, 443 for https) as the port is optional in that case. However, this fails on non-standard port as it would then be required to be explicit for both the HTTP header and the URL. By ignoring the port, the library would generate a signature that wouldn't be recognized as valid by the remote server if the latter takes the port into account.

This PR forces the library to take the port into account when the targeted port is not standard. However, should the client application use an explicit Host header, this one will be used instead.

The server code is not impacted as it always uses the Host HTTP header.

Consequences

Servers are not impacted by the PR.

Clients only sending requests to servers on a standard port (80 for http and 443 for https) are not affected.

Clients that were sending requests to servers which were modified not to take the port into account needs to be updated to do so.

Nothing ->
case (Client.secure req, Client.port req) of
(True, 443) -> Client.host req
(False, 80) -> Client.host req
Copy link
Member

Choose a reason for hiding this comment

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

I don't know this codebase much but are you sure this will be reliable even when server is behind the reverse proxy that accepts https trafic but forwards unecrypted http trafic to haskell server?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this won't be a problem since this code is in client to server but I'm rather asking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think unencrypted traffic will be an issue. With HMAC, we're more concerned about authentication and integrity rather than confidentiality. For the later, https should be used anyway. If https is not used, I guess confidentiality is not that important 😀

Copy link
Member

@kahlil29 kahlil29 left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍🏻

@michivi
Copy link
Contributor Author

michivi commented Mar 7, 2022

Thank you all for the reviews.
Unless there's an absolute necessity for the merge, I'll delay it just a little until another PR regarding the hashing of the request's content is ready. While they're not related, it'll take less time to handle both PRs.

@michivi michivi merged commit 8ab21bc into master Mar 8, 2022
@michivi michivi deleted the tle/take-port-into-account branch March 8, 2022 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants