How do use fckEditor safely, without risk of cross

2020-07-22 09:43发布

问题:

This link describes an exploit into my app using fckEditor: http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html

How do I make my app secure while still using fckEditor? Is it an fckEditor configuration? Is it some processing I'm supposed to do server-side after I grab the text from fckEditor?

It's a puzzle because fckEditor USES html tags for its formatting, so I can't just HTML encode when I display back the text.

回答1:

Sanitize html server-side, no other choice. For PHP it would be HTML Purifier, for .NET I don't know. It's tricky to sanitize HTML - it's not sufficient to strip script tags, you also have to watch out for on* event handlers and even more, thanks to stupidities of IE for example.

Also with custom html and css it's easy to hijack look and layout of your site - using overlay (absolutely positioned) which covers all screen etc. Be prepared for that.



回答2:

The bug is not actually FCKeditors fault. As long as you let users edit HTML that will be displayed on your web site they will always have to possibility to do harm unless you check the data before you output it.

Some people use HTMLencoding to do this, but that will destroy all the formatting done by FCKeditor, not what you want.


Maybe you can use the Microsoft Anti-Cross Site Scripting Library. Samples on MSDN



回答3:

Is it some processing I'm supposed to do server-side after I grab the text from fckEditor?

Precisely. StackOverflow had some early issues related to this as well. The easiest way to solve it is to use an HTML library to parse user's input, and then escape any tags you don't want in the output. Do this as a post-processing step when printing to the page -- the data in the database should be the exact same as what the user typed in.

For example, if the user enters <b><script>evil here</script></b>, your code would translate it to <b>&lt;script&gt;evil here&lt;/script&gt;</b> before rendering the page.

And do not use regular expressions for solving this, that's just an invitation for somebody clever to break it again.



回答4:

FCKEditor can be configured to use only a few tags. You will need to encode everything except for those few tags.

Those tags are: <strong> <em> <u> <ol> <ul> <li> <p> <blockquote> <font> <span>.

The font tag only should have face and size attributes. The span tag should only have a class attribute.

No other attributes should be allowed for these tags.



回答5:

I understand the DONTS. I'm lacking a DO.

Is use of FCKEditor a requirement, or can you use a different editor/markup language? I advise using Markdown and WMD Editor, the same language used by StackOverflow. The Markdown library for .NET should have an option to escape all HTML tags -- be sure to turn it on.



回答6:

XSS is a tricky thing. I suggest some reading:

  • Is HTML a Humane Markup Language?
  • Safe HTML and XSS

Anyway, my summary is when it comes down to it, you have to only allow in strictly accepted items; you can't reject known exploit vectors because or you'll always be behind the eternal struggle.



回答7:

I think the issue raised by some is not that Fckeditor only encodes a few tags. This is a naive assumption that an evil user will use the Fckeditor to write his malice. The tools that allow manual changing of input are legion.

I treat all user data as tainted; and use Markdown to convert text to HTML. It sanitizes any HTML found in the text, which reduces malice.



标签: xss fckeditor