html - 使用 Jekyll 实现内容安全策略

标签 html jekyll content-security-policy

我的内容安全政策如下:

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/

相关文章:

html - 将 Span 元素定位在 Table 元素上的 CSS 解决方案

pagination - Jekyll 分页

javascript - Jekyll 网站未设置图标

ruby - "/usr/bin/env: ruby_executable_hooks: No such file or directory"怎么解决?

html - 如何在 css 的第一个 p 标签之后选择一个 img?

html - 垂直对齐位于 LI 内的 float DIV 内的元素

html - HTML 元标记中的内容安全策略 ~ 这安全吗?

javascript - 内容安全策略。网络组件。 script src DataURI 。我可以通过 META 标记覆盖 HTTP HEADER 吗?

html - Firefox iframe 中的 CSP header 在具有动态内容的整个页面上工作

javascript - 使用 JavaScript 从另一个页面修改一个页面的 HTML 值