Skip to content

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

Merged
merged 1 commit into from
Jun 4, 2019
Merged

Conversation

pietroalbini
Copy link
Member

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!

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Thanks!

@onur
Copy link
Member

onur commented Jun 4, 2019

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.

@onur
Copy link
Member

onur commented Jun 4, 2019

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.
@pietroalbini
Copy link
Member Author

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.

@onur
Copy link
Member

onur commented Jun 4, 2019

Awesome, thanks again!

@onur onur merged commit 254ceae into rust-lang:master Jun 4, 2019
@pietroalbini pietroalbini deleted the fix-http-redirects branch June 4, 2019 12:54

// Only include the port if it's needed
let port = req.url.port();
if port == 80 {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@est31 est31 mentioned this pull request Jun 10, 2019
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.

badge links unnecessarily redirect to an HTTP endpoint
4 participants