CSP style-src:“不安全内联"-值得吗? [英] CSP style-src: 'unsafe-inline' - is it worth it?

查看:70
本文介绍了CSP style-src:“不安全内联"-值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我在所有网站上都使用Modernizr,事实证明,由于其工作方式,它要求允许使用 unsafe-inline 样式.我已经不允许内联脚本和不安全评估脚本了.好奇允许内嵌样式存在哪些安全风险?

Currently I'm using Modernizr on all my sites and it turns out because of how it works it requires unsafe-inline styles to be allowed. I am already not allowing inline scripts and unsafe-eval for scripts. Curious as to what security risks there are for allowing inline styles?

推荐答案

允许内联样式使您容易受到其他XSS"的影响.跨站点样式攻击.

Allowing inline styles makes you susceptible to a the "other XSS". Cross Site Styling attacks.

这里的想法是,用户可以在任何可以将样式属性注入文档中的地方,以他们想要的任何方式来修改页面的外观.我将按照严重性从高到低列出几种潜在的攻击方式:

The idea here is that any places where a user can inject a style attribute into your document they can modify the appearance of your page any way they want. I'll list a couple potential attacks ordered by increasing severity:

  1. 他们可以将您的页面变成粉红色,并使其看起来很傻.
  2. 他们可以修改您页面的文字,使其看起来像是您在说些冒犯读者的冒犯性内容.
  3. 他们可以使用户生成的内容(如他们提供的链接)出现在人们希望看到用户内容的正常位置之外,从而使其显得正式.(例如,用自己的链接替换您网站上的登录"按钮).
  4. 使用精心设计的样式规则,他们可以将页面上包含的所有信息发送到外部域,并对用户公开或以其他方式恶意使用该数据.

第四个示例,即使 unsafe-inline ,也可以完全防止信息泄漏到外部域,前提是您确保其他CSP规则绝不允许任何类型的请求发送到不可信或通配符域.但是,如果您错过在某处阻止样式属性的话,前三个总是可能的.

The fourth example, with the information being leaked to external domains could be entirely prevented in spite of the unsafe-inline provided you ensure your other CSP rules never allow any kind of request to go to a untrusted or wildcard domain. But the first 3 will always be possible if you miss blocking a style attribute somewhere.

Mike West 做的很好

Mike West did a good talk on this for CSSConf a few years back for some more examples.

这篇关于CSP style-src:“不安全内联"-值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