CVE-2023-29202: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: XWiki Commons are technical libraries common to several other top level XWiki projects. The RSS macro that is bundled in XWiki included the content of the feed items without any cleaning in the HTML output when the parameter `content` was set to `true`. This allowed arbitrary HTML and in particular also JavaScript injection and thus cross-site scripting (XSS) by specifying an RSS feed with malicious content. With the interaction of a user with programming rights, this could be used to execute arbitrary actions in the wiki, including privilege escalation, remote code execution, information disclosure, modifying or deleting content and sabotaging the wiki. The issue has been patched in XWiki 14.6 RC1, the content of the feed is now properly cleaned before being displayed. As a workaround, if the RSS macro isn't used in the wiki, the macro can be uninstalled by deleting `WEB-INF/lib/xwiki-platform-rendering-macro-rss-XX.jar`, where `XX` is XWiki's version, in the web application's directory.
CWE description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
CVSS v3 base score: 9
Published: 2023-04-15T15:15Z
Repository: https://github.com/xwiki/xwiki-platform
Language: Other
Files changed: xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/pom.xml, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/main/java/org/xwiki/rendering/internal/macro/rss/RssMacro.java, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/feed3.xml, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss1.test, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss2.test, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss3.test, xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss4.test
Commit date: 2022-07-07 11:43:12 +0200
Commit message: XWIKI-19671: Filter the feed's content in the RSS macro

Diff: diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/pom.xml b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/pom.xml
index 70ce8330903fe..28f6992a5a607 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/pom.xml
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/pom.xml
@@ -48,10 +48,15 @@
     <dependency>
       <groupId>org.xwiki.rendering</groupId>
       <artifactId>xwiki-rendering-macro-box</artifactId>
       <version>${rendering.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.xwiki.commons</groupId>
+      <artifactId>xwiki-commons-xml</artifactId>
+      <version>${commons.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.xwiki.platform</groupId>
       <artifactId>xwiki-platform-bridge</artifactId>
       <version>${project.version}</version>
     </dependency>
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/main/java/org/xwiki/rendering/internal/macro/rss/RssMacro.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/main/java/org/xwiki/rendering/internal/macro/rss/RssMacro.java
index 26486b2205670..c1131440e9c0a 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/main/java/org/xwiki/rendering/internal/macro/rss/RssMacro.java
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/main/java/org/xwiki/rendering/internal/macro/rss/RssMacro.java
@@ -20,18 +20,21 @@
 package org.xwiki.rendering.internal.macro.rss;
 
 import java.io.StringReader;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.inject.Singleton;
 
 import org.apache.commons.lang3.StringUtils;
+import org.w3c.dom.Document;
 import org.xwiki.bridge.SkinAccessBridge;
 import org.xwiki.component.annotation.Component;
 import org.xwiki.context.Execution;
 import org.xwiki.rendering.block.Block;
 import org.xwiki.rendering.block.GroupBlock;
@@ -47,10 +50,13 @@
 import org.xwiki.rendering.macro.rss.RssMacroParameters;
 import org.xwiki.rendering.parser.ParseException;
 import org.xwiki.rendering.parser.Parser;
 import org.xwiki.rendering.syntax.Syntax;
 import org.xwiki.rendering.transformation.MacroTransformationContext;
+import org.xwiki.xml.html.HTMLCleaner;
+import org.xwiki.xml.html.HTMLCleanerConfiguration;
+import org.xwiki.xml.html.HTMLUtils;
 
 import com.sun.syndication.feed.synd.SyndEntry;
 import com.sun.syndication.feed.synd.SyndFeed;
 
 /**
@@ -100,10 +106,16 @@ public class RssMacro extends AbstractBoxMacro<RssMacroParameters>
      * Needed to keep the feed information.
      */
     @Inject
     private Execution execution;
 
+    /**
+     * To clean the HTML content.
+     */
+    @Inject
+    private HTMLCleaner htmlCleaner;
+
     /**
      * Create a Feed object from a feed specified as a URL.
      */
     private RomeFeedFactory romeFeedFactory = new DefaultRomeFeedFactory();
 
@@ -276,28 +288,56 @@ private void generateEntries(Block parentBlock, SyndFeed feed, RssMacroParameter
                 // is, because some feed will declare text while they actually contain HTML.
                 // See http://stuffthathappens.com/blog/2007/10/29/i-hate-rss/
                 // A case where doing this might hurt is if a feed declares "text" and has any XML inside it does
                 // not want to be interpreted as such, but displayed as is instead. But this certainly is too rare
                 // compared to mis-formed feeds that say text while they want to say HTML.
-                Block html = new RawBlock(entry.getDescription().getValue(), Syntax.XHTML_1_0);
+                Block html = new RawBlock(cleanHTML(entry.getDescription().getValue()), Syntax.HTML_5_0);
                 parentBlock.addChild(new GroupBlock(Arrays.asList(html), Collections.singletonMap(CLASS_ATTRIBUTE,
                     "rssitemdescription")));
             }
         }
     }
 
