【发布时间】:2020-07-24 04:18:32
【问题描述】:
根据official AWS documentation,我可以通过AWS Lambda 添加静态Content-Security-Policy 标头。但我想知道是否有办法添加动态nonce-<base64-value> 并在每次查看者刷新页面时更改?
这就是我通过 Node.js 添加 CSP 标头的方式:
'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['content-security-policy'] = [{key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}];
//Return modified response
callback(null, response);
};
但是如何从 Lambda 获取响应正文?
【问题讨论】:
标签: javascript node.js amazon-web-services aws-lambda content-security-policy