我的内容安全政策如下:
Content-Security-Policy: default-src 'self' https://fonts.googleapis.com https://ajax.googleapis.com; script-src 'self' https://fonts.googleapis.com https://ajax.googleapis.com; style-src 'self' https://fonts.googleapis.com; img-src 'self' ; font-src 'self' https://fonts.googleapis.com; connect-src 'self' https://ajax.googleapis.com; media-src 'self' ; object-src 'self' ; child-src 'self' ; frame-ancestors 'self' ; form-action 'none' ; sandbox allow-same-origin allow-scripts allow-pointer-lock;
您可以使用 meta http-equiv
部分实现它,但据我所知,它不允许您构建祖先和沙盒。您需要发送一个 http header 。但是,我的虚拟主机不允许来自 HTML 文件的 php 命令,无论如何我都想避免它。
长话短说,在使用 Jekyll 作为生成器时,我有哪些选择来实现此策略?
最佳答案
要在本地进行测试,您可以使用 Jekyll 指定自定义 header 。在你的 _config.yml
添加:
# Custom headers
webrick:
headers:
Content-Security-Policy: default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';
My-Other-Header: My-Other-Value
来源:https://jekyllrb.com/docs/configuration/#custom-webrick-headers
关于html - 使用 Jekyll 实现内容安全策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39192352/