CVE-2023-29515 (published 2023-04-19T00:15Z)

XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. Any user who can create a space can become admin of that space through App Within Minutes. The admin right implies the script right and thus allows JavaScript injection. The vulnerability can be exploited by creating an app in App Within Minutes. If the button should be disabled because the user doesn't have global edit right, the app can also be created by directly opening `/xwiki/bin/view/AppWithinMinutes/CreateApplication?wizard=true` on the XWiki installation. This has been patched in XWiki 13.10.11, 14.4.8, 14.10.1 and 15.0 RC1 by not granting the space admin right if the user doesn't have script right on the space where the app is created. Error message are displayed to warn the user that the app will be broken in this case. Users who became space admin through this vulnerability won't loose the space admin right due to the fix, so it is advised to check if all users who created AWM apps should keep their space admin rights. Users are advised to upgrade. There are no known workarounds for this vulnerability.

CVSS v3 base score: 5.4, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
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.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/xwiki/xwiki-platform
commit_details: repo_url: https://github.com/xwiki/xwiki-platform
author: Michael Hamann
author_date: 2022-12-01 17:56:50+01:00
msg: XWIKI-20190: Properly handle AWM creation without script right

* Warn when the user doesn't have script right.
* Ensure that in integration tests the users have script right.
* Add an explicit test for the behavior without script right.
* Fix missing dependency.
* Actually delete the preferences in AppsLiveTableIT.
repository: repo_url: https://github.com/xwiki/xwiki-platform
repo_name: xwiki/xwiki-platform
description: The XWiki platform
repo_language: Java
owner: xwiki
file_changes: filename: AllITs.java
change_type: ModificationType.MODIFY
diff: @@ -85,4 +85,10 @@ class NestedUserClassFieldIT extends UserClassFieldIT
     class NestedClassEditorIT extends ClassEditorIT
     {
     }
+
+    @Nested
+    @DisplayName("Without script right test")
+    class NestedWithoutScriptRightIT extends WithoutScriptRightIT
+    {
+    }
 }

programming_language: Java
filename: AppsLiveTableIT.java
change_type: ModificationType.MODIFY
diff: @@ -58,6 +58,9 @@
     @BeforeAll
     public void setupClass(TestUtils testUtils)
     {
+        testUtils.loginAsSuperAdmin();
+        // The application creator needs script rights in order to execute the scripts generated by the wizard.
+        testUtils.setGlobalRights("", "XWiki." + USERNAME, "script", true);
         testUtils.createUserAndLogin(USERNAME, PASSWORD);
     }
 
@@ -179,6 +182,7 @@ void testActionRights(TestUtils testUtils, TestReference testReference)
             assertTrue(appsLiveTable.canEditApplication(appName));
             assertFalse(appsLiveTable.canDeleteApplication(appName));
         } finally {
+            testUtils.loginAsSuperAdmin();
             // We don't want to keep the rights
             testUtils.deletePage(xwikiPreferences);
         }

programming_language: Java
filename: WithoutScriptRightIT.java
change_type: ModificationType.ADD
diff: @@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+package org.xwiki.appwithinminutes.test.ui;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.xwiki.appwithinminutes.test.po.AppWithinMinutesHomePage;
+import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
+import org.xwiki.appwithinminutes.test.po.ApplicationCreatePage;
+import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
+import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
+import org.xwiki.appwithinminutes.test.po.ApplicationsLiveTableElement;
+import org.xwiki.appwithinminutes.test.po.EntryEditPage;
+import org.xwiki.appwithinminutes.test.po.EntryNamePane;
+import org.xwiki.test.docker.junit5.TestReference;
+import org.xwiki.test.docker.junit5.UITest;
+import org.xwiki.test.ui.TestUtils;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests AWM without script right.
+ *
+ * @version $Id$
+ * @since 13.10.11
+ * @since 14.4.8
+ * @since 14.10.1
+ * @since 15.0RC1
+ */
+@UITest
+class WithoutScriptRightIT
+{
+    private static final String USER_NAME = "NoScript";
+
+    private static final String PASSWORD = "password";
+
+    private static final String NO_SCRIPT_ERROR = "You don't have the script right which is necessary to create or "
+        + "edit an application. The application might not work correctly when you continue.";
+
+    @BeforeAll
+    static void beforeAll(TestUtils testUtils)
+    {
+        testUtils.loginAsSuperAdmin();
+        testUtils.createUserAndLogin(USER_NAME, PASSWORD, "");
+    }
+
+    @Order(1)
+    @Test
+    void createApplicationWithoutScriptRight(TestReference testReference)
+    {
+        ApplicationCreatePage appCreatePage = AppWithinMinutesHomePage.gotoPage().clickCreateApplication();
+        String appName = testReference.getLastSpaceReference().getName();
+        appCreatePage.setApplicationName(appName);
+        appCreatePage.waitForApplicationNamePreview();
+        assertTrue(appCreatePage.getContent().contains(NO_SCRIPT_ERROR));
+
+        ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
+        classEditPage.addField("Short Text");
+        ApplicationHomeEditPage applicationHomeEditPage = classEditPage.clickNextStep().clickNextStep();
+        assertTrue(applicationHomeEditPage.getContent().contains(NO_SCRIPT_ERROR));
+
+        ApplicationHomePage applicationHomePage = applicationHomeEditPage.clickFinish();
+        // TODO: change to assert rendering errors when https://jira.xwiki.org/browse/XWIKI-20423 has been fixed.
+        assertTrue(applicationHomePage.hasEntriesLiveTable());
+
+        EntryNamePane entryNamePane = applicationHomePage.clickAddNewEntry();
+        entryNamePane.setName("Test entry");
+        EntryEditPage editPage = entryNamePane.clickAdd();
+        // The edit form doesn't work without script right.
+        assertTrue(editPage.hasRenderingError());
+
+        // Without script right, no delete is available.
+        ApplicationsLiveTableElement liveTable = AppWithinMinutesHomePage.gotoPage().getAppsLiveTable();
+        assertTrue(liveTable.isApplicationListed(appName));
+        assertFalse(liveTable.canDeleteApplication(appName));
+    }
+}

