简体   繁体   English

如何使用 AWS Lambda + CloudFront + S3 设置为内联脚本/样式动态添加 CSP 随机数属性?

[英]How to dynamically adds CSP nonce attributes for inline scripts/styles with AWS Lambda + CloudFront + S3 setup?

According to official AWS documentation , I can add static Content-Security-Policy headers via AWS Lambda.根据官方 AWS 文档,我可以通过 AWS Lambda 添加 static Content-Security-Policy标头。 But I'd like to know if there's a way to add dynamic nonce-<base64-value> and change every time the viewer refresh the page?但我想知道是否有办法添加动态nonce-<base64-value>并在每次查看器刷新页面时更改?

This is how I add CSP headers via Node.js:这就是我通过 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);
};

But how can I get the response body from Lambda?但是我怎样才能从 Lambda 获得响应体?

As I know there is a checkbox in CloudFront configuration with "Send response body to lambda"据我所知,CloudFront 配置中有一个带有“将响应正文发送到 lambda”的复选框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在遵守不允许使用内联脚本的CSP的情况下动态设置Google Universal Analytics的跟踪代码? - How can I dynamically set the tracking code for Google Universal Analytics while adhering to a CSP that disallows inline scripts? 属性内内联 JS 的 CSP 哈希或随机数 - CSP hash or nonce for inline JS within attribute 将具有随机数的 CSP 标头添加到 Lambda 边缘 - Adding CSP headers with a nonce to Lambda Edge 适用于视频文件的AWS S3和Cloudfront CDN - AWS S3 and Cloudfront CDN for video files 多个内联脚本的CSP解决方案 - CSP solution for multiple inline scripts 如何允许内联 JS 脚本使用 Nonce 进行 CSP - How to allow Inline JS Scripts using Nonces for CSP 如何在没有内联脚本的情况下异步加载 CSS(符合 CSP) - How to load CSS Asynchronously without Inline Scripts (comply with CSP) 如何使用AWS Lambda下载大型S3文件(javascript) - How to download a large S3 file with AWS Lambda (javascript) 如何使用AWS S3 URL设置凭证? - How to use AWS S3 url setup credentials? 如何在没有NodeJ的情况下使用javascript sdk为s3视频创建AWS CloudFront签名的URL - How to create AWS CloudFront signed url for s3 video using javascript sdk without NodeJs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM