CVE-2024-21650 (Java, published 2024-01-08T16:15Z)
Description: value: XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. XWiki is vulnerable to a remote code execution (RCE) attack through its user registration feature. This issue allows an attacker to execute arbitrary code by crafting malicious payloads in the "first name" or "last name" fields during user registration. This impacts all installations that have user registration enabled for guests. This vulnerability has been patched in XWiki 14.10.17, 15.5.3 and 15.8 RC1.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-94 \u2014 Improper Control of Generation of Code ('Code Injection')
The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
Repository: https://github.com/xwiki/xwiki-platform
Files changed:
xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-docker/src/test/it/org/xwiki/administration/test/ui/RegisterIT.java
xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-ui/src/main/resources/XWiki/RegistrationConfig.xml
xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/RegistrationPage.java
Commit message: XWIKI-21173: Improve escaping in registration success message

* Use $xwiki.getUserName to link to the user profile.
* Add an integration test to test proper escaping.


Vulnerable code:
import java.util.List;
import org.openqa.selenium.WebElement;
            return guestUserRegistration(testUtils, registrationPage);
    private boolean guestUserRegistration(TestUtils testUtils, AbstractRegistrationPage registrationPage)
        List<WebElement> infos = testUtils.getDriver().findElements(By.className("infomessage"));
        for (WebElement info : infos) {
            if (info.getText().contains("Registration successful.")) {
                return true;
            }
        }
        return false;
      <registrationSuccessMessage>#set($fullName = "$request.get('register_first_name') $request.get('register_last_name')")
{{info}}$services.localization.render('core.register.successful', ["[[$fullName&gt;&gt;$userSpace$userName]]", $userName]){{/info}}</registrationSuccessMessage>

Fixed code:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
    @Test
    @Order(8)
    void registerWikiSyntaxName(TestUtils testUtils) throws Exception
    {
        AbstractRegistrationPage registrationPage = setUp(testUtils, false, false);
        String password = "SomePassword";
        String firstName = "]]{{/html}}{{html clean=false}}HT&amp;ML";
        String lastName = "]]{{/html}}";
        String username = "WikiSyntaxName";
        registrationPage.fillRegisterForm(firstName, lastName, username, password, password, "wiki@example.com");
        assertTrue(validateAndRegister(testUtils, false, false, registrationPage));

        assertEquals(String.format("%s %s (%s): Registration successful.", firstName, lastName, username),
            ((RegistrationPage) registrationPage).getRegistrationSuccessMessage().orElseThrow());
    }

            return guestUserRegistration(registrationPage);
    private boolean guestUserRegistration(AbstractRegistrationPage registrationPage)
        return ((RegistrationPage) registrationPage).getRegistrationSuccessMessage().isPresent();
      <registrationSuccessMessage>#set($message = $services.localization.render('core.register.successful', 'xwiki/2.1', ['USERLINK', $userName]))
#set($userLink = $xwiki.getUserName("$userSpace$userName"))
{{info}}$message.replace('USERLINK', "{{html clean=false}}$userLink{{/html}}"){{/info}}</registrationSuccessMessage>
import java.util.List;
import java.util.Optional;

import org.openqa.selenium.By;

    /**
     * @since 14.10.17
     * @since 15.5.3
     * @since 15.8RC1
     *
     * @return the registration success message if present after submitting the registration form
     */
    public Optional<String> getRegistrationSuccessMessage()
    {
        List<WebElement> infos = getDriver().findElements(By.className("infomessage"));
        for (WebElement info : infos) {
            if (info.getText().contains("Registration successful.")) {
                return Optional.of(info.getText());
            }
        }

        return Optional.empty();
    }