-
Notifications
You must be signed in to change notification settings - Fork 17
Fix: ACME directory URL redirects are not followed #77
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
Open
mdegel
wants to merge
4
commits into
nginx:main
Choose a base branch
from
mdegel:bugfix/75-redirect-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−7
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1acf361
Refactor HttpClient request handling to support redirect logic.
mdegel a508f09
Revert "Refactor HttpClient request handling to support redirect logic."
mdegel 264d08d
Add redirect handling to AcmeClient and including relevant error repo…
mdegel d8d7a08
Add redirect error handling and new IRI dependency.
mdegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's still necessary to handle relative URIs in the Location header.
I don't like the idea of reimplementing RFC3986 § 5 reference resolution algorithm (
resolve_locationin the previous revision didn't look quite right), so I suggest to use the same dependency asreqwestandtower-httpdo, iri-string. Here's how it may look: https://docs.rs/tower-http/0.6.6/src/tower_http/follow_redirect/mod.rs.html#394.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.
I have adjusted the code to match your suggestion.
I also split out the error logic to a custom
RedirectError, similar toNewAccountError, as the potential issues kind of started to polluteRequestError.In addition I could also extend it into the Problem and extend some logic there:
nginx-acme/src/acme/types.rs
Line 326 in d8d7a08
Not sure what you'd prefer here though?
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.
Do you mind extracting URI resolution code into a function? I suspect we may need it elsewhere in the future, because RFC8555 does not require any of the directory or resource location URIs to be absolute.
I also don't believe we need that many errors:
UriAbsoluteString::try_from()should not fail, becauseself.http.request()already fails on invalid URI. Still need to check the result, but don't expect anything useful.UriReferenceStr::new()returns a rather useless error "Invalid IRI".Uri::try_from()should succeed, because it always receives a valid absolute URI.With that in mind,
fn resolve_uri(base, relative) -> Option<Uri>is a reasonable interface, and the None can be later converted to a singleInvalidUri."invalid redirect URI"/"missing redirect URI"/"too many redirects" is a sufficient set of errors to handle this, and it will look acceptable both as a separate
RedirectErroror as members ofRequestError. Just ensure that you maintain the sorting order of the enum members.Problemis reserved for ACME protocol errors received from the server. Redirect errors don't belong there.The conversion you quoted exists to simplify handling
Problems that point to a permanent configuration error, i.e. cases when we should stop attempting to process the current item. Also, to make logs prettier.