How to implement HTTP Strict Transport Security (HSTS) on AWS Elastic Load Balancer?

前端 未结 4 1229
臣服心动
臣服心动 2021-02-20 17:04

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

4条回答
  •  情书的邮戳
    2021-02-20 17:46

    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"
    

提交回复
热议问题