tags:

views:

3172

answers:

7

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.

+4  A: 

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.


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

Espo
... But, FCKEditor uses HTML for its markup, so I can't encode the tags.
Corey Trager
Yep, i changed my answer to reflect that now.
Espo
Thanks for the link to the library.
Corey Trager
+7  A: 

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.

phjr
...this answer is good, in that it understands the problem I'm having with FCKEditor. So, right, I need a server-side .NET compatible equivalent to HTML Purifer, I guess.
Corey Trager
+2  A: 

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.

John Millikin
I understand the DONTS. I'm lacking a DO.
Corey Trager
A: 

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.

John Millikin
Unfortunately, I'm not starting from scratch. The app has already been distributed, with HTML formatted data already in databases...
Corey Trager
A: 

XSS is a tricky thing. I suggest some reading:

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.

Mufasa
+2  A: 

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.

Chris
A: 

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.

Merovech