+    private String cleanHTML(String content)
+    {
+        HTMLCleanerConfiguration cleanerConfiguration = this.htmlCleaner.getDefaultConfiguration();
+        Map<String, String> parameters = new HashMap<>(cleanerConfiguration.getParameters());
+
+        // Just always use HTML 5 as this is what browsers parse.
+        parameters.put(HTMLCleanerConfiguration.HTML_VERSION, "5");
+        // Don't trust remote content.
+        parameters.put(HTMLCleanerConfiguration.RESTRICTED, "true");
+
+        cleanerConfiguration.setParameters(parameters);
+
+        Document document = this.htmlCleaner.clean(new StringReader(content), cleanerConfiguration);
+
+        // Remove the HTML envelope since this macro is only a fragment of a page which will already have an
+        // HTML envelope when rendered. We remove it so that the HTML <head> tag isn't output.
+        HTMLUtils.stripHTMLEnvelope(document);
+
+        // Don't print the XML declaration nor the XHTML DocType.
+        String cleanedContent = HTMLUtils.toString(document, true, true);
+        // Don't print the top level html element (which is always present and at the same location
+        // since it's been normalized by the HTML cleaner)
+        // Note: we trim the first 7 characters since they correspond to a leading new line (generated by
+        // XMLUtils.toString() since the doctype is printed on a line by itself followed by a new line) +
+        // the 6 chars from "<html>".
+        return cleanedContent.substring(7, cleanedContent.length() - 8);
+    }
+
     /**
      * @param romeFeedFactory a custom implementation to use instead of the default, useful for tests
      */
     protected void setFeedFactory(RomeFeedFactory romeFeedFactory)
     {
         this.romeFeedFactory = romeFeedFactory;
     }
 
     /**
      * Convenience method to not have to handle exceptions in several places.
-     * 
+     *
      * @param content the content to parse as plain text
      * @return the parsed Blocks
      * @since 2.0M3
      */
     private List<Block> parsePlainText(String content)
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/feed3.xml b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/feed3.xml
new file mode 100644
index 0000000000000..65cc9b1d17931
--- /dev/null
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/feed3.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<!--
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+
+<rss version="2.0">
+  <channel>
+    <title>Test Feed 3</title>
+    <link>http://localhost/feed.xml</link>
+    <description>A pseudo-feed to test the RSS macro</description>
+    <item>
+      <title>Item1</title>
+      <link>http://localhost/blog/item1</link>
+      <description>An item with &lt;a href="javascript:alert(1)"&gt;dangerous&lt;/a&gt; &lt;b&gt;HTML&lt;/b&gt;markup.</description>
+    </item>
+  </channel>
+</rss>
\ No newline at end of file
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss1.test b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss1.test
index a2cab33beb6e0..33a9f5c82c7ac 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss1.test
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss1.test
@@ -29,24 +29,24 @@ onWord [Star]
 onSpace
 onWord [City]
 endLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp]] [true]
 endParagraph [[class]=[rssitemtitle]]
 beginGroup [[class]=[rssitemdescription]]
-onRawText [How do Americans get ready to work with Russians aboard the International Space Station?] [xhtml/1.0]
+onRawText [<p>How do Americans get ready to work with Russians aboard the International Space Station?</p>] [html/5.0]
 endGroup [[class]=[rssitemdescription]]
 beginParagraph [[class]=[rssitemtitle]]
 beginLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/]] [true]
 onWord [Space]
 onSpace
 onWord [Exploration]
 endLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/]] [true]
 endParagraph [[class]=[rssitemtitle]]
 beginGroup [[class]=[rssitemdescription]]
