May posting of images through a rich text editor be vulnerable to XSS attacks?

情到浓时终转凉″ 提交于 2019-12-11 07:59:43

问题


I'm using a rich text editor - CKEditor to allow users to input formatted text that renders HTML/CSS.

To prevent XSS attacks by untrusted users, I'm using the Jsoup Java library which filters/whiltelists necessary tags and/or attributes of the user input something like, for example, an anchor tag like,

<a href='http://example.com/' onclick='executeMaliciousTask();'>Click Here</a>

is turned into

<a href="http://example.com/" rel="nofollow">Click Here</a>

The link generated by Jsoup seems to be safe against XSS attacks.


I need to allow users to input images through the editor. For this to be so, I'm using using the following method of Jsoup.

org.jsoup.Jsoup.clean(editorContents, org.jsoup.safety.Whitelist.basicWithImages();

May allowing users to post images in this way be vulnerable to XSS attacks in any way?


回答1:


The risk is not in the clean HTML generated, but in the server that provides the image. My main concern would be CSRFs. But there could be other issues (like an malicious images causing a buffer overrun, or changing the response content-type and fooling the browser into executing script, or setting tracking cookies, etc).

My suggestion would be not to allow images to be remotely hosted. Allow the user to include an img, but fetch the image, validate / normalize it, and serve it from your own host.



来源:https://stackoverflow.com/questions/20021330/may-posting-of-images-through-a-rich-text-editor-be-vulnerable-to-xss-attacks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!