Skip to content

Redirect HTTP -> HTTPS for custom domains #6882

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

Closed

Conversation

davidfischer
Copy link
Contributor

  • Only redirect if the appropriate flag is set on the Domain (default is not to redirect)
  • Use a 302 redirect for now. Ideally this is a 301 redirect, but redirecting other people's domains with a 301 is always a bit risky. If things go smoothly, it's an easy change to switch from a 301 to a 302.

Fixes #4641

- Only redirect if the appropriate flag is set on the Domain
  (default is not to redirect)
- Use a 302 redirect for now. Ideally this is a 301 redirect,
  but redirecting other people's domains with a 301 is always a bit
  risky.
@davidfischer davidfischer requested a review from a team April 9, 2020 00:11
if domain.https and not request.is_secure():
# Redirect HTTP -> HTTPS (302) for this custom domain
log.debug('Proxito CNAME HTTPS Redirect: host=%s', host)
return redirect('https://%s%s' % (host, request.get_full_path()))
Copy link
Member

Choose a reason for hiding this comment

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

we should use f-strings or .format here

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

🎉

Would be good to add a validatehttp check for this as well 👍

if domain.https and not request.is_secure():
# Redirect HTTP -> HTTPS (302) for this custom domain
log.debug('Proxito CNAME HTTPS Redirect: host=%s', host)
return redirect('https://{}{}'.format(host, request.get_full_path()))
Copy link
Member

@ericholscher ericholscher Apr 13, 2020

Choose a reason for hiding this comment

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

If possible, I'd like to see a custom RTD header on here so we know where this request comes from similar to

resp['X-RTD-System-Redirect'] = True

Perhaps X-RTD-HTTPS-Redirect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll do X-RTD-Redirect and the value will be https. I might use the same header with the value canonicalize when doing the domain canonicalization.

@davidfischer
Copy link
Contributor Author

Hold off on merging this. I'm considering a refactor here that might make it easier to canonicalize the domain as well. I might move the actual redirection to ServeRedirectMixin.system_redirect and merely set an attribute on the request object in the Middleware (or rather map_host_to_project_slug)

@davidfischer
Copy link
Contributor Author

I put an alternative implementation (based on this one) in #6905. That one uses the regular resolver code to actually perform the redirect and I think I like that solution a bit better overall. I'm open to feedback on either/both though.

If we want to roll out the HTTP -> HTTPS change separately from canonicalizing the domain, we can merge this, roll this out, and merge that one in the future.

@davidfischer
Copy link
Contributor Author

I'm going to close this in favor of #6905 which seems closer to rolling out.

@stsewd stsewd deleted the davidfischer/custom-domain-https-redirect branch September 15, 2020 17:12
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.

Support HTTPS redirect
4 participants