【问题标题】:IE Edge not honoring Lambda@Edge HSTSIE Edge 不支持 Lambda@Edge HSTS
【发布时间】:2021-01-14 13:19:05
【问题描述】:

我有一个托管在 AWS S3 中的 React 应用程序。为了帮助保护它,我按照 AWS 指南实施了 Lambda@Edge:https://aws.amazon.com/blogs/networking-and-content-delivery/adding-http-security-headers-using-lambdaedge-and-amazon-cloudfront/

Nodejs lambda 托管在弗吉尼亚北部:

'use strict';
exports.handler = (event, context, callback) => {
    
    //Get contents of response
    const response = event.Records[0].cf.response;
    const headers = response.headers;

//Set new headers 
 headers['strict-transport-security'] = [{key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubdomains; preload'}]; 
 headers['content-security-policy'] = [{key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}]; 
 headers['x-content-type-options'] = [{key: 'X-Content-Type-Options', value: 'nosniff'}]; 
 headers['x-frame-options'] = [{key: 'X-Frame-Options', value: 'DENY'}]; 
 headers['x-xss-protection'] = [{key: 'X-XSS-Protection', value: '1; mode=block'}]; 
 headers['referrer-policy'] = [{key: 'Referrer-Policy', value: 'same-origin'}]; 
    
    //Return modified response
    callback(null, response);
};

HSTS 标头和从 HTTP 到 HTTPS 的重定向在 Google Chrome 和 Firefox 中运行良好,但 Internet Explorer Edge 无法重定向。它通过 HTTP 加载页面,并在地址栏旁边显示“不安全”警报。

查看 Internet Explorer 中的网络选项卡会在响应中显示 Strict-Transport-Security 标头。我的所有研究都表明 IE 支持 HSTS,所以我不确定为什么 Edge 不重定向到 HTTPS 而是通过 HTTP 加载页面。我想阻止通过 HTTP 加载任何内容。

我有有效的证书和域以及通过 AWS 购买的所有东西,在 Firefox 和 Chrome 上一切正常,只是在 IE 上不行。

【问题讨论】:

  • 这里没有提到可以解释为什么你会期望有一个从 HTTP 到 HTTPS 的重定向。

标签: amazon-web-services internet-explorer hsts aws-lambda-edge


【解决方案1】:

我在假设 CloudFront 正在执行从 HTTP 到 HTTPS 的重定向的工作的情况下创建了这个。 Michael 的评论让我回去检查我们认为重定向发生在哪里。

原来 CloudFront 有两种行为:

Precedence    Pattern     Origin    Policy
0             *           [URL]     HTTP and HTTPS
1             Default(*)  [URL]     Redirect HTTP to HTTPS

我猜即使它是默认的并且是使用重定向创建的,AWS / Cloudfront 创建了优先级 0,它首先生效并允许 HTTP,无法更改优先级顺序,您必须更改 0 的行为也可以将 HTTP 重定向到 HTTPS。

之后,HSTS 被浏览器记住并使用。

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多