CVE-2023-29211: Improper Control of Generation of Code ('Code Injection') (CWE-94)
value: XWiki Commons are technical libraries common to several other top level XWiki projects. Any user with view rights `WikiManager.DeleteWiki` can execute arbitrary Groovy, Python or Velocity code in XWiki leading to full access to the XWiki installation. The root cause is improper escaping of the `wikiId` url parameter. The problem has been patched on XWiki  13.10.11, 14.4.7, and 14.10.
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-04-16T07:15Z
Repository: https://github.com/xwiki/xwiki-platform
Language: Java
Files changed: xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/AttachmentSelectorPageTest.java, xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/WebHomeSheetPageTest.java, xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/test/java/org/xwiki/help/XWikiSyntaxMacrosListPageTest.java, xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/LocalizationSetup.java, xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/TestNoScriptMacro.java, xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/resources/META-INF/components.txt, xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/DisplayPageTest.java, xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/pom.xml, xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/main/resources/WikiManager/DeleteWiki.xml, xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/DeleteWikiPageTest.java, xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerPageTest.java
Commit date: 2022-10-27 14:15:04 +0200
Commit message: XWIKI-20297: Improved DeleteWiki error message escaping

- Cleanup the unknown wiki error message in DeleteWiki
- Make it easier to use the TestNoScriptMacro by moving it to  xwiki-platform-test-page
- Make it easier to use the translation macro in page tests

Diff: diff --git a/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/AttachmentSelectorPageTest.java b/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/AttachmentSelectorPageTest.java
index 334a8b90c90a3..392dadb4754d5 100644
--- a/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/AttachmentSelectorPageTest.java
+++ b/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/AttachmentSelectorPageTest.java
@@ -59,10 +59,11 @@
 import org.xwiki.test.annotation.ComponentList;
 import org.xwiki.test.junit5.mockito.MockComponent;
 import org.xwiki.test.page.HTML50ComponentList;
 import org.xwiki.test.page.IconSetup;
 import org.xwiki.test.page.PageTest;
+import org.xwiki.test.page.TestNoScriptMacro;
 import org.xwiki.test.page.XWikiSyntax21ComponentList;
 import org.xwiki.xml.internal.html.filter.ControlCharactersFilter;
 
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiAttachment;
diff --git a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/TestNoScriptMacro.java b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/TestNoScriptMacro.java
deleted file mode 100644
index 13fa1bfe92b3c..0000000000000
--- a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/TestNoScriptMacro.java
+++ /dev/null
@@ -1,72 +0,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.
- */
-package org.xwiki.flamingo;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.slf4j.Logger;
-import org.xwiki.component.annotation.Component;
-import org.xwiki.rendering.block.Block;
-import org.xwiki.rendering.macro.AbstractMacro;
-import org.xwiki.rendering.transformation.MacroTransformationContext;
-
-import static java.util.Collections.emptyList;
-
-/**
- * This script prints an error log when it is interpreted, making the test fail.
- *
- * @version $Id$
- * @since 13.10.10
- * @since 14.4.6
- * @since 14.9RC1
- */
-@Component
-@Named("noscript")
-@Singleton
-public class TestNoScriptMacro extends AbstractMacro<Object>
-{
-    @Inject
-    private Logger logger;
-
-    /**
-     * Default constructor.
-     */
-    public TestNoScriptMacro()
-    {
-        super("NoScript", "No Script!");
-    }
-
-    @Override
-    public boolean supportsInlineMode()
-    {
-        return true;
-    }
-
-    @Override
-    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
-    {
-        this.logger.error("SHOULD NOT BE CALLED");
-        return emptyList();
-    }
-}
diff --git a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/WebHomeSheetPageTest.java b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/WebHomeSheetPageTest.java
index b30a8a34b8886..ddb2d12d1eb03 100644
--- a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/WebHomeSheetPageTest.java
+++ b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-theme/xwiki-platform-flamingo-theme-ui/src/test/java/org/xwiki/flamingo/WebHomeSheetPageTest.java
@@ -17,34 +17,25 @@
  * 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.flamingo;
 
-import java.util.Locale;
-
 import org.jsoup.nodes.Document;
 import org.junit.jupiter.api.Test;
