I would like to implement HSTS to my application.
I have an ELB terminating SSL and forwarding the traffic to my application, which is an apache server used as reverse p
I asked the AWS Support and the answer was that at the moment ELB cannot add HSTS headers on the requests from the clients. So, I decided to find a workaround using my Apache server. Here is the solution I found:
The HSTS RFC states that
An HSTS Host MUST NOT include the STS header field in HTTP responses conveyed over non-secure transport.
What I did then was to set the header AFTER the http=>https redirection in Apache. Since this redirection has the flag [L], that means that the 301 redirection will not include the header, but any https request will. My apache config looks like this:
...
#http=>https
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
#hsts
Header set Strict-Transport-Security "max-age=31536000"