在 CSP 标头中,Chrome 表示我的单引号 sha256 哈希值包含无效字符,但这看起来不正确

gbu*_*ton 8 google-chrome content-security-policy

我在脚本源中有许多 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\-

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

我相信错误消息具有误导性,并且哈希值还存在其他问题。

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

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

Hal*_*aug 7

Chrome 认为你的哈希值是一个指令。

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

看起来您正在插入像指令一样的源。CSP 的结构为 <directive> <source> ... <source>;<指令> <源> ... <源>; ...另请参阅https://content-security-policy.com/

  • 我意识到一个杂散的分号似乎是原因。script-src 部分已提前结束。 (2认同)