大家有没有遇到过 Nginx 配置 CSP,页面触发了 javascript:history.go(-1);导致被阻止的?

2021-06-29 23:49:09 +08:00
 daimaosix

做了一个网页,用 HTML 标签写了一个返回上一页

<a href="javascript:history.go(-1);" class="button">返回</a>

结果 Chrome 提示了以下信息

Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "default-src 'self'". 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. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

网站用 Nginx 配置了一个 CSP 规则,但是遇到这个问题不知道怎么改规则了,好像怎么改都不起作用,以下是 CSP 规则:

default-src 'self'; media-src https://abc.com; style-src 'self' 'unsafe-inline' https://abc.com; font-src 'self' data: https://abc.com;

找了一下资料也挺少的,唯一找到了一个 stackoverflow 的问题: https://stackoverflow.com/questions/63832626/why-cant-i-get-around-my-csp-blocking-my-javascript-code-in-nunjucks-when-i-use,但是没怎么看明白,大概意思可能是这种方式 CSP 还不支持直接配置,看样子是需要改代码。有知道的大佬吗?

858 次点击
所在节点    NGINX
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/786574

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX