CSP 阻止我的本地 js 文件。 这是我的 nuxt.config.js
unsafeInlineCompatibility: true,
policies: {
'default-src': ["'self'", 'delivly.com', 'localhost', '*.gstatic.com', '*.fontawesome.com'],
'script-src': ["'unsafe-inline'", 'delivly.com', 'localhost', '*.fontawesome.com', '*.googlesyndication.com', '*.googletagmanager.com'],
'style-src': ["'self'", "'unsafe-inline'", 'delivly.com', '*.googleapis.com', '*.fontawesome.com'],
'connect-src': ["'self'", 'wss://delivly.com']
},
addMeta: true
}
阻止的文件:
http://localhost:3010/_nuxt/runtime.js
http://localhost:3010/_nuxt/pages_index.js
http://localhost:3010/_nuxt/commons.app.js
http://localhost:3010/_nuxt/vendors.app.js
http://localhost:3010/_nuxt/app.js
有谁知道问题出在哪里吗?
最佳答案
我知道现在回答 topicstarter 已经太晚了,但也许它会对“新一代”派上用场。
localhost
充当主机源,但主机源仅允许标准端口。
在 HTTP:-page 上,localhost
将转换为 http://localhost
(同源策略用于恢复方案)。对于 http://
方案,标准端口为 80,因此任何其他端口都将被 CSP 禁止(CSP3 浏览器也将允许端口 443)。
要允许任何端口,需要使用 *
作为端口号,如下所示:
'default-src': ['localhost:*']
或指定真实端口号:
'default-src': ['localhost:3010']
关于vue.js - NUXT 中的 CSP 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60776336/