【发布时间】:2021-07-29 18:39:49
【问题描述】:
对于我的公司,我需要更新我们的 Nuxt + Vuetify 应用程序以使用内容安全策略 (CSP) 标头。
'unsafe-inline' 不允许用于 'default-src'。我们目前面临的问题是 Vuetify 在运行时给 DOM 元素添加样式属性。
例如:
<div id="app">
<v-system-bar app>
<v-container>Content</v-container>
</v-system-bar>
</div>
结果:
<div class="v-system-bar v-system-bar--fixed theme--light" style="height: 24px;">
<div class="container">Content</div>
</div>
CSP 标头不允许style="height: 24px"。这给了我以下错误:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src https://unpkg.com/ 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-gGKtWVlwtb9dj1Sa7K4ybKpqUOE61nkachaCJ1LfmFY='), or a nonce ('nonce-...') is required to enable inline execution.
其他 vuetify 组件也会出现此问题,v-system-bar 只是一个示例。我知道可以为<style> 元素添加随机数,但不能为style 属性添加随机数。除了将标头设置为unsafe-inline之外,有没有办法解决这个问题?我想继续使用 Vuetify 和 CSP 标头。
这是一个 codepen 链接:https://codepen.io/erikeuserr/pen/WNpbOwx。
提前致谢!
【问题讨论】:
标签: vue.js nuxt.js vuetify.js content-security-policy