【问题标题】:Firebase hosting CSP nonce implementationFirebase 托管 CSP 随机数实施
【发布时间】:2021-06-28 17:57:20
【问题描述】:

我一直在为我的 Firebase 托管网站开发 CSP,大量请求被 CSP 阻止,因为 GTM(Google 跟踪代码管理器)位于内联脚本中。

我正在使用 Firebase Analytics,这就是将 GTM 注入页面的原因。 我读过我可以使用 nonce [1],在大多数情况下,这不是实现的问题。 这将如何使用 Firebase 托管来实现? - 根据我的研究,Firebase 托管标头在部署后无法修改。

1:https://developers.google.com/tag-manager/web/csp

【问题讨论】:

    标签: firebase google-tag-manager firebase-hosting content-security-policy


    【解决方案1】:

    是的,您可以,您应该在项目文件夹的根目录中有一个 firebase.json 文件,您可以在其中更改标题,检查我的文件:

    {
      "hosting": {
        "public": "dist/browser",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ],
        "headers": [
          {
            "source": "**/*.@(jpg|jpeg|gif|png|webp|eot|otf|ttf|ttc|woff)",
            "headers": [
              {
                "key": "Cache-Control",
                "value": "max-age=7200"
              }
            ]
          },
          {
            "source": "**/*.@(html|js|css)",
            "headers": [
              {
                "key": "Cache-Control",
                "value": "no-cache, no-store, must-revalidate"
              }
            ]
          },
          {
            "source": "**",
            "headers": [
              {
                "key": "X-Frame-Options",
                "value": "SAMEORIGIN"
              }
            ]
          },
          {
            "source": "**",
            "headers": [
              {
                "key": "X-Content-Type-Options",
                "value": "nosniff"
              }
            ]
          },
          {
            "source": "**",
            "headers": [
              {
                "key": "Referrer-Policy",
                "value": "strict-origin"
              }
            ]
          },
          {
            "source": "**",
            "headers": [
              {
                "key": "Permissions-Policy",
                "value": "geolocation=(), microphone=(), gyroscope=()"
              }
            ]
          }
        ]
      }
    }
    

    不幸的是,我有义务从中删除我的 csp...

    【讨论】:

      猜你喜欢
      • 2015-12-23
      • 2013-06-12
      • 1970-01-01
      • 2017-08-22
      • 2018-07-05
      • 1970-01-01
      • 2021-12-10
      • 2017-11-14
      • 2020-06-17
      相关资源
      最近更新 更多