技术控

    今日:102| 主题:49113
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Fixing an XSS vulnerability in marked

[复制链接]
萌面超人 发表于 2016-10-5 01:30:17
115 2

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Marked’s protection mechanisms

   While Markdown doesn’t support scripts, marked (like other Markdown clients) does support inline HTML. Inline HTML can include '));
// Outputs:

marked.setOptions({ sanitize: true });
console.log(marked(''));
// Outputs:

[/code]   Catching HTML is important, but sanitization doesn’t end there. While Markdown doesn’t support scripts, it does support links, which creates the potential for javascript links (e.g. javascript:alert(1) ) , which can cause damage when a user clicks them. The sanitize functionality is aware of this, and removes links starting with the javascript: protocol. It even removes links using the HTML entity for colons — e.g. javascript&58;alert(1) . Unfortunately, even with this awareness, they missed one vulnerability vector.
  The Vulnerability

   HTML is a very loose format, and browsers are very tolerant when processing it. An example of this tolerance is that, when processing HTML entities, browsers do not enforce the trailing colon, accepting both : and : . The sanitization in marked, on the other hand, requires the colon, and treats the text as simple text if it doesn’t find it. This means : will be removed, but &58this; will simply be passed along to the output. An attacker can use this technique to evade marked 's sanitizer while browsers still execute a script.
   Here’s a code illustration of where sanitize does and doesn’t work:
  [code]var marked = require('marked');
marked.setOptions({sanitize: true});

// Naive attempt - fails.
console.log(marked('[Gotcha](javascript:alert(1))'));
// Outputs:

)



// Evasion attempt using ':' instead of ':' - fails.
console.log(marked('[Gotcha](javascript:alert(1))'));
// Outputs:



// Evasion attempt using ':this;' (note the 'this') instead of ':' - SUCCEEDS
console.log(marked('[Gotcha](javascript:this;alert(1))'));
// Outputs:

Gotcha


// Same as:

Gotcha

[/code]   The browser will interpret : the same as : , thus invoking the script on click. Of course, the script we included is quite pointless, but an attacker could inject a much more sophisticated payload, breaking the browser’s Same-Origin Policy and triggering the full damage XSS can cause.
  Live Exploit on a Sample Node.js application

   Nothing helps one appreciate a vulnerability better than exploiting it on real code. Therefore, I added this vulnerability to Snyk’s vulnerable demo application, Goof . You can clone Goof and get it running through the instructions on GitHub .
  Goof is a TODO application, and uses marked to support Markdown in its notes. Goof is a best-in-class TODO app, and such an app simply MUST support links, bold and italics!
   For instance, entering the TODO items Buy **beer** and [snyk](https://snyk.io/) would result in the expected bold and hyperlink like so:
     
Fixing an XSS vulnerability in marked-1 (vulnerability,vulnerability,翻译,vulnerabilityscanner,vulnerability,漏洞,vulnerability,source)
      An amazingly feature-complete TODO app.      Next, let’s try to enter a malicious payload. The next screenshot shows the visual and DOM state after entering each of the three attack payloads above. Note that since this is a TODO list, the items are sorted by the date they were added, with the newest on top.

Fixing an XSS vulnerability in marked-2 (vulnerability,vulnerability,翻译,vulnerabilityscanner,vulnerability,漏洞,vulnerability,source)
      Entering malicious payloads into the TODO app.       As you can see, the first two attempted attacks were mitigated by the sanitizer, reduced to

)

and

respectively. The last payload, however, successfully created a hyperlink which will invoke javascript:this;alert(1) . Executing this does nothing (simply references an existing variable), while the alert shows a popup.
  After making our exploit alert a bit clearer and clicking the link, we get this:
12下一页
友荐云推荐




上一篇:Estimating covariate effects after gmm
下一篇:Java Singleton Design Pattern
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

景晓丽 发表于 2016-10-5 04:26:09
学海无涯,回头是岸!  
回复 支持 反对

使用道具 举报

她的枕头 发表于 2016-10-5 04:47:04
好贴,好贴,必须顶一个!
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表