CVE-2023-36470 (XML, published 2023-06-29T21:15Z)
Description: value: XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. By either creating a new or editing an existing document with an icon set, an attacker can inject XWiki syntax and Velocity code that is executed with programming rights and thus allows remote code execution. There are different attack vectors, the simplest is the Velocity code in the icon set's HTML or XWiki syntax definition. The [icon picker](https://extensions.xwiki.org/xwiki/bin/view/Extension/Icon%20Theme%20Application#HIconPicker) can be used to trigger the rendering of any icon set. The XWiki syntax variant of the icon set is also used without any escaping in some documents, allowing to inject XWiki syntax including script macros into a document that might have programming right, for this the currently used icon theme needs to be edited. Further, the HTML output of the icon set is output as JSON in the icon picker and this JSON is interpreted as XWiki syntax, allowing again the injection of script macros into a document with programming right and thus allowing remote code execution. This impacts the confidentiality, integrity and availability of the whole XWiki instance. This issue has been patched in XWiki 14.10.6 and 15.1. Icon themes now require script right and the code in the icon theme is executed within the context of the icon theme, preventing any rights escalation. A macro for displaying icons has been introduced to avoid injecting the raw wiki syntax of an icon set into another document. Users are advised to upgrade. There are no known workarounds for this vulnerability.

Severity: nan (CVSS v3 base score: 8.8)
Weakness: CWE-74 \u2014 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
Repository: https://github.com/xwiki/xwiki-platform
Files changed:
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-script/pom.xml
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-script/src/main/java/org/xwiki/icon/IconManagerScriptService.java
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-ui/src/main/resources/IconThemesCode/IconPicker.xml
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-ui/src/main/resources/IconThemesCode/IconPickerMacro.xml
Commit message: XWIKI-20524: Improve icon rendering

* Use the icon macro for rendering icons in the icon script service.
* Properly send the JSON response in the icon picker.
* Adapt the IconPickerMacro to not use the icon service rendering for
  resource loading but to use the dedicated method for that as the old
  way no longer works.


Vulnerable code:
        try {
            return iconManager.render(iconName);
        } catch (IconException e) {
            setLastError(e);
            return null;
        }
        try {
            return iconManager.render(iconName, iconSetName);
        } catch (IconException e) {
            setLastError(e);
            return null;
        }
        try {
            return iconManager.render(iconName, iconSetName, fallback);
        } catch (IconException e) {
            setLastError(e);
            return null;
        }
  $jsontool.serialize($map)
  $jsontool.serialize($icons)
  ## The icons themes may need some SSX, so we ask for a rendering of an icon of each icon theme, to be able to display
  ## all icon themes in the picker
    $services.icon.render('wiki', $iconSetName)

Fixed code:
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-rendering-xwiki</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-icon-macro</artifactId>
      <version>${project.version}</version>
      <scope>runtime</scope>
    </dependency>
import org.xwiki.rendering.internal.util.XWikiSyntaxEscaper;
import org.xwiki.rendering.syntax.Syntax;
    @Inject
    private XWikiSyntaxEscaper escaper;

        return String.format("{{displayIcon name=\"%s\"/}}", escapeXWiki21(iconName));
        return String.format("{{displayIcon name=\"%s\" iconSet=\"%s\"/}}", escapeXWiki21(iconName),
            escapeXWiki21(iconSetName));
        return String.format("{{displayIcon name=\"%s\" iconSet=\"%s\" fallback=\"%b\"/}}", escapeXWiki21(iconName),
            escapeXWiki21(iconSetName), fallback);
    }

    private String escapeXWiki21(String value)
    {
        return this.escaper.escape(value, Syntax.XWIKI_2_1);
  #jsonResponse($map)
  #jsonResponse($icons)
  ## The icons themes may need some SSX, so we ask to load the resources of all icon sets to be able to display them
  ## in the picker.
    $services.icon.use($iconSetName)