CVE-2022-41934 (XML, published 2022-11-23T20:15Z)
Description: value: XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. Any user with view rights on commonly accessible documents including the menu macro can execute arbitrary Groovy, Python or Velocity code in XWiki leading to full access to the XWiki installation due to improper escaping of the macro content and parameters of the menu macro. The problem has been patched in XWiki 14.6RC1, 13.10.8 and 14.4.3. The patch (commit `2fc20891`) for the document `Menu.MenuMacro` can be manually applied or a XAR archive of a patched version can be imported. The menu macro was basically unchanged since XWiki 11.6 so on XWiki 11.6 or later the patch for version of 13.10.8 (commit `59ccca24a`) can most likely be applied, on XWiki version 14.0 and later the versions in XWiki 14.6 and 14.4.3 should be appropriate.
Severity: nan (CVSS v3 base score: 8.8)
Weakness: CWE-116 \u2014 Improper Encoding or Escaping of Output
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.
Repository: https://github.com/xwiki/xwiki-platform
Files changed:
xwiki-platform-core/xwiki-platform-menu/xwiki-platform-menu-ui/src/main/resources/Menu/MenuMacro.xml
Commit message: XWIKI-19857: Modernize the menu macro and add escaping


Vulnerable code:
<xwikidoc version="1.3" reference="Menu.MenuMacro" locale="">
$xwiki.getDocument('MenuTemplate').content
{{include reference="MenuTemplate" /}}
{{include reference="MenuTemplate" /}}
        <number>12</number>
        <number>13</number>
        <separator> </separator>
        <values>doc.reference=Document|icon.theme=Icon theme|locale=Language|request.base=Request base URL|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki</values>
        <number>11</number>
        &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#$!{id}" aria-expanded="false"&gt;
    (% id="${id}" class="menu menu-$!type collapse navbar-collapse" %)(((
      $xcontext.macro.content
  (% #if ("$!id" != '') id="$id"#end class="menu menu-$!type" %)(((
    $xcontext.macro.content
      <contentJavaType/>

Fixed code:
<xwikidoc version="1.5" reference="Menu.MenuMacro" locale="">
#set ($menuTemplateDoc = $xwiki.getDocument('MenuTemplate'))
## No way to escape content in the code macro, so just remove {, see https://jira.xwiki.org/browse/XRENDERING-13.
$menuTemplateDoc.content.replace('{', '')
{{velocity}}
## Include the content of the menu template.
## Escape {{ in the rendered content to be sure that the HTML macro is not closed unintentionally.
{{html}}$menuTemplateDoc.displayDocument().replace('{{', '&amp;amp;#123;&amp;amp;#123;'){{/html}}
{{/velocity}}
{{velocity}}
## Include the content of the menu template.
## Escape {{ in the rendered content to be sure that the HTML macro is not closed unintentionally.
{{html}}$menuTemplateDoc.displayDocument().replace('{{', '&amp;amp;#123;&amp;amp;#123;'){{/html}}
{{/velocity}}
        <number>13</number>
        <number>14</number>
        <separator>, </separator>
        <values>action=Action|doc.reference=Document|icon.theme=Icon theme|locale=Language|rendering.defaultsyntax=Default syntax|rendering.restricted=Restricted|rendering.targetsyntax=Target syntax|request.base=Request base URL|request.cookies|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki</values>
        <number>12</number>
      <priority>
        <disabled>0</disabled>
        <name>priority</name>
        <number>11</number>
        <numberType>integer</numberType>
        <prettyName>Priority</prettyName>
        <size>10</size>
        <unmodifiable>0</unmodifiable>
        <classType>com.xpn.xwiki.objects.classes.NumberClass</classType>
      </priority>
        &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#$!{escapetool.xml($id)}" aria-expanded="false"&gt;
    (% id="$!{services.rendering.escape($id, 'xwiki/2.1')}" class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')} collapse navbar-collapse" %)(((
      {{wikimacrocontent/}}
  (% #if ("$!id" != '') id="${services.rendering.escape($id, 'xwiki/2.1')}"#end class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')}" %)(((
    {{wikimacrocontent/}}
      <contentJavaType>Wiki</contentJavaType>
    <property>
      <priority/>
    </property>