Skip to content
RCE Advisory Advanced

GHSL-2020-050: Arbitrary code execution in Pebble Templates

When Spring integration is enabled, an attacker who can modify template contents can access exposed Servlet and Spring objects to bypass the Pebble sandbox and execute arbitrary Java code or system commands. This leads to remote code execution with the privileges of the Servlet container account.

Alvaro Muñoz Follow

Originally disclosed on GitHub Security Lab

When Spring integration is enabled, an attacker that is able to modify Template contents may execute arbitrary Java code or run arbitrary system commands with the same privileges as the account running the Servlet container.

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

Likely the Pebble sandbox is bypassed because Spring integration exposes Servlet context and Spring beans, which provide access to objects like InstanceManager or class loaders that can instantiate arbitrary classes and execute code.

Impact

This issue may lead to Remote Code Execution (RCE).

What the attacker needed

Spring integration enabled; attacker can modify template contents

How it was found

  1. Access the Servlet context through request.servletContext or similar.
  2. Retrieve the org.apache.tomcat.InstanceManager attribute from the Servlet context.
  3. Use the InstanceManager to instantiate a ScriptEngineManager and evaluate JavaScript to run system commands.
  4. Alternatively, access Spring beans to load arbitrary classes or disable the sandbox.

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.

Pebble is a template engine that normally prevents dangerous Java methods from being called. However, when it is integrated with Spring, it exposes internal objects like the Servlet context and Spring beans. An attacker who can edit a template can use these objects to break out of the sandbox and run any command 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.