CVE-2023-29202 (Other, published 2023-04-15T15:15Z)
Description: 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.
Severity: nan (CVSS v3 base score: 9)
Weakness: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
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.
Repository: https://github.com/xwiki/xwiki-platform
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 message: XWIKI-19671: Filter the feed's content in the RSS macro


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>