我在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托管在弗吉尼亚州北部:
'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。
发布于 2020-10-01 06:40:25
我创建它的前提是,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。
https://stackoverflow.com/questions/64110968
复制相似问题