如何通过AWS Lambda + CloudFront + S3设置为内联脚本/样式动态添加CSP nonce属性?

问题描述 投票:0回答:1

根据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
1个回答
0
投票

据我所知,CloudFront配置中有一个复选框,其中包含“将响应正文发送到lambda”

© www.soinside.com 2019 - 2024. All rights reserved.