CVE-2023-35152: Improper Control of Generation of Code ('Code Injection') (CWE-94)
value: XWiki Platform is a generic wiki platform. Starting in version 12.9-rc-1 and prior to versions 14.4.8, 14.10.6, and 15.1, any logged in user can add dangerous content in their first name field and see it executed with programming rights. Leading to rights escalation. The vulnerability has been fixed on XWiki 14.4.8, 14.10.6, and 15.1. As a workaround, one may apply the patch manually.
CWE description: 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.
CVSS v3 base score: 8.8
Published: 2023-06-23T17:15Z
Repository: https://github.com/xwiki/xwiki-platform
Language: XML
Files changed: xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/pom.xml, xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/main/resources/XWiki/Like/Code/LiveTableResultPage.xml, xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/test/java/org/xwiki/like/LiveTableResultPagePageTest.java
Commit date: 2023-02-21 14:25:42 +0100
Commit message: XWIKI-19900: Liked page whose FULLNAME contains dot(.) can not show in user profile.

Diff: diff --git a/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/pom.xml b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/pom.xml
index 9c8c6eba053fc..9ede5b0ceea6a 100644
--- a/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/pom.xml
+++ b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/pom.xml
@@ -68,7 +68,34 @@
       <type>xar</type>
       <version>${project.version}</version>
       <scope>runtime</scope>
       <optional>true</optional>
     </dependency>
+    <!-- Test dependencies. -->
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-test-page</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-web-templates</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-like-api</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-user-default</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
   </dependencies>
 </project>
diff --git a/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/main/resources/XWiki/Like/Code/LiveTableResultPage.xml b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/main/resources/XWiki/Like/Code/LiveTableResultPage.xml
index 88632a7b83fb3..a451df6d3d22d 100644
--- a/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/main/resources/XWiki/Like/Code/LiveTableResultPage.xml
+++ b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/main/resources/XWiki/Like/Code/LiveTableResultPage.xml
@@ -34,11 +34,11 @@
   <title/>
   <comment/>
   <minorEdit>false</minorEdit>
   <syntaxId>xwiki/2.1</syntaxId>
   <hidden>true</hidden>
-  <content>{{velocity}}
+  <content>{{velocity wiki="false"}}
 #if ($xcontext.action == 'get')
   #template('hierarchy_macros.vm')
   #if("$!{request.xpage}" == 'plain')
     $response.setContentType('application/json')
   #end
diff --git a/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/test/java/org/xwiki/like/LiveTableResultPagePageTest.java b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/test/java/org/xwiki/like/LiveTableResultPagePageTest.java
new file mode 100644
index 0000000000000..56e4e92d942d5
--- /dev/null
+++ b/xwiki-platform-core/xwiki-platform-like/xwiki-platform-like-ui/src/test/java/org/xwiki/like/LiveTableResultPagePageTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.like;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.junit.jupiter.api.Test;
+import org.xwiki.like.script.LikeScriptServiceComponentList;
+import org.xwiki.model.reference.DocumentReference;
+import org.xwiki.model.script.ModelScriptService;
+import org.xwiki.ratings.RatingsManager;
+import org.xwiki.ratings.internal.DefaultRating;
+import org.xwiki.rendering.syntax.Syntax;
+import org.xwiki.template.script.TemplateScriptService;
+import org.xwiki.test.annotation.ComponentList;
+import org.xwiki.test.junit5.mockito.MockComponent;
+import org.xwiki.test.page.PageTest;
+import org.xwiki.test.page.XWikiSyntax21ComponentList;
+import org.xwiki.user.UserReferenceComponentList;
+
+import com.xpn.xwiki.doc.XWikiDocument;
+
+import net.sf.json.JSONObject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test of {@code XWiki.Like.Code.LiveTableResultPage}.
+ *
+ * @version $Id$
+ * @since 15.1
+ * @since 14.10.6
+ */
+@XWikiSyntax21ComponentList
+@LikeScriptServiceComponentList
+@UserReferenceComponentList
+@ComponentList({
+    TemplateScriptService.class,
+    ModelScriptService.class
+})
+class LiveTableResultPagePageTest extends PageTest
+{
+    private static final DocumentReference DOCUMENT_REFERENCE =
+        new DocumentReference("xwiki", List.of("XWiki", "Like", "Code"), "LiveTableResultPage");
+
+    @MockComponent
+    @Named("solr")
+    private RatingsManager ratingsManager;
+
+    @Test
+    void likedPageWithADot() throws Exception
+    {
+        DocumentReference likedPageReference = new DocumentReference("xwiki", "Space", "With.ADot");
+
+        // Create an empty page to be returned as a liked page.
+        XWikiDocument likedDocument = this.xwiki.getDocument(likedPageReference, this.context);
+        this.xwiki.saveDocument(likedDocument, this.context);
+
+        // The rating manager is mocked for now as the focus of the tests is currently not to test the likes indexing.
+        when(this.ratingsManager.getRatings(anyMap(), anyInt(), anyInt(), any(RatingsManager.RatingQueryField.class),
+            anyBoolean())).thenReturn(List.of(new DefaultRating("id1").setReference(likedPageReference)));
+
+        setOutputSyntax(Syntax.PLAIN_1_0);
+        this.context.setAction("get");
+
+        this.request.put("offset", "1");
+        this.request.put("reqNo", "1");
+        this.request.put("limit", "10");
+
+        JSONObject object = renderJSONPage(DOCUMENT_REFERENCE);
+        
+        assertEquals("xwiki:Space.With\\.ADot", object.getJSONArray("rows").getJSONObject(0).getString("doc_fullName"));
+    }
+}

Vulnerable code:   <content>{{velocity}}
Fixed code:     <!-- Test dependencies. -->
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-test-page</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-web-templates</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-like-api</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <type>test-jar</type>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-user-default</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <type>test-jar</type>
    </dependency>
  <content>{{velocity wiki="false"}}
/*
 * 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.like;

import java.util.List;

import javax.inject.Named;

import org.junit.jupiter.api.Test;
import org.xwiki.like.script.LikeScriptServiceComponentList;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.script.ModelScriptService;
import org.xwiki.ratings.RatingsManager;
import org.xwiki.ratings.internal.DefaultRating;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.template.script.TemplateScriptService;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.junit5.mockito.MockComponent;
import org.xwiki.test.page.PageTest;
import org.xwiki.test.page.XWikiSyntax21ComponentList;
import org.xwiki.user.UserReferenceComponentList;

import com.xpn.xwiki.doc.XWikiDocument;

import net.sf.json.JSONObject;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.when;

/**
 * Test of {@code XWiki.Like.Code.LiveTableResultPage}.
 *
 * @version $Id$
 * @since 15.1
 * @since 14.10.6
 */
@XWikiSyntax21ComponentList
@LikeScriptServiceComponentList
@UserReferenceComponentList
@ComponentList({
    TemplateScriptService.class,
    ModelScriptService.class
})
class LiveTableResultPagePageTest extends PageTest
{
    private static final DocumentReference DOCUMENT_REFERENCE =
        new DocumentReference("xwiki", List.of("XWiki", "Like", "Code"), "LiveTableResultPage");

    @MockComponent
    @Named("solr")
    private RatingsManager ratingsManager;

    @Test
    void likedPageWithADot() throws Exception
    {
        DocumentReference likedPageReference = new DocumentReference("xwiki", "Space", "With.ADot");

        // Create an empty page to be returned as a liked page.
        XWikiDocument likedDocument = this.xwiki.getDocument(likedPageReference, this.context);
        this.xwiki.saveDocument(likedDocument, this.context);

        // The rating manager is mocked for now as the focus of the tests is currently not to test the likes indexing.
        when(this.ratingsManager.getRatings(anyMap(), anyInt(), anyInt(), any(RatingsManager.RatingQueryField.class),
            anyBoolean())).thenReturn(List.of(new DefaultRating("id1").setReference(likedPageReference)));

        setOutputSyntax(Syntax.PLAIN_1_0);
        this.context.setAction("get");

        this.request.put("offset", "1");
        this.request.put("reqNo", "1");
        this.request.put("limit", "10");

        JSONObject object = renderJSONPage(DOCUMENT_REFERENCE);
        
        assertEquals("xwiki:Space.With\\.ADot", object.getJSONArray("rows").getJSONObject(0).getString("doc_fullName"));
    }
}