Skip to content
RCE Advisory Advanced

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.

Alvaro Muñoz Follow

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.

pwntester, on GitHub Security Lab

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

  1. Edit wiki content to include a Velocity template.
  2. Use the template to access the Servlet Context through the request object.
  3. List the Servlet Context attributes to find the Tomcat InstanceManager.
  4. 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.

More by Alvaro Muñoz

View all

132 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.