programming_language: Java
filename: WizardIT.java
change_type: ModificationType.MODIFY
diff: @@ -344,10 +344,8 @@ void goBackToFirstStep(TestUtils testUtils, TestReference testReference)
 
     private ApplicationCreatePage goToAppCreatePage(TestUtils testUtils, TestReference testReference)
     {
-        // Register a simple user, login and go to the App Within Minutes home page.
-        String userName = "SimpleUser";
-        String password = "SimplePassword";
-        testUtils.createUserAndLogin(userName, password);
+        // Login and go to the App Within Minutes home page.
+        testUtils.login(USER_NAME, PASSWORD);
         // Make sure the application location exists so that we can select it with the location picker.
         testUtils.createPage(Arrays.asList(getClass().getSimpleName(), testReference.getLastSpaceReference().getName()),
             "WebHome", null, null);

programming_language: Java
filename: pom.xml
change_type: ModificationType.MODIFY
diff: @@ -119,6 +119,12 @@
       <version>${rendering.version}</version>
       <scope>runtime</scope>
     </dependency>
+    <dependency>
+      <groupId>org.xwiki.rendering</groupId>
+      <artifactId>xwiki-rendering-macro-message</artifactId>
+      <version>${rendering.version}</version>
+      <scope>runtime</scope>
+    </dependency>
     <!-- Used to implement drag & drop in the "Structure" (class definition) and  "Presentation" (home page) steps. -->
     <dependency>
       <groupId>org.webjars</groupId>

programming_language: HTML
filename: CreateApplication.xml
change_type: ModificationType.MODIFY
diff: @@ -143,6 +143,11 @@
         $services.localization.render('platform.appwithinminutes.appNameIsUsedWarning')
       &lt;/div&gt;
     #end
+    #if (!$services.security.authorization.hasAccess('script', $xcontext.userReference, $appHomeRef))
+      &lt;div class="box errormessage"&gt;
+        $escapetool.xml($services.localization.render('platform.appwithinminutes.appHomePageNoScriptRight'))
+      &lt;/div&gt;
+    #end
   #end
 #end
 

programming_language: JavaScript
filename: LiveTableEditSheet.xml
change_type: ModificationType.MODIFY
diff: @@ -231,7 +231,9 @@
   ## Grant space administration rights only if the space is new. Don't overwrite existing space preferences.
   #set ($spaceHomeRef = $services.model.resolveDocument('', 'default', $spaceRef))
   #set ($spacePrefsRef = $services.model.resolveDocument('WebPreferences', 'explicit', $spaceRef))
-  #if (!$xwiki.exists($spaceHomeRef) &amp;&amp; !$xwiki.exists($spacePrefsRef))
+  ## Verify that the current user has script right on the current space home.
+  #set ($hasScript = $services.security.authorization.hasAccess('script',  $xcontext.userReference, $spaceHomeRef))
+  #if ($hasScript &amp;&amp; !$xwiki.exists($spaceHomeRef) &amp;&amp; !$xwiki.exists($spacePrefsRef))
     #set ($spacePrefsDoc = $xwiki.getDocument($spacePrefsRef))
     #set ($discard = $spacePrefsDoc.use($spacePrefsDoc.getObject('XWiki.XWikiGlobalRights', true)))
     #set ($discard = $spacePrefsDoc.set('allow', 1))
@@ -353,6 +355,10 @@
 {{/velocity}}
 
 {{velocity}}
+#if (!$services.security.authorization.hasAccess('script', $xcontext.userReference, $doc.documentReference))
+  {{error}}{{translation key="platform.appwithinminutes.appHomePageNoScriptRight" /}}{{/error}}
+
+#end
 #if ("$!request.wizard" == 'true')
   {{include reference="AppWithinMinutes.WizardStep" /}}
 #end

programming_language: PHP
filename: Translations.xml
change_type: ModificationType.MODIFY
diff: @@ -210,6 +210,7 @@
 platform.appwithinminutes.appHomePageTranslateAppLabel=Translate application
 platform.appwithinminutes.appHomePageDeleteAppLabel=Delete application
 platform.appwithinminutes.appHomePageMovedWarning=The application might not function correctly because it has been renamed or moved without updating the code. Please edit the application and follow the steps in order to update the code.
+platform.appwithinminutes.appHomePageNoScriptRight=You don't have the script right which is necessary to create or edit an application. The application might not work correctly when you continue.
 AppWithinMinutes.LiveTableClass_description=Description
 AppWithinMinutes.LiveTableClass_columns=Live Table Columns
 

programming_language: Scala