Affects Version/s: 1.10
Fix Version/s: 1.11
The popular Greasemonkey browser extension in FIrefox can inject <script> elements into the <body> of the CKEditor's IFRAME. These <script> elements' contents then get erroneously transformed into HTML-encoded markup that gets saved into the wiki page content.
I was able to repro on Firefox/Greasemonkey using the following fabricated script:
1. Install Greasemonkey for Firefox and add the above userscript to it.
2. Open any XWiki CKEditor page.
3. Switch to Source edit mode.
4. Observe that part of the GM script gets injected as content into the editor.
The same issue occurs if you just "Save" instead of switching to Source edit mode at step 3 above.
Note that this issue does NOT repro on TamperMonkey/Chrome, evidently because GM runs in the context of each IFRAME on the page whereas TM only runs in the root <body>.
My understanding is that it's not possible for a webpage to detect whether Greasemonkey is running – and this is by design.
However, one possible reasonable fix may be to strip out any <script> elements present in the CKEditor WYSIWYG IFRAME before saving or going to Source view.
This approach should work since a user would not normally be able to add an unencoded <script> tag to the WYSIWYG editor, and even in CKEditor's Source edit mode, typing in e.g. "<script>alert(1);</script>" gets transformed into "<script>alert(1);</script>" when you switch back to WYSIWYG mode.
And in the case where you write something like
in Source edit mode, that gets transformed into
... so again, this is distinct from Greasemonkey's injection of unescaped <script> elements, and thus we should still be able to safely strip out unescaped <script> elements to handle this scenario.
This would not mitigate the potential for other kinds of HTML elements to be injected into the IFRAME body, but in the case of Greasemonkey scripts, the injection of <script> tags are by far the most common scenario, so this proposed fix seems like an appropriate solution for the specific issue outlined above.