-import org.xwiki.localization.Translation;
-import org.xwiki.localization.TranslationBundle;
-import org.xwiki.localization.TranslationBundleContext;
 import org.xwiki.localization.macro.internal.TranslationMacro;
 import org.xwiki.model.reference.DocumentReference;
 import org.xwiki.rendering.RenderingScriptServiceComponentList;
-import org.xwiki.rendering.block.WordBlock;
 import org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration;
 import org.xwiki.rendering.internal.configuration.RenderingConfigClassDocumentConfigurationSource;
 import org.xwiki.rendering.internal.macro.message.ErrorMessageMacro;
 import org.xwiki.test.annotation.ComponentList;
 import org.xwiki.test.page.HTML50ComponentList;
 import org.xwiki.test.page.PageTest;
+import org.xwiki.test.page.TestNoScriptMacro;
 import org.xwiki.test.page.XWikiSyntax21ComponentList;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Test of the {@code FlamingoThemesCode.WebHomeSheet} page.
  *
  * @version $Id$
@@ -69,22 +60,11 @@ void createAction() throws Exception
     {
         this.request.put("newThemeName", "some content\"/}}{{noscript/}}");
         this.request.put("form_token", "1");
         this.request.put("action", "create");
 
-        TranslationBundleContext translationBundleContext = this.componentManager
-            .getInstance(TranslationBundleContext.class);
-        TranslationBundle translationBundle = mock(TranslationBundle.class);
-        Translation translation = mock(Translation.class);
-        when(translation.getLocale()).thenReturn(Locale.ENGLISH);
-        when(translation.render(any(), any())).thenAnswer(invocationOnMock -> new WordBlock(
-            "platform.flamingo.themes.home.create.csrf " + invocationOnMock.getArgument(1)));
-        when(translationBundle.getTranslation(eq("platform.flamingo.themes.home.create.csrf"), any()))
-            .thenReturn(translation);
-        translationBundleContext.addBundle(translationBundle);
-
         Document document = this.renderHTMLPage(new DocumentReference("xwiki", "FlamingoThemesCode", "WebHomeSheet"));
 
-        assertEquals("platform.flamingo.themes.home.create.csrf some content\"/}}{{noscript/}}",
+        assertEquals("platform.flamingo.themes.home.create.csrf [some content\"/}}{{noscript/}}]",
             document.select(".box.errormessage").text());
     }
 }
