首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IE Edge不支持Lambda@Edge HSTS

IE Edge不支持Lambda@Edge HSTS
EN

Stack Overflow用户
提问于 2020-09-29 07:37:01
回答 1查看 118关注 0票数 0

我在AWS S3中托管了一个React应用程序。为了帮助保护它,我遵循亚马逊网络服务指南实现了Lambda@Edge:https://aws.amazon.com/blogs/networking-and-content-delivery/adding-http-security-headers-using-lambdaedge-and-amazon-cloudfront/

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

代码语言:javascript
复制
'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加载页面,并在地址栏旁边显示警告"Not Secure“。

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

我有有效的证书和域名,以及通过AWS购买的所有东西,所有东西都可以使用Firefox和Chrome正常工作,但不是IE。

EN

回答 1

Stack Overflow用户

发布于 2020-10-01 06:40:25

我创建它的前提是,CloudFront正在执行从HTTP到HTTPS的重定向。Michael的评论让我回去检查我们认为发生了重定向的地方。

原来CloudFront有两种行为:

代码语言:javascript
复制
Precedence    Pattern     Origin    Policy
0             *           [URL]     HTTP and HTTPS
1             Default(*)  [URL]     Redirect HTTP to HTTPS

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

在此之后,浏览器会记住并使用HSTS。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64110968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档