我的内容安全策略如下:
内容安全政策: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的“自我”;object-src的'self'; child-src的“自我”;框架祖先的“自我”;形式动作“无”;沙箱allow-same-origins allow-scripts allow-pointer-lock;
您可以使用来部分实现它meta http-equiv
,但是据我了解,它不允许您构架祖先和沙箱。您需要发送一个HTTP标头。但是,我的网络主机不允许来自HTML文件的php命令,无论如何我都希望避免。
长话短说,当我使用杰基尔作为发电机时,我有哪些实施该政策的选择?
听起来您好像已经回答了自己的问题,但您可能不喜欢这个答案。Jekyll只是一个静态HTML生成工具。除了生成包含内联HTML标头的HTML之外,它没有任何其他功能。
如果您无权访问Web服务器(nginx,apache,乘客独立服务器等),因此无法从服务器配置文件写入标头,则必须找到一种方法来生成适当的Jekyll模板中的标题。
您应该可以通过http-equiv
在Jekyll布局文件中正确设置(可能是_layouts/default.html
)来设置自定义标头。将以下内容添加到此文件应该可以帮助您将http-equiv
CSP meta标签包含在默认布局下的Jekyll生成的所有HTML页面中:
<meta http-equiv="X-Content-Security-Policy" content="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;" />
PS-我意识到这不能解决frame-ancestors
您提到的问题。不幸的是,除了与您的网络托管服务提供商合作,看看是否可以让他们以某种方式将CSP标头插入站点配置外,我不知道该答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句