GHSL-2020-046: Server-Side Template Injection in XWiki
XWiki's Velocity template sandbox could be bypassed by accessing exposed Servlet Context attributes, allowing an attacker with edit rights to instantiate arbitrary Java objects and execute code. This led to remote code execution with the privileges of the XWiki process.
Originally disclosed on GitHub Security Lab
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.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The Velocity sandbox exposed objects through the Templating API whose object graph reached the Servlet Context, including an InstanceManager that can instantiate arbitrary Java classes.
Impact
An attacker with edit rights could execute arbitrary Java code or system commands with the privileges of the XWiki process, leading to remote code execution.
What the attacker needed
Privileges to edit wiki content
The fix
XWiki released fixes in versions 12.2.1, 11.10.5, 12.5 and 11.10.6 after finding similar vectors.
How it was found
- Edit wiki content to include a Velocity template.
- Use the template to access the Servlet Context through the request object.
- List the Servlet Context attributes to find the Tomcat InstanceManager.
- Use the InstanceManager to instantiate a ScriptEngineManager and evaluate JavaScript that runs a system command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
XWiki lets users write templates in a language called Velocity. A security feature called a sandbox tries to stop those templates from doing dangerous things. The report shows that the sandbox could be tricked into giving access to Java objects that let an attacker run their own commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.