The following is a security advisory for the Drupal CKEditor. Please note this has also been submitted to the CKEditor project too.

# Exploit Title: Drupal CKEditor 3.6.2 - Persistent EventHandler XSS
# Google Dork: "inurl:"sites/all/modules/ckeditor" -drupalcode.org"
# Google Results: Approximately 379.000 results
# Date: 9th December 2011
# Author: MaXe @InterN0T
# Software Link: http://ckeditor.com/ & http://drupal.org/node/1332022
# Version: 3.6.2 (Drupal module: 6.x-1.8)
# Screenshot: If attached, see image file(s).
# Tested on: Windows + FireFox 8.0 & Internet Explorer 8.0

Drupal CKEditor - Persistent / Stored Cross-Site Scripting

Versions Affected: 3.6.2 (Possibly all versions that supports eventhandler injection.)

Info:
CKEditor is a text editor to be used inside web pages. It's a WYSIWYG editor, which
means that the text being edited on it looks as similar as possible to the results users
have when publishing it. It brings to the web common editing features found on desktop
editing applications like Microsoft Word and OpenOffice.

External Links:
http://ckeditor.com/
http://drupal.org/node/1332022

Credits: MaXe (@InterN0T)

-:: The Advisory ::-
CKEditor is prone to Persistent Cross-Site Scripting within the actual editor, as
it is possible for an attacker could maliciously inject eventhandlers serving java-
script code in preview / editing in html mode.

If an attacker injects an eventhandler into an image, such as "onload='alert(0);'",
then the javascript will execute, even if the data is saved and previewed in editing
mode later on. (The XSS will only executing during preview / editing in html mode.)

If an administrator tries to edit the comment afterward, or is logged in and browses
to the edit page of the malicious comment, then he or she will execute the javascript,
allowing attacker controlled code to run in the context of the browser.

Proof of Concept:
Switching to "raw mode" in CKEditor and then writing:

Only local images are allowed.

Will become this when it is saved:

Only local images are allowed.

If one searches for alert(0); in Firebug after the code has been injected and executed, the location of the script will be: $full_url_to_script/event/seq/4/onload
Where $full_url_to_script is e.g. the following: http://localhost/drupal/drupal-6.22/?q=comment/edit/3/event/seq/4/onload

The content of this script is:
function onload(event) {
alert(0);
}

As there is a HTML filter in Drupal, it does not matter whether the Only local images are allowed. tag is allowed in this case, as it was possible to execute the eventhandler either way. (And even store the data.)

-:: Solution ::-
* Awaits developer response *
Note: It shouldn't be possible to use eventhandlers unless explicitly specified by the administrator of the target site.
All eventhandler input should also be sanitized / encoded to their equivalent htmlentities and encapsulated in quotes.

Disclosure Information:
6th December 2011 - Vulnerability found during a Penetration Test
7th December 2011 - Researched and confirmed the vulnerability
4th January 2012 - Reported to Drupal and CKEditor via http://drupal.org/project/ckeditor and http://dev.ckeditor.com/ and http://cksource.com/contact

There has been no public disclosure of this advisory yet. Please respond back to us whenever a solution is available, or if this is deemed a "non-issue".

CommentFileSizeAuthor
ckeditorxss.png213.58 KBmaxel3g3nd
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maxel3g3nd’s picture

Space added to IMG tags.

Proof of Concept:
Switching to "raw mode" in CKEditor and then writing:

< img onload="alert(0);" src="http://1.images.napster.com/mp3s/2348/resources/324/363/files/324363272.jpg" />

Will become this when it is saved:

< img data-cke-pa-onload="alert(0);" src="http://1.images.napster.com/mp3s/2348/resources/324/363/files/324363272.jpg" data-cke-saved-src="http://1.images.napster.com/mp3s/2348/resources/324/363/files/324363272.jpg" >

mkesicki’s picture

Title: Drupal CKEditor 3.6.2 - Persistent EventHandler XSS » [CKEditor library problem] Drupal + CKEditor 3.6.2 - Persistent EventHandler XSS

@maxel3g3nd thank you for report this. This looks like a problem with CKEditor library. This issue is reported here : http://dev.ckeditor.com/ticket/8630. We have to wait for CKEditor developers.

wwalc’s picture

To prevent against various XSS attacks there is a security section in each CKEditor profile. By default before loading content in "editing mode" ajax requests are executed to strip unsafe content.
E.g. the profile assigned to " Filtered HTML" input format by default executes the "Limit allowed HTML tags" filter, which removes unsafe attributes and tags.

In case of using other filters, e.g http://drupal.org/project/htmlpurifier you should check them in the CKEditor profile and you will be safe as well.

MustLive’s picture

Guys!

I've already wrote to MaXe and to CKEditor trac (http://dev.ckeditor.com/ticket/8630) on Sunday, that I've wrote already about this vulnerability last year. There are two XSS vulnerabilities here: persistent and reflected.

Persistent XSS in Drupal - SecurityVulns ID: 11748 ( http://securityvulns.com/docs26584.html and http://seclists.org/fulldisclosure/2011/Jun/501).

And similar Reflected XSS in Drupal - SecurityVulns ID: 11750 ( http://securityvulns.com/docs26588.html and http://seclists.org/fulldisclosure/2011/Jun/529).

These XSS attacks can be done as via FCKeditor/CKEditor, as via TinyMCE and any other rich editors (with preview functionality). As I've mentioned in publications at my site, these vulnerabilities were found by me at 16.08.2010 (during security audit). After my brief informing about them at 11.12.2010 and detailed informing at 13.04.2011 to Drupal developers, they were ignored and not fixed (so it's no wonder that MaXe have found them). I've announced these vulnerabilities at 12.04.2011 and 13.04.2011, and after giving enough time for developers to fix, they were disclosed at 24.06.2011 and 25.06.2011.

This issue is not in CKEditor itself, but in Drupal (which must properly sanitize the input, if only CKEditor will not have their own XSS filters). And XSS attack can be conducted via any rich editor with preview functionality.

Because these vulnerabilities concern Drupal itself, not only CKEditor (such attack can also be conducted via FCKeditor, TinyMCE and any other rich editors, and it's Drupal's filter fault), I've not informed CKEditor developers, but only Drupal developers. So from MaXe's side, he has did some job to also draw their attention to this issue (and maybe if Drupal is ignoring, then there will be some moving from other side to fix these issues, but it was better for Drupal developers to fix it).

brontide’s picture

...

wwalc’s picture

Status: Needs review » Fixed

This issue, reported as http://dev.ckeditor.com/ticket/8630 for CKEditor, has been fixed in CKEditor 3.6.3. I do agree with MustLive that this problem touches Drupal in general as well, fortunately Drupal 8 will gonna solve this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.