CVE-2022-23620 (published 2022-02-09T22:15Z)

XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. In affected versions AbstractSxExportURLFactoryActionHandler#processSx does not escape anything from SSX document references when serializing it on filesystem, it is possible to for the HTML export process to contain reference elements containing filesystem syntax like "../", "./". or "/" in general. The referenced elements are not properly escaped. This issue has been resolved in version 13.6-rc-1. This issue can be worked around by limiting or disabling document export.

Severity: MEDIUM
CVSS v2 base score: 5.8 (AV:N/AC:M/Au:N/C:P/I:P/A:N)
CVSS v3 base score: 5.4, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-116
cwe_name: Improper Encoding or Escaping of Output
description: The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.
extended_description: 
            Improper encoding or escaping can allow attackers to change the commands that are sent to another component, inserting malicious commands instead.
            Most products follow a certain protocol that uses structured messages for communication between components, such as queries or commands. These structured messages can contain raw data interspersed with metadata or control information. For example, "GET /index.html HTTP/1.1" is a structured message containing a command ("GET") with a single argument ("/index.html") and metadata about which protocol version is being used ("HTTP/1.1").
            If an application uses attacker-supplied inputs to construct a structured message without properly encoding or escaping, then the attacker could insert special characters that will cause the data to be interpreted as control information or metadata. Consequently, the component that receives the output will perform the wrong operations, or otherwise interpret the data incorrectly.
         
         

Fix information:
repo_url: https://github.com/xwiki/xwiki-platform
commit_details: repo_url: https://github.com/xwiki/xwiki-platform
author: Thomas Mortagne
author_date: 2021-07-07 16:02:50+02:00
msg: XWIKI-18819: It's possible to save pretty much anything anywhere by creating and using an SSX/JSX containing "../" in its reference
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: AbstractSxExportURLFactoryActionHandler.java
change_type: ModificationType.MODIFY
diff: @@ -100,13 +100,13 @@ public URL createURL(String spaces, String name, String queryString, String anch
         XWikiDocument.backupContext(backup, context);
         try {
             sxDocument.setAsContextDoc(context);
-            return processSx(spaceNames, name, queryString, context, exportContext);
+            return processSx(sxDocument.getId(), queryString, context, exportContext);
         } finally {
             XWikiDocument.restoreContext(backup, context);
         }
     }
 
-    private URL processSx(List<String> spaceNames, String name, String queryString, XWikiContext context,
+    private URL processSx(long id, String queryString, XWikiContext context,
         FilesystemExportContext exportContext) throws Exception
     {
         SxSource sxSource = null;
@@ -128,7 +128,7 @@ private URL processSx(List<String> spaceNames, String name, String queryString,
 
         // Write the content to file
         // We need a unique name for that SSX content
-        String targetPath = String.format("%s/%s/%s", getSxPrefix(), StringUtils.join(spaceNames, '/'), name);
+        String targetPath = String.format("%s/%s", getSxPrefix(), id);
         File targetDirectory = new File(exportContext.getExportDir(), targetPath);
         if (!targetDirectory.exists()) {
             targetDirectory.mkdirs();
@@ -146,11 +146,7 @@ private URL processSx(List<String> spaceNames, String name, String queryString,
 
         path.append(getSxPrefix());
         path.append(URL_PATH_SEPARATOR);
-        for (String spaceName : spaceNames) {
-            path.append(encodeURLPart(spaceName));
-            path.append(URL_PATH_SEPARATOR);
-        }
-        path.append(encodeURLPart(name));
+        path.append(id);
         path.append(URL_PATH_SEPARATOR);
         path.append(encodeURLPart(targetLocation.getName()));
 
@@ -161,14 +157,14 @@ protected String getContent(SxSource sxSource, FilesystemExportContext exportCon
     {
         String content;
 
-        // We know we're inside a SX file located at "<S|J>sx/<Space>/<Page>/<s|j>sx<NNN>.<css|js>". Inside this CSS
+        // We know we're inside a SX file located at "<S|J>sx/<id>/<s|j>sx<NNN>.<css|js>". Inside this CSS
         // there can be URLs and we need to ensure that the prefix for these URLs lead to the root of the path, i.e.
-        // 3 levels up ("../../../").
+        // 3 levels up ("../../").
         // To make this happen we reuse the Doc Parent Level from FileSystemExportContext to a fixed value of 3.
         // We also make sure to put back the original value
         int originalDocParentLevel = exportContext.getDocParentLevel();
         try {
-            exportContext.setDocParentLevels(3);
+            exportContext.setDocParentLevels(2);
             content = sxSource.getContent();
         } finally {
             exportContext.setDocParentLevels(originalDocParentLevel);

programming_language: Java