Как исправить проблему CSP со встроенным скриптом?
Я использую шаблон Hugo для веб-сайта и устанавливаю заголовки CSP:
headers['content-security-policy'] = { value: "default-src https://www.google-analytics.com; img-src 'self' https://www.google-analytics.com ssl.google-analytics.com www.google.com analytics.google.com; connect-src www.google-analytics.com stats.g.doubleclick.net ampcid.google.com analytics.google.com; script-src 'self' https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com https://google-analytics.com; style-src 'self' https://cdnjs.cloudflare.com; object-src 'none'; frame-ancestors 'none'"};
Тем не менее я вижу такие ошибки:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com https://google-analytics.com". Either the 'unsafe-inline' keyword, a hash ('sha256-0CvETIgOK2clmfWGF5sSIEiekhHQQDQzs6qA3VIIZiU='), or a nonce ('nonce-...') is required to enable inline execution.
Я не хочу добавлять
unsafe-inline
. Пытался добавить хеш (
sha256-0CvETIgOK2clmfWGF5sSIEiekhHQQDQzs6qA3VIIZiU=
) в мой script-src, но это тоже не помогло. Как лучше решить эту проблему? Поскольку я использую шаблон Hugo, я не могу обновить код. (это подмодуль git).
Обновление: если я напишу sha в одинарных кавычках, ошибка исчезнет, но я получу одну последнюю ошибку:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' all-urls-and-sha's". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.