-
Notifications
You must be signed in to change notification settings - Fork 210
Fix http redirects #365
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
Fix http redirects #365
Conversation
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.
Thanks!
Thats great, thanks @pietroalbini and @HeroicKatora. We have been aware of the issue since we started using CloudFront but we weren't able to provide a solution for it. This is so useful. |
like I said in the discord; I am only skeptical about dotenv, we are already doing same thing with systemd, it's reading our environment variables from (~/.cratesfyi.env) and passing it to our process. So I don't think we need dotenv. |
All the docs.rs redirects are absolute, including the protocol and the host name. This is fine if docs.rs is exposed directly on the Internet, but the production instance sits behind CloudFront, which terminates TLS connections. This means the application thinks it's serving HTTP requests instead of HTTPS ones, and it issues wrong redirects. This fixes the issue by taking the Cloudfront-Forwarded-Proto header into account when building the redirect URL.
7a0b8ed
to
b4de77c
Compare
Moved the dotenv commit in its own PR: #366 I still think it's useful but we don't need to block this PR on it. |
Awesome, thanks again! |
|
||
// Only include the port if it's needed | ||
let port = req.url.port(); | ||
if port == 80 { |
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.
Shouldn't this be 80 or 443?
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.
Uh, probably yes, but it shouldn't cause any issue with our production setup, so fixing it is not that high priority.
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 think only 80 is fine since CloudFront is sending requests to 80.
All the docs.rs redirects are absolute, including the protocol and the host name. This is fine if docs.rs is exposed directly on the Internet, but the production instance sits behind CloudFront which terminates TLS connections. This means the application thinks it's serving HTTP requests instead of HTTPS ones, and it issues wrong redirects.
This PR fixes the issue by taking the Cloudfront-Forwarded-Proto header into account when building the redirect URL. This also adds
dotenv
to the project. It's not necessary but it's handy when you want to set environment variables and you aren't in the vagrant VM.Fixes #363, and thanks @HeroicKatora for investigating this!