1

我正在通过 Github 页面部署 Hugo 站点,但我想添加自定义 HTTP 标头,例如 X-Frame-Options、X-XSS-protections。但是,我尝试按照他们网站的说明将以下代码添加到我的 config.yaml 文件中。但它不起作用。该网站仍然存在标头漏洞。有人可以在这方面帮助我。

  headers:
  - for: /**.html
    values:
      Content-Security-Policy: connect-src api.github.com; font-src cdnjs.cloudflare.com fonts.googleapis.com; img-src 'self' www.countryflags.io; script-src-elem 'unsafe-inline' cdnjs.cloudflare.com 'self'; style-src-attr 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline' cdnjs.cloudflare.com fonts.googleapis.com
      Referrer-Policy: strict-origin-when-cross-origin
      X-Content-Type-Options: nosniff
      X-Frame-Options: DENY
      Strict-Transport-Security = max-age=2592000
      X-XSS-Protection: 1; mode=block
4

1 回答 1

1

我遇到了一个类似的问题——我想在标题中加载一些特定的文件,这取决于前面的变量。

对我来说,问题是通过调整页面的标题和前面的内容来解决的,如下所示。

HTML 布局标题

在标题的布局文件中(例如,hugo > 主题 > your_very_unique_theme > 布局 > header.html),我添加了这行代码:

<!-- Additional Header -->
{{ with .Params.header }} 
  <link rel="stylesheet" href="{{ .some_extra_file }}">
  <script src="{{ .another_extra_file }}"></script>
{{ end }}

页首

然后,在页面的最前面,我写道:

---
title: test page
[...]
header: 
  some_extra_file: "some.css"
  another_extra_file: "extra.js"
---

结果

如果您设置这些参数(some_extra_file 和 another_extra_file),您呈现的 html 将如下所示:

  [...]
  <link href="some.css">
  <link href="extra.js">

如果您不设置这两个参数,则 html 将为空。


我从 hugo discours 的这个帮助线程中获取了 golang 模板代码:https ://discourse.gohugo.io/t/empty-tags-on-param-isset-and-not-empty/4187 。

于 2021-06-21T08:52:52.950 回答