Use values from x-forwarded headers in getOrigin server side#1850
Use values from x-forwarded headers in getOrigin server side#1850tdonohue merged 2 commits intoDSpace:mainfrom
Conversation
There was a problem hiding this comment.
👍Thanks @artlowel ! I tested this today and verified it works just as well as #1725, and I like this approach much better (as it aligns with standard HTTP headers).
Here's the testing process that I used:
- Starting from
main, I spun up the UI locally in production mode behind a proxy that uses HTTPS &X-Forwardedheaders. - Accessed an Item page from the UI.
- Then, turned off Javascript in my browser & reloaded the page.
- Verified that
citation_pdf_urlwrongly useshttpinstead ofhttps. (This was just to verify the bug still exists and it does) - Then, rebuilt/redeployed the UI using this PR & repeated these same steps
- Verified that
citation_pdf_urlnow useshttps, even with JavaScript off.
So, this fixes the issue! Thanks again for figuring out a solution that uses X-Forwarded-* headers.
|
I haven't had the chance to ask to @atarix83 for an opinion but I was just searching if there is anything "built-in" in angular to deal with proxy as it was a bit surprising for me that we need to write our own solution, I found this webpage that seems to indicate a built-in mechanism in expressjs (is it what we use right?) Anyway, I'm ok with the approach in this PR also if we should end to make our own implementation |
|
@artlowel and @abollini : I tried out @abollini 's idea, and it appears that we may be able to use the built-in approach in Express. Here's what I tried:
@artlowel : Could you see if this also works for you? If it does, we can likely remove the custom code and either hardcode this setting to |
556c132 to
941e71a
Compare
|
Yes that works I updated the PR to use it instead |
References
Description
This PR fixes #1721 by checking for the presence of the
x-forwarded-protoandx-forwarded-hostheaders server side, and using them instead of the defaulthostandprotocolproperties on the request if they are available.To stay on par with #1725, I also added the same small extra fix to ensure a redirect ends up in the browser's history
Instructions for Reviewers
Run the app in prod mode. And test it with and without a proxy server in front that's configured to use the
x-forwardedheadersTest that the
citation_pdf_urlon an item page always contains a URL that uses with the correct host and protocol, with and without using a proxy server .To test the redirect change, download a file, and use the back button of your browser. You should end up back on the item page
Checklist
yarn run lint