skip to content
Back to
Home Bounties Research Advisories CodeQL Wall of Fame Get Involved Events
August 19, 2020

GHSL-2020-046: Server-Side Template Injection in XWiki

Alvaro Munoz


A user with privileges to edit wiki content may execute arbitrary Java code or run arbitrary system commands with the same privileges as the account running XWiki.



Tested Version

XWiki 12.1


Server-Side Template Injection (Velocity)

Even though XWiki does a good job installing the Velocity SecureUberspector to sandbox the User macro templates, it stills exposes a number of objects through the Templating API that can be used to circumvent the sandbox and achieve remote code execution.

Deep inspection of the exposed objects’ object graph allows an attacker to get access to objects that allow them to instantiate arbitrary Java objects. In particular, it exposes the Servlet Context through $request.getServletContext()

We can then list all Servlet Context attributes with:

  #foreach( $attr in $request.getServletContext().getAttributeNames() )

On a Tomcat server (used in official XWiki Docker image), we get:

The most interesting one is org.apache.tomcat.InstanceManager which enables us to instantiate arbitrary objects. Note that this class is available on e.g. Jetty as well and similar classes are available on other servers. For example JBoss/WildFly exposes org.wildfly.extension.undertow.deployment.UndertowJSPInstanceManage.

An attacker can access an Instance manager with any of the options below (probably more):

Once an attacker gets access to an Instance Manager, they can use it to instantiate arbitrary Java objects and invoke methods that may lead to arbitrary code execution, effectively bypassing the sandbox. Probably the most common one is to instantiate a ScriptEngineManager:



This issue may lead to Remote Code Execution.

Coordinated Disclosure Timeline

Vendor Advisories:



This issue was discovered and reported by GHSL team member @pwntester (Alvaro Munoz).


You can contact the GHSL team at, please include the GHSL-2020-046 in any communication regarding this issue.