CVE-2023-29209: 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 on commonly accessible documents including the legacy notification activity macro 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 macro parameters of the legacy notification activity macro. This macro is installed by default in XWiki. The vulnerability can be exploited via every wiki page that is editable including the user's profile, but also with just view rights using the HTMLConverter that is part of the CKEditor integration which is bundled with XWiki. The vulnerability has been patched in 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-15T17:15Z
Repository: https://github.com/xwiki/xwiki-platform
Language: XML
Files changed: xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notification-activitymacro/src/main/resources/XWiki/Notifications/Code/Legacy/ActivityMacro.xml
Commit date: 2022-10-26 12:06:13 +0200
Commit message: XWIKI-20258: Improve escaping in the Legacy ActivityMacro

Diff: diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notification-activitymacro/src/main/resources/XWiki/Notifications/Code/Legacy/ActivityMacro.xml b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notification-activitymacro/src/main/resources/XWiki/Notifications/Code/Legacy/ActivityMacro.xml
index b5f00099b78e4..1a201149d0a1d 100644
--- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notification-activitymacro/src/main/resources/XWiki/Notifications/Code/Legacy/ActivityMacro.xml
+++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notification-activitymacro/src/main/resources/XWiki/Notifications/Code/Legacy/ActivityMacro.xml
@@ -249,14 +249,23 @@
       <async_enabled>0</async_enabled>
     </property>
     <property>
       <code>{{velocity}}
 #set ($wikis = '')
-#if ($services.wiki.currentWikiId != $services.wiki.mainWikiId)
+#if ("$!xcontext.macro.params.wikis" != '')
+  #set ($wikis = $xcontext.macro.params.wikis)
+#elseif ($services.wiki.currentWikiId != $services.wiki.mainWikiId)
   #set ($wikis = $services.wiki.currentWikiId)
 #end
-{{notifications useUserPreferences="false" displayOwnEvents="true" count="$xcontext.macro.params.entries" #if("$!xcontext.macro.params.wikis" != '')wikis="$xcontext.macro.params.wikis"#{else}wikis="$wikis"#end #if("$!xcontext.macro.params.spaces" != '')spaces="$xcontext.macro.params.spaces"#end #if("$!xcontext.macro.params.authors" != '')users="$xcontext.macro.params.authors"#end #if("$!xcontext.macro.params.tags" != '')tags="$xcontext.macro.params.tags"#end #if("$!xcontext.macro.params.minor" != '')displayMinorEvents="$xcontext.macro.params.minor"#end #if("$!xcontext.macro.params.rss" != '')displayRSSLink="$xcontext.macro.params.rss"#end /}}
+{{notifications useUserPreferences="false" displayOwnEvents="true"
+        count="$services.rendering.escape($xcontext.macro.params.entries, 'xwiki/2.1')"
+        wikis="$services.rendering.escape($wikis, 'xwiki/2.1')"
+        #if("$!xcontext.macro.params.spaces" != '')spaces="$services.rendering.escape($xcontext.macro.params.spaces, 'xwiki/2.1')"#end
+        #if("$!xcontext.macro.params.authors" != '')users="$services.rendering.escape($xcontext.macro.params.authors, 'xwiki/2.1')"#end
+        #if("$!xcontext.macro.params.tags" != '')tags="$services.rendering.escape($xcontext.macro.params.tags, 'xwiki/2.1')"#end
+        #if("$!xcontext.macro.params.minor" != '')displayMinorEvents="$services.rendering.escape($xcontext.macro.params.minor, 'xwiki/2.1')"#end
+        #if("$!xcontext.macro.params.rss" != '')displayRSSLink="$services.rendering.escape($xcontext.macro.params.rss, 'xwiki/2.1')"#end /}}
 {{/velocity}}</code>
     </property>
     <property>
       <contentDescription/>
     </property>

Vulnerable code: #if ($services.wiki.currentWikiId != $services.wiki.mainWikiId)
{{notifications useUserPreferences="false" displayOwnEvents="true" count="$xcontext.macro.params.entries" #if("$!xcontext.macro.params.wikis" != '')wikis="$xcontext.macro.params.wikis"#{else}wikis="$wikis"#end #if("$!xcontext.macro.params.spaces" != '')spaces="$xcontext.macro.params.spaces"#end #if("$!xcontext.macro.params.authors" != '')users="$xcontext.macro.params.authors"#end #if("$!xcontext.macro.params.tags" != '')tags="$xcontext.macro.params.tags"#end #if("$!xcontext.macro.params.minor" != '')displayMinorEvents="$xcontext.macro.params.minor"#end #if("$!xcontext.macro.params.rss" != '')displayRSSLink="$xcontext.macro.params.rss"#end /}}
Fixed code: #if ("$!xcontext.macro.params.wikis" != '')
  #set ($wikis = $xcontext.macro.params.wikis)
#elseif ($services.wiki.currentWikiId != $services.wiki.mainWikiId)
{{notifications useUserPreferences="false" displayOwnEvents="true"
        count="$services.rendering.escape($xcontext.macro.params.entries, 'xwiki/2.1')"
        wikis="$services.rendering.escape($wikis, 'xwiki/2.1')"
        #if("$!xcontext.macro.params.spaces" != '')spaces="$services.rendering.escape($xcontext.macro.params.spaces, 'xwiki/2.1')"#end
        #if("$!xcontext.macro.params.authors" != '')users="$services.rendering.escape($xcontext.macro.params.authors, 'xwiki/2.1')"#end
        #if("$!xcontext.macro.params.tags" != '')tags="$services.rendering.escape($xcontext.macro.params.tags, 'xwiki/2.1')"#end
        #if("$!xcontext.macro.params.minor" != '')displayMinorEvents="$services.rendering.escape($xcontext.macro.params.minor, 'xwiki/2.1')"#end
        #if("$!xcontext.macro.params.rss" != '')displayRSSLink="$services.rendering.escape($xcontext.macro.params.rss, 'xwiki/2.1')"#end /}}