CVE-2023-50722 (XML, published 2023-12-15T19:15Z)
Description: value: XWiki Platform is a generic wiki platform. Starting in 2.3 and prior to versions 14.10.15, 15.5.2, and 15.7-rc-1, there is a reflected XSS or also direct remote code execution vulnerability in the code for displaying configurable admin sections. The code that can be passed through a URL parameter is only executed when the user who is visiting the crafted URL has edit right on at least one configuration section. While any user of the wiki could easily create such a section, this vulnerability doesn't require the attacker to have an account or any access on the wiki. It is sufficient to trick any admin user of the XWiki installation to visit the crafted URL. This vulnerability allows full remote code execution with programming rights and thus impacts the confidentiality, integrity and availability of the whole XWiki installation. This has been fixed in XWiki 14.10.15, 15.5.2 and 15.7RC1. The patch can be manually applied to the document `XWiki.ConfigurableClass`.

Severity: nan (CVSS v3 base score: 8.8)
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-administration/xwiki-platform-administration-ui/src/main/resources/XWiki/ConfigurableClass.xml
xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-ui/src/test/java/org/xwiki/administration/ConfigurableClassPageTest.java
Commit message: XWIKI-21167: Improve escaping of space parameter in ConfigurableClass


Vulnerable code:
    #set($queryString = "space=${currentSpace}&amp;amp;section=")

Fixed code:
    #set($queryString = "space=$escapetool.url($currentSpace)&amp;amp;section=")
import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.apache.http.client.utils.URLEncodedUtils;
import static org.junit.jupiter.api.Assertions.fail;

    @Test
    void escapeSectionLink() throws Exception
    {
        // Create a new section document.
        XWikiDocument mySectionDoc = new XWikiDocument(MY_SECTION);
        BaseObject object = mySectionDoc.newXObject(CONFIGURABLE_CLASS, this.context);
        object.setStringValue("displayInCategory", "other");
        object.setStringValue("displayInSection", "other");
        object.set("scope", "WIKI+ALL_SPACES", this.context);
        this.xwiki.saveDocument(mySectionDoc, this.context);

        // Make sure the section document is returned by the query and the user has access to edit.
        when(this.query.execute()).thenReturn(List.of(MY_SECTION_SERIALIZED)).thenReturn(List.of());
        when(this.oldcore.getMockRightService()
            .hasAccessLevel(eq("edit"), any(), any(), any())).thenReturn(true);

        // Set a new document with space ">{{/html}}{{noscript /}} as context document to check escaping of the
        // current space.
        String spaceName = "\">{{/html}}{{noscript /}}";
        DocumentReference docRef = new DocumentReference(WIKI_NAME, spaceName, "WebHome");
        XWikiDocument contextDoc = new XWikiDocument(docRef);
        this.xwiki.saveDocument(contextDoc, this.context);
        this.context.setDoc(contextDoc);

        XWikiDocument doc = loadPage(CONFIGURABLE_CLASS);
        Document htmlPage = renderHTMLPage(doc);
        String link = Objects.requireNonNull(htmlPage.selectFirst("li.other a")).attr("href");
        URI uri = new URI(link);
        // Parse the query parameters and check the space name.
        URLEncodedUtils.parse(uri, StandardCharsets.UTF_8).stream()
            .filter(pair -> pair.getName().equals("space"))
            .findFirst()
            .ifPresentOrElse(pair -> assertEquals(spaceName, pair.getValue()), () -> fail("No space parameter in URL"));
    }