-onRawText [Sky watchers in Europe, Asia, and parts of Alaska and Canada.] [xhtml/1.0]
+onRawText [<p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p>] [html/5.0]
 endGroup [[class]=[rssitemdescription]]
 endGroup [[class]=[box rssfeed]]
 endMacroMarkerStandalone [testrss] [feed=file://feed1.xml|content=true|count=2|image=true]
 endDocument
 .#-----------------------------------------------------
 .expect|xhtml/1.0
 .#-----------------------------------------------------
-<div class="box rssfeed"><img src="http://www.w3schools.com/images/logo.gif" class="wikimodel-freestanding" alt="http://www.w3schools.com/images/logo.gif"/><br/><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Lift Off News</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription">How do Americans get ready to work with Russians aboard the International Space Station?</div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription">Sky watchers in Europe, Asia, and parts of Alaska and Canada.</div></div>
\ No newline at end of file
+<div class="box rssfeed"><img src="http://www.w3schools.com/images/logo.gif" class="wikimodel-freestanding" alt="http://www.w3schools.com/images/logo.gif"/><br/><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Lift Off News</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription"><p>How do Americans get ready to work with Russians aboard the International Space Station?</p></div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription"><p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p></div></div>
\ No newline at end of file
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss2.test b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss2.test
index e34a3607f5e0e..3efdc9c167979 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss2.test
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss2.test
@@ -26,14 +26,14 @@ beginParagraph [[class]=[rssitemtitle]]
 beginLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
 onWord [Item1]
 endLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
 endParagraph [[class]=[rssitemtitle]]
 beginGroup [[class]=[rssitemdescription]]
-onRawText [An item with<b>HTML</b>markup.] [xhtml/1.0]
+onRawText [<p>An item with<b>HTML</b>markup.</p>] [html/5.0]
 endGroup [[class]=[rssitemdescription]]
 endGroup [[class]=[box rssfeed]]
 endMacroMarkerStandalone [testrss] [feed=file://feed2.xml|content=true|count=1|image=false]
 endDocument
 .#-----------------------------------------------------
 .expect|xhtml/1.0
 .#-----------------------------------------------------
-<div class="box rssfeed"><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml">Test Feed 2</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription">An item with<b>HTML</b>markup.</div></div>
\ No newline at end of file
+<div class="box rssfeed"><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml">Test Feed 2</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription"><p>An item with<b>HTML</b>markup.</p></div></div>
\ No newline at end of file
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss3.test b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss3.test
index 539ba3eaa451a..9f19741322611 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss3.test
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss3.test
@@ -15,24 +15,24 @@ onWord [Star]
 onSpace
 onWord [City]
 endLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp]] [true]
 endParagraph [[class]=[rssitemtitle]]
 beginGroup [[class]=[rssitemdescription]]
-onRawText [How do Americans get ready to work with Russians aboard the International Space Station?] [xhtml/1.0]
+onRawText [<p>How do Americans get ready to work with Russians aboard the International Space Station?</p>] [html/5.0]
 endGroup [[class]=[rssitemdescription]]
 beginParagraph [[class]=[rssitemtitle]]
 beginLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/]] [true]
 onWord [Space]
 onSpace
 onWord [Exploration]
 endLink [Typed = [true] Type = [url] Reference = [http://liftoff.msfc.nasa.gov/]] [true]
 endParagraph [[class]=[rssitemtitle]]
 beginGroup [[class]=[rssitemdescription]]
-onRawText [Sky watchers in Europe, Asia, and parts of Alaska and Canada.] [xhtml/1.0]
+onRawText [<p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p>] [html/5.0]
 endGroup [[class]=[rssitemdescription]]
 endGroup [[class]=[rssfeed]]
 endMacroMarkerStandalone [testrss] [feed=file://feed1.xml|content=true|count=2|decoration=false|encoding=UTF-8]
 endDocument
 .#-----------------------------------------------------
 .expect|xhtml/1.0
 .#-----------------------------------------------------
-<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription">How do Americans get ready to work with Russians aboard the International Space Station?</div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription">Sky watchers in Europe, Asia, and parts of Alaska and Canada.</div></div>
\ No newline at end of file
+<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription"><p>How do Americans get ready to work with Russians aboard the International Space Station?</p></div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription"><p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p></div></div>
\ No newline at end of file
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss4.test b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss4.test
new file mode 100644
index 0000000000000..7ee3c7239899f
--- /dev/null
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-rss/src/test/resources/macrorss4.test
@@ -0,0 +1,27 @@
+.runTransformations
+.#-----------------------------------------------------
+.input|xwiki/2.0
+.# Verify HTML filtering works.
+.#-----------------------------------------------------
+{{testrss feed="file://feed3.xml" content="true" count="2" decoration="false" encoding="UTF-8"/}}
+.#-----------------------------------------------------
+.expect|event/1.0
+.#-----------------------------------------------------
+beginDocument
+beginMacroMarkerStandalone [testrss] [feed=file://feed3.xml|content=true|count=2|decoration=false|encoding=UTF-8]
+beginGroup [[class]=[rssfeed]]
+beginParagraph [[class]=[rssitemtitle]]
+beginLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
+onWord [Item1]
+endLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
+endParagraph [[class]=[rssitemtitle]]
+beginGroup [[class]=[rssitemdescription]]
+onRawText [<p>An item with <a>dangerous</a> <b>HTML</b>markup.</p>] [html/5.0]
+endGroup [[class]=[rssitemdescription]]
+endGroup [[class]=[rssfeed]]
+endMacroMarkerStandalone [testrss] [feed=file://feed3.xml|content=true|count=2|decoration=false|encoding=UTF-8]
+endDocument
+.#-----------------------------------------------------
+.expect|xhtml/1.0
+.#-----------------------------------------------------
+<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription"><p>An item with <a>dangerous</a> <b>HTML</b>markup.</p></div></div>
\ No newline at end of file

Vulnerable code:                 Block html = new RawBlock(entry.getDescription().getValue(), Syntax.XHTML_1_0);
     * 
onRawText [How do Americans get ready to work with Russians aboard the International Space Station?] [xhtml/1.0]
onRawText [Sky watchers in Europe, Asia, and parts of Alaska and Canada.] [xhtml/1.0]
<div class="box rssfeed"><img src="http://www.w3schools.com/images/logo.gif" class="wikimodel-freestanding" alt="http://www.w3schools.com/images/logo.gif"/><br/><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Lift Off News</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription">How do Americans get ready to work with Russians aboard the International Space Station?</div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription">Sky watchers in Europe, Asia, and parts of Alaska and Canada.</div></div>
onRawText [An item with<b>HTML</b>markup.] [xhtml/1.0]
<div class="box rssfeed"><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml">Test Feed 2</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription">An item with<b>HTML</b>markup.</div></div>
onRawText [How do Americans get ready to work with Russians aboard the International Space Station?] [xhtml/1.0]
onRawText [Sky watchers in Europe, Asia, and parts of Alaska and Canada.] [xhtml/1.0]
<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription">How do Americans get ready to work with Russians aboard the International Space Station?</div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription">Sky watchers in Europe, Asia, and parts of Alaska and Canada.</div></div>
Fixed code:     <dependency>
      <groupId>org.xwiki.commons</groupId>
      <artifactId>xwiki-commons-xml</artifactId>
      <version>${commons.version}</version>
    </dependency>
import java.util.HashMap;
import java.util.Map;
import org.w3c.dom.Document;
import org.xwiki.xml.html.HTMLCleaner;
import org.xwiki.xml.html.HTMLCleanerConfiguration;
import org.xwiki.xml.html.HTMLUtils;
    /**
     * To clean the HTML content.
     */
    @Inject
    private HTMLCleaner htmlCleaner;

                Block html = new RawBlock(cleanHTML(entry.getDescription().getValue()), Syntax.HTML_5_0);
    private String cleanHTML(String content)
    {
        HTMLCleanerConfiguration cleanerConfiguration = this.htmlCleaner.getDefaultConfiguration();
        Map<String, String> parameters = new HashMap<>(cleanerConfiguration.getParameters());

        // Just always use HTML 5 as this is what browsers parse.
        parameters.put(HTMLCleanerConfiguration.HTML_VERSION, "5");
        // Don't trust remote content.
        parameters.put(HTMLCleanerConfiguration.RESTRICTED, "true");

        cleanerConfiguration.setParameters(parameters);

        Document document = this.htmlCleaner.clean(new StringReader(content), cleanerConfiguration);

        // Remove the HTML envelope since this macro is only a fragment of a page which will already have an
        // HTML envelope when rendered. We remove it so that the HTML <head> tag isn't output.
        HTMLUtils.stripHTMLEnvelope(document);

        // Don't print the XML declaration nor the XHTML DocType.
        String cleanedContent = HTMLUtils.toString(document, true, true);
        // Don't print the top level html element (which is always present and at the same location
        // since it's been normalized by the HTML cleaner)
        // Note: we trim the first 7 characters since they correspond to a leading new line (generated by
        // XMLUtils.toString() since the doctype is printed on a line by itself followed by a new line) +
        // the 6 chars from "<html>".
        return cleanedContent.substring(7, cleanedContent.length() - 8);
    }

     *
<?xml version="1.0"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<rss version="2.0">
  <channel>
    <title>Test Feed 3</title>
    <link>http://localhost/feed.xml</link>
    <description>A pseudo-feed to test the RSS macro</description>
    <item>
      <title>Item1</title>
      <link>http://localhost/blog/item1</link>
      <description>An item with &lt;a href="javascript:alert(1)"&gt;dangerous&lt;/a&gt; &lt;b&gt;HTML&lt;/b&gt;markup.</description>
    </item>
  </channel>
</rss>
onRawText [<p>How do Americans get ready to work with Russians aboard the International Space Station?</p>] [html/5.0]
onRawText [<p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p>] [html/5.0]
<div class="box rssfeed"><img src="http://www.w3schools.com/images/logo.gif" class="wikimodel-freestanding" alt="http://www.w3schools.com/images/logo.gif"/><br/><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Lift Off News</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription"><p>How do Americans get ready to work with Russians aboard the International Space Station?</p></div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription"><p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p></div></div>
onRawText [<p>An item with<b>HTML</b>markup.</p>] [html/5.0]
<div class="box rssfeed"><p class="rsschanneltitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml">Test Feed 2</a></span><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/feed.xml"><img src="/xwiki/resources/icons/silk/feed.png" alt="/xwiki/resources/icons/silk/feed.png"/></a></span></p><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription"><p>An item with<b>HTML</b>markup.</p></div></div>
onRawText [<p>How do Americans get ready to work with Russians aboard the International Space Station?</p>] [html/5.0]
onRawText [<p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p>] [html/5.0]
<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp">Star City</a></span></p><div class="rssitemdescription"><p>How do Americans get ready to work with Russians aboard the International Space Station?</p></div><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://liftoff.msfc.nasa.gov/">Space Exploration</a></span></p><div class="rssitemdescription"><p>Sky watchers in Europe, Asia, and parts of Alaska and Canada.</p></div></div>
.runTransformations
.#-----------------------------------------------------
.input|xwiki/2.0
.# Verify HTML filtering works.
.#-----------------------------------------------------
{{testrss feed="file://feed3.xml" content="true" count="2" decoration="false" encoding="UTF-8"/}}
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginMacroMarkerStandalone [testrss] [feed=file://feed3.xml|content=true|count=2|decoration=false|encoding=UTF-8]
beginGroup [[class]=[rssfeed]]
beginParagraph [[class]=[rssitemtitle]]
beginLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
onWord [Item1]
endLink [Typed = [true] Type = [url] Reference = [http://localhost/blog/item1]] [true]
endParagraph [[class]=[rssitemtitle]]
beginGroup [[class]=[rssitemdescription]]
onRawText [<p>An item with <a>dangerous</a> <b>HTML</b>markup.</p>] [html/5.0]
endGroup [[class]=[rssitemdescription]]
endGroup [[class]=[rssfeed]]
endMacroMarkerStandalone [testrss] [feed=file://feed3.xml|content=true|count=2|decoration=false|encoding=UTF-8]
endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<div class="rssfeed"><p class="rssitemtitle"><span class="wikiexternallink"><a class="wikimodel-freestanding" href="http://localhost/blog/item1">Item1</a></span></p><div class="rssitemdescription"><p>An item with <a>dangerous</a> <b>HTML</b>markup.</p></div></div>