diff --git a/xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/test/java/org/xwiki/help/XWikiSyntaxMacrosListPageTest.java b/xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/test/java/org/xwiki/help/XWikiSyntaxMacrosListPageTest.java
index 2336f34cc8f80..eccbbcba81b55 100644
--- a/xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/test/java/org/xwiki/help/XWikiSyntaxMacrosListPageTest.java
+++ b/xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/test/java/org/xwiki/help/XWikiSyntaxMacrosListPageTest.java
@@ -142,11 +142,11 @@ void renderTable() throws Exception
         assertEquals("help.macroList.name", includeMacroRowTds.get(1).text());
         assertEquals("help.macroList.categories", includeMacroRowTds.get(2).text());
         assertEquals("help.macroList.description", includeMacroRowTds.get(3).text());
         assertEquals("help.macroList.visibility", includeMacroRowTds.get(4).text());
         assertWikiMacro(trs.get(1), "mymacro", "/xwiki/bin/view/XWiki/MyMacro", "My Macro",
-            Set.of("Category1", "Category2"), "My Macro Description", "WIKI");
+            Set.of("Category1", "Category2"), "My Macro Description", "XWiki.WikiMacroClass_visibility_WIKI");
         assertJavaMacro(trs.get(2), "velocity", "Velocity", "Development", "Executes a Velocity script.",
             "XWiki.WikiMacroClass_visibility_Global");
         assertJavaMacro(trs.get(3), "translation", "Translation", "Content",
             "Display a translation message.", "XWiki.WikiMacroClass_visibility_Global");
         assertJavaMacro(trs.get(4), "html", "HTML", "Development", "Inserts HTML or XHTML code into the page.",
diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/LocalizationSetup.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/LocalizationSetup.java
index 83333a9e62461..d3cf1ee6929e2 100644
--- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/LocalizationSetup.java
+++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/LocalizationSetup.java
@@ -17,18 +17,25 @@
  * 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.test.page;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Locale;
 import java.util.stream.Collectors;
 
-import org.mockito.stubbing.Answer;
+import org.mockito.invocation.InvocationOnMock;
+import org.xwiki.localization.Translation;
+import org.xwiki.localization.TranslationBundle;
+import org.xwiki.localization.TranslationBundleContext;
 import org.xwiki.localization.script.LocalizationScriptService;
+import org.xwiki.rendering.block.WordBlock;
 import org.xwiki.script.service.ScriptService;
 import org.xwiki.test.TestComponentManager;
 
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyCollection;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -49,37 +56,87 @@ private LocalizationSetup()
      * Sets up localization so that all translation return their key as translation values. When the translation has
      * parameters, the parameter are appended comma separated and  between square brackets after the key.
      * <p>
      * For instance, calling {@code $services.localization.render('my.key')} returns {@code "my.key"}, and calling
      * {@code $services.localization.render('my.key2', 'a', 1)} returns {@code "my.key2 [a, 1]"}.
-     * 
      *
      * @param tcm the stubbed Component Manager for the test
      * @throws Exception when a setup error occurs
      */
     public static void setUp(TestComponentManager tcm) throws Exception
     {
         LocalizationScriptService lss = mock(LocalizationScriptService.class);
         tcm.registerComponent(ScriptService.class, "localization", lss);
-        
+
         // The translations are mocked by returning the translation, suffixed with the list of the String.valueOf
         // values of the translation parameters if they exist.
         // We mock the translations instead of using their actual values because they are subject to change from
         // Weblate, possibly making the build fail unexpectedly.
-        when(lss.render(anyString())).thenAnswer(
-            (Answer<String>) invocationOnMock -> {
+        when(lss.render(anyString())).thenAnswer(invocationOnMock -> {
                 // Return the translation key as the value
-                return invocationOnMock.getArgument(0);
+                return renderString(invocationOnMock.getArgument(0), new Object[] {});
             }
         );
-        when(lss.render(anyString(), anyCollection())).thenAnswer((Answer<String>) invocationOnMock -> {
+        when(lss.render(anyString(), anyCollection())).thenAnswer(invocationOnMock -> {
             // Displays the comma-separated list of parameters between squared brackets after the translation key as
             // the value, so that they can be verified in tests.
             // For instance: my.key [paramA, paramB]
-            Object key = invocationOnMock.getArgument(0);
             Collection<?> parameters = invocationOnMock.getArgument(1);
-            return parameters.stream()
-                .map(String::valueOf)
-                .collect(Collectors.joining(", ", key + " [", "]"));
+            return renderString(invocationOnMock.getArgument(0), parameters.toArray());
         });
+
+        TranslationBundleContext translationBundleContext = tcm.getInstance(TranslationBundleContext.class);
+        TranslationBundle translationBundle = mock(TranslationBundle.class);
+        when(translationBundle.getTranslation(any(), any()))
+            .thenAnswer(invocationOnMockTranslation -> {
+                Translation translation = mock(Translation.class);
+                when(translation.getLocale()).thenReturn(Locale.ENGLISH);
+                String translationKey = invocationOnMockTranslation.getArgument(0);
+                when(translation.getKey()).thenReturn(translationKey);
+                when(translation.render(any())).thenAnswer(invocationOnMockRender -> {
+                    Object[] parameters = getVarArgs(invocationOnMockRender, 0);
+                    return renderBlock(translationKey, parameters);
+                });
+                when(translation.render(any(), any())).thenAnswer(invocationOnMockRender -> {
+                    Object[] parameters = getVarArgs(invocationOnMockRender, 1);
+                    return renderBlock(translationKey, parameters);
+                });
+                return translation;
+            });
+        translationBundleContext.addBundle(translationBundle);
+    }
+
+    private static WordBlock renderBlock(String translationKey, Object[] parameters)
+    {
+        return new WordBlock(renderString(translationKey, parameters));
+    }
+
+    private static String renderString(String translationKey, Object[] parameters)
+    {
+        String word;
+        if (parameters.length == 0) {
+            word = translationKey;
+        } else {
+            String parametersString = Arrays.stream(parameters)
+                .map(String::valueOf)
+                .collect(Collectors.joining(", ", "[", "]"));
+            word = String.format("%s %s", translationKey, parametersString);
+        }
+        return word;
+    }
+
+    private static Object[] getVarArgs(InvocationOnMock invocationOnMockRender, int i)
+    {
+        Object[] parameters;
+        if (invocationOnMockRender.getArguments().length > i) {
+            Object argument = invocationOnMockRender.getArgument(i);
+            if (argument instanceof String) {
+                parameters = new Object[] { argument };
+            } else {
+                parameters = (Object[]) argument;
+            }
+        } else {
+            parameters = new Object[] {};
+        }
+        return parameters;
     }
 }
diff --git a/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/TestNoScriptMacro.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/TestNoScriptMacro.java
similarity index 91%
rename from xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/TestNoScriptMacro.java
rename to xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/TestNoScriptMacro.java
index 83cc5a71b463c..2efc9038da49d 100644
--- a/xwiki-platform-core/xwiki-platform-attachment/xwiki-platform-attachment-ui/src/test/java/org/xwiki/attachment/TestNoScriptMacro.java
+++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/java/org/xwiki/test/page/TestNoScriptMacro.java
@@ -15,11 +15,11 @@
  * 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.attachment;
+package org.xwiki.test.page;
 
 import java.util.List;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -32,16 +32,16 @@
 import org.xwiki.rendering.transformation.MacroTransformationContext;
 
 import static java.util.Collections.emptyList;
 
 /**
- * This script prints an error log when it is interpreted, making the test fail.
+ * This macro prints an error log when it is executed, making the page test fail.
  *
  * @version $Id$
- * @since 14.5
- * @since 14.4.2
- * @since 13.10.7
+ * @since 13.10.11
+ * @since 14.4.7
+ * @since 14.10RC1
  */
 @Component
 @Named("noscript")
 @Singleton
 public class TestNoScriptMacro extends AbstractMacro<Object>
diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/resources/META-INF/components.txt
index 06843a613dd4a..34726a5c4abef 100644
--- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/resources/META-INF/components.txt
+++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-page/src/main/resources/META-INF/components.txt
@@ -1 +1,2 @@
 org.xwiki.test.page.StubRenderingConfiguration
+org.xwiki.test.page.TestNoScriptMacro
diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/DisplayPageTest.java b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/DisplayPageTest.java
index dcad24edbe427..81e1666544996 100644
--- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/DisplayPageTest.java
+++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/DisplayPageTest.java
@@ -57,18 +57,18 @@ class DisplayPageTest extends PageTest
 
     private static final String FIELD_NAME = "testField";
 
     private static final String FIELD_PRETTY_NAME = "Test Field";
 
-    private static final String DEFAULT_LABEL = "defaultValue";
+    private static final String DEFAULT_LABEL = "space.page_testField_";
 
     private static final String VALUE_1 = "value1";
 
     private static final String DEFAULT_SELECT =
         "<select id='space.page_0_testField' name='space.page_0_testField' size='1'>"
-        + "<option selected='selected' value='' label='defaultValue'>defaultValue</option>"
-        + "<option value='value1' label='value1'>value1</option></select>"
+        + "<option selected='selected' value='' label='space.page_testField_'>space.page_testField_</option>"
+        + "<option value='value1' label='space.page_testField_value1'>space.page_testField_value1</option></select>"
         + "<input name='space.page_0_testField' type='hidden' value=''/>";
 
     private TemplateManager templateManager;
 
     private String serializedDocumentReference;
diff --git a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/pom.xml b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/pom.xml
index c4e2adc12b461..c827f9c533e55 100644
--- a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/pom.xml
+++ b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/pom.xml
@@ -127,10 +127,17 @@
       <groupId>org.xwiki.platform</groupId>
       <artifactId>xwiki-platform-wiki-ui-common</artifactId>
       <version>${project.version}</version>
       <type>xar</type>
     </dependency>
+    <!-- Runtime dependencies. -->
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-rendering-xwiki</artifactId>
+      <version>${project.version}</version>
+      <scope>runtime</scope>
+    </dependency>
     <!-- Needed to display wiki activity in the user profile "Wiki" tab -->
     <dependency>
       <groupId>org.xwiki.platform</groupId>
       <artifactId>xwiki-platform-notifications-ui</artifactId>
       <version>${project.version}</version>
@@ -162,10 +169,17 @@
       <artifactId>xwiki-platform-livedata-macro</artifactId>
       <version>${project.version}</version>
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-platform-rendering-xwiki</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
       <plugin>
         <groupId>org.xwiki.commons</groupId>
diff --git a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/main/resources/WikiManager/DeleteWiki.xml b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/main/resources/WikiManager/DeleteWiki.xml
index 7e3f52165db14..89587c2704772 100755
--- a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/main/resources/WikiManager/DeleteWiki.xml
+++ b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/main/resources/WikiManager/DeleteWiki.xml
@@ -58,11 +58,12 @@
   ##
   #set ($wiki = $services.wiki.getById($wikiId))
   ##
   #if (!$wiki)
     #if (!$services.wiki.lastError)
-      {{error}}{{translation key="platform.wiki.error.wikidoesnotexist" parameters="$wikiId"/}}{{/error}}
+      #set ($escapedWikiId = $services.rendering.escape($escapetool.java($wikiId), 'xwiki/2.1'))
+      {{error}}{{translation key="platform.wiki.error.wikidoesnotexist" parameters="~"${escapedWikiId}~""/}}{{/error}}
     #else
       #printException($services.wiki.lastError)
     #end
   #else
     #set ($currentUser = "${services.wiki.mainWikiId}:${xcontext.user}")
diff --git a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/DeleteWikiPageTest.java b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/DeleteWikiPageTest.java
new file mode 100644
index 0000000000000..df58fc0bc9881
--- /dev/null
+++ b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/DeleteWikiPageTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.wiki;
+
+import org.jsoup.nodes.Document;
+import org.junit.jupiter.api.Test;
+import org.xwiki.localization.macro.internal.TranslationMacro;
+import org.xwiki.model.reference.DocumentReference;
+import org.xwiki.rendering.RenderingScriptServiceComponentList;
+import org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration;
+import org.xwiki.rendering.internal.configuration.RenderingConfigClassDocumentConfigurationSource;
+import org.xwiki.rendering.internal.macro.message.ErrorMessageMacro;
+import org.xwiki.test.annotation.ComponentList;
+import org.xwiki.test.page.HTML50ComponentList;
+import org.xwiki.test.page.PageTest;
+import org.xwiki.test.page.TestNoScriptMacro;
+import org.xwiki.test.page.XWikiSyntax21ComponentList;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test of the {@code WikiManager.DeleteWiki} page.
+ *
+ * @version $Id$
+ * @since 13.10.11
+ * @since 14.4.7
+ * @since 14.10RC1
+ */
+@HTML50ComponentList
+@XWikiSyntax21ComponentList
+@RenderingScriptServiceComponentList
+@ComponentList({
+    ErrorMessageMacro.class,
+    TranslationMacro.class,
+    TestNoScriptMacro.class,
+    DefaultExtendedRenderingConfiguration.class,
+    RenderingConfigClassDocumentConfigurationSource.class
+})
+class DeleteWikiPageTest extends PageTest
+{
+    @Test
+    void unknownWikiId() throws Exception
+    {
+        this.request.put("wikiId", "\" /}}{{noscript/}}");
+        Document document = renderHTMLPage(new DocumentReference("xwiki", "WikiManager", "DeleteWiki"));
+        assertEquals("platform.wiki.error.wikidoesnotexist [\" /}}{{noscript/}}]",
+            document.select(".box.errormessage").text());
+    }
+}
diff --git a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerTest.java b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerPageTest.java
similarity index 99%
rename from xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerTest.java
rename to xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerPageTest.java
index b8ed585b3b566..272d9d0b3b119 100644
--- a/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerTest.java
+++ b/xwiki-platform-core/xwiki-platform-wiki/xwiki-platform-wiki-ui/xwiki-platform-wiki-ui-mainwiki/src/test/java/org/xwiki/wiki/WikiManagerPageTest.java
@@ -56,11 +56,11 @@
 @HTML50ComponentList
 @LiveDataMacroComponentList
 @ComponentList({
     ControlCharactersFilter.class,
 })
-class WikiManagerTest extends PageTest
+class WikiManagerPageTest extends PageTest
 {
     /**
      * Verify the resolved configuration of the Live Data macro (stored in the {@code data-config} attribute of the
      * {@code <div/>} produced by the macro.
      */

Vulnerable code: /*
 * 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.flamingo;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.rendering.block.Block;
import org.xwiki.rendering.macro.AbstractMacro;
import org.xwiki.rendering.transformation.MacroTransformationContext;

import static java.util.Collections.emptyList;

/**
 * This script prints an error log when it is interpreted, making the test fail.
 *
 * @version $Id$
 * @since 13.10.10
 * @since 14.4.6
 * @since 14.9RC1
 */
@Component
@Named("noscript")
@Singleton
public class TestNoScriptMacro extends AbstractMacro<Object>
{
    @Inject
    private Logger logger;

    /**
     * Default constructor.
     */
    public TestNoScriptMacro()
    {
        super("NoScript", "No Script!");
    }

    @Override
    public boolean supportsInlineMode()
    {
        return true;
    }

    @Override
    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
    {
        this.logger.error("SHOULD NOT BE CALLED");
        return emptyList();
    }
}
import java.util.Locale;

import org.xwiki.localization.Translation;
import org.xwiki.localization.TranslationBundle;
import org.xwiki.localization.TranslationBundleContext;
import org.xwiki.rendering.block.WordBlock;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
        TranslationBundleContext translationBundleContext = this.componentManager
            .getInstance(TranslationBundleContext.class);
        TranslationBundle translationBundle = mock(TranslationBundle.class);
        Translation translation = mock(Translation.class);
        when(translation.getLocale()).thenReturn(Locale.ENGLISH);
        when(translation.render(any(), any())).thenAnswer(invocationOnMock -> new WordBlock(
            "platform.flamingo.themes.home.create.csrf " + invocationOnMock.getArgument(1)));
        when(translationBundle.getTranslation(eq("platform.flamingo.themes.home.create.csrf"), any()))
            .thenReturn(translation);
        translationBundleContext.addBundle(translationBundle);

        assertEquals("platform.flamingo.themes.home.create.csrf some content\"/}}{{noscript/}}",
            Set.of("Category1", "Category2"), "My Macro Description", "WIKI");
import org.mockito.stubbing.Answer;
     * 
        
        when(lss.render(anyString())).thenAnswer(
            (Answer<String>) invocationOnMock -> {
                return invocationOnMock.getArgument(0);
        when(lss.render(anyString(), anyCollection())).thenAnswer((Answer<String>) invocationOnMock -> {
            Object key = invocationOnMock.getArgument(0);
            return parameters.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(", ", key + " [", "]"));
package org.xwiki.attachment;
 * This script prints an error log when it is interpreted, making the test fail.
 * @since 14.5
 * @since 14.4.2
 * @since 13.10.7
    private static final String DEFAULT_LABEL = "defaultValue";
        + "<option selected='selected' value='' label='defaultValue'>defaultValue</option>"
        + "<option value='value1' label='value1'>value1</option></select>"
      {{error}}{{translation key="platform.wiki.error.wikidoesnotexist" parameters="$wikiId"/}}{{/error}}
class WikiManagerTest extends PageTest
Fixed code: import org.xwiki.test.page.TestNoScriptMacro;
import org.xwiki.test.page.TestNoScriptMacro;
        assertEquals("platform.flamingo.themes.home.create.csrf [some content\"/}}{{noscript/}}]",
            Set.of("Category1", "Category2"), "My Macro Description", "XWiki.WikiMacroClass_visibility_WIKI");
import java.util.Arrays;
import java.util.Locale;
import org.mockito.invocation.InvocationOnMock;
import org.xwiki.localization.Translation;
import org.xwiki.localization.TranslationBundle;
import org.xwiki.localization.TranslationBundleContext;
import org.xwiki.rendering.block.WordBlock;
import static org.mockito.ArgumentMatchers.any;

        when(lss.render(anyString())).thenAnswer(invocationOnMock -> {
                return renderString(invocationOnMock.getArgument(0), new Object[] {});
        when(lss.render(anyString(), anyCollection())).thenAnswer(invocationOnMock -> {
            return renderString(invocationOnMock.getArgument(0), parameters.toArray());

        TranslationBundleContext translationBundleContext = tcm.getInstance(TranslationBundleContext.class);
        TranslationBundle translationBundle = mock(TranslationBundle.class);
        when(translationBundle.getTranslation(any(), any()))
            .thenAnswer(invocationOnMockTranslation -> {
                Translation translation = mock(Translation.class);
                when(translation.getLocale()).thenReturn(Locale.ENGLISH);
                String translationKey = invocationOnMockTranslation.getArgument(0);
                when(translation.getKey()).thenReturn(translationKey);
                when(translation.render(any())).thenAnswer(invocationOnMockRender -> {
                    Object[] parameters = getVarArgs(invocationOnMockRender, 0);
                    return renderBlock(translationKey, parameters);
                });
                when(translation.render(any(), any())).thenAnswer(invocationOnMockRender -> {
                    Object[] parameters = getVarArgs(invocationOnMockRender, 1);
                    return renderBlock(translationKey, parameters);
                });
                return translation;
            });
        translationBundleContext.addBundle(translationBundle);
    }

    private static WordBlock renderBlock(String translationKey, Object[] parameters)
    {
        return new WordBlock(renderString(translationKey, parameters));
    }

    private static String renderString(String translationKey, Object[] parameters)
    {
        String word;
        if (parameters.length == 0) {
            word = translationKey;
        } else {
            String parametersString = Arrays.stream(parameters)
                .map(String::valueOf)
                .collect(Collectors.joining(", ", "[", "]"));
            word = String.format("%s %s", translationKey, parametersString);
        }
        return word;
    }

    private static Object[] getVarArgs(InvocationOnMock invocationOnMockRender, int i)
    {
        Object[] parameters;
        if (invocationOnMockRender.getArguments().length > i) {
            Object argument = invocationOnMockRender.getArgument(i);
            if (argument instanceof String) {
                parameters = new Object[] { argument };
            } else {
                parameters = (Object[]) argument;
            }
        } else {
            parameters = new Object[] {};
        }
        return parameters;
package org.xwiki.test.page;
 * This macro prints an error log when it is executed, making the page test fail.
 * @since 13.10.11
 * @since 14.4.7
 * @since 14.10RC1
org.xwiki.test.page.TestNoScriptMacro
    private static final String DEFAULT_LABEL = "space.page_testField_";
        + "<option selected='selected' value='' label='space.page_testField_'>space.page_testField_</option>"
        + "<option value='value1' label='space.page_testField_value1'>space.page_testField_value1</option></select>"
    <!-- Runtime dependencies. -->
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-rendering-xwiki</artifactId>
      <version>${project.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-rendering-xwiki</artifactId>
      <version>${project.version}</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
      #set ($escapedWikiId = $services.rendering.escape($escapetool.java($wikiId), 'xwiki/2.1'))
      {{error}}{{translation key="platform.wiki.error.wikidoesnotexist" parameters="~"${escapedWikiId}~""/}}{{/error}}
/*
 * 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.wiki;

import org.jsoup.nodes.Document;
import org.junit.jupiter.api.Test;
import org.xwiki.localization.macro.internal.TranslationMacro;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.rendering.RenderingScriptServiceComponentList;
import org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration;
import org.xwiki.rendering.internal.configuration.RenderingConfigClassDocumentConfigurationSource;
import org.xwiki.rendering.internal.macro.message.ErrorMessageMacro;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.page.HTML50ComponentList;
import org.xwiki.test.page.PageTest;
import org.xwiki.test.page.TestNoScriptMacro;
import org.xwiki.test.page.XWikiSyntax21ComponentList;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Test of the {@code WikiManager.DeleteWiki} page.
 *
 * @version $Id$
 * @since 13.10.11
 * @since 14.4.7
 * @since 14.10RC1
 */
@HTML50ComponentList
@XWikiSyntax21ComponentList
@RenderingScriptServiceComponentList
@ComponentList({
    ErrorMessageMacro.class,
    TranslationMacro.class,
    TestNoScriptMacro.class,
    DefaultExtendedRenderingConfiguration.class,
    RenderingConfigClassDocumentConfigurationSource.class
})
class DeleteWikiPageTest extends PageTest
{
    @Test
    void unknownWikiId() throws Exception
    {
        this.request.put("wikiId", "\" /}}{{noscript/}}");
        Document document = renderHTMLPage(new DocumentReference("xwiki", "WikiManager", "DeleteWiki"));
        assertEquals("platform.wiki.error.wikidoesnotexist [\" /}}{{noscript/}}]",
            document.select(".box.errormessage").text());
    }
}
class WikiManagerPageTest extends PageTest