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.
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.
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
- Access the Servlet context through request.servletContext or similar.
- Retrieve the org.apache.tomcat.InstanceManager attribute from the Servlet context.
- Use the InstanceManager to instantiate a ScriptEngineManager and evaluate JavaScript to run system commands.
- 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.