Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon AWS 307 response and permanent redirect to HTTPS

I have a domain from GoDaddy, with AWS Route53 for managing DNS records. Route53 sends request to a load-balancer.

For webserver I have a load-balancer that routes requests to a single (for now) EC2 instance and the nginx in EC2 instance get the request and sends a response to the client.

The problem is that when I use http:// to perform a request, AWS redirects requests to the https:// version of the domain with 307 Internal Redirect response. The response object has Non-Authoritative-Reason: HSTS header as well.

What's the problem and which component is redirect requests?

like image 489
Afshin Mehrabani Avatar asked Feb 18 '15 14:02

Afshin Mehrabani


2 Answers

It's neither component.

This isn't anything from AWS... it's the browser. It's an internal redirect the browser is generating, related to HSTS... HTTP Strict Transport Security.

If you aren't doing it now, then presumably, in the past, you've generated a Strict-Transport-Security: header in responses from this domain, and the browser has remembered this fact, preventing you from accessing the site insecurely, as it is intended to do.

like image 171
Michael - sqlbot Avatar answered Oct 28 '22 21:10

Michael - sqlbot


I know I'm lat eto the party but I wanted to post the actual full solution this this inspired from this post on the Wordpress forums.

Just removing the HSTS header from the server will not solve it because the browser cached the HSTS response and will continue triggering https:// for that website regardless. In Chrome/Chromium you can delete the website from about://net-internals/#hsts but that's hardly a solution for your visitors as you have no idea how many already cached it as HSTS.

On the server side, you need to set max-age=0 which will (as per the RFC) ask the browser to stop considering that host as HSTS.

In Apache, do the following:

<IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=0"
</IfModule>

and make sure you enabled the headers module (you can use a2enmod headers on Ubuntu/Debian/Mint).

like image 32
Normadize Avatar answered Oct 28 '22 21:10

Normadize