-
Notifications
You must be signed in to change notification settings - Fork 1
Get rid of enforcing absolute URLs for redirects. #5
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
Conversation
Without it, `lein test` produces the following error when executing test/test_friend/functional.clj: ``` Syntax error (ClassNotFoundException) compiling at (ring/adapter/jetty.clj:1:1). org.eclipse.jetty.util.component.AggregateLifeCycle ```
This fixes clj-commons#4. For long, the HTTP spec has allowed relative URLs in the Location header, see https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2. Absolute URLs have been introduced here: cemerick@5b04323 It was trying to fix the issue reported in 2013: cemerick#42 where they claimed that friend doesn't follow the HTTP spec. However, this lead to all sorts of problems with the clojure app running behind an SSL/TLS proxy, e.g. cemerick#84. To sum up: Original friend implementation got it right by using relative URLs for redirects but it wasn't, at the time, strictly following the HTTP spec. However, the HTTP spec has since been updated and there's no more reason to use absolute URLs - they are brittle and break apps.
This is to avoid redirecting to HTTP when the user request was in fact to an HTTPS endpoint. Such a situation happens when you run an SSL proxy in front of your plain HTTP app server. In that case, `ring.util.request/request-url` returns _almost_ a proper endpoint, but uses "http" not "https".
| @@ -1,5 +1,11 @@ | |||
| ## [Friend](http://github.com/cemerick/friend) changelog | |||
|
|
|||
| ### `0.3.x` | |||
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.
Not sure how does versioning works these days - should I replace x with something specific?
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.
No worries, I'll take care of that at release
| (defn resolve-absolute-uri | ||
| [^String uri request] | ||
| (-> (original-url request) | ||
| java.net.URI. | ||
| (.resolve uri) | ||
| str)) |
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.
Should we be worried about an external client using this function?
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.
Perhaps it's safer to leave it and mark it as deprecated?
| (str (if (.contains login-uri "?") login-uri (str login-uri "?")) | ||
| param)))) |
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.
This is basically the same implementation as it was 9 years ago: cemerick@5b04323#diff-7e2343c759ed64f4985000a745bce4778210e832d9e98b4c59e8793344cb5ef9L65-L66
slipset
left a comment
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.
If you could reinstate the one deleted fn and update the documentation as mentioned in comments, I'm good.
Use relative URLs for redirects.
This fixes #4.
For long, the HTTP spec has allowed relative URLs in the Location header,
see https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2.
Absolute URLs have been introduced here: cemerick@5b04323
It was trying to fix the issue reported in 2013: cemerick#42
where they claimed that friend didn't follow the HTTP spec.
However, this lead to all sorts of problems with Clojure apps running behind an SSL/TLS proxy,
e.g. cemerick#84.
To sum up: The original friend implementation got it right by using
relative URLs for redirects but it wasn't, at the time, strictly following the HTTP spec.
However, the HTTP spec has since been updated and there's no more reason
to use absolute URLs - they are brittle and break apps.
UPDATE: ring-defaults vs relative redirects
I fixed all the paths in friend's code that I could find.
However, even after doing that, my application was still redirecting to HTTP, instead of HTTPS.
I found that the problem is in ring-defaults: https://github.com/ring-clojure/ring-defaults#customizing
:absolute-redirectsis set totrueinsite-defaults: https://github.com/ring-clojure/ring-defaults/blob/master/src/ring/middleware/defaults.clj#L52So to make this work, you also need to customize
wrap-defaults, e.g. like this:I posted a message about this on Clojurians slack's ring channel: https://clojurians.slack.com/archives/C0A5GSC6T/p1650524416846019