在 CSP header Chrome 中说我的单引号 sha256 哈希包含无效字符,但这看起来不正确

In CSP header Chrome says my single quoted sha256 hash contains invalid characters but this looks incorrect

我在脚本源中有一些 sha256 哈希值。 chrome 给我第一个错误;

The Content-Security-Policy directive name ''sha256-OIf-redacted-bJEXc='' contains one or more invalid characters. Only ASCII alphanumeric characters or dashes '-' are allowed in directive names.

编辑部分仅包含 a-zA-Z0-9\-

如果我删除引号(唯一的 non-compliant 字符),它根本无法识别该部分。

我被引导相信错误消息具有误导性并且哈希还有其他问题。

真正的问题是什么?为什么 chrome 不接受这些指令?

header 看起来像这样: default-src 'none'; script-src 'self' https://consentcdn.cookiebot.com/ https://consent.cookiebot.com/ ; 'sha256-e-redacted-A=' ...more stuff...

Chrome 认为你的散列是指令。

您应该首先插入指令,在您的情况下是 script-src 或 default-src,然后添加源,例如哈希、'self' 或指定的域。

您好像是在插入指令之类的源代码。 CSP 的结构是 ... ; <指令> <来源> ... <来源>; ... 另见 https://content-security-policy.com/