GHSL-2020-048: Remote Code Execution in Apache Velocity - CVE-2020-13936
Apache Velocity's SecureUberspector blocklist failed to inspect the full class hierarchy, so methods on subclasses of blocked classes like ClassLoader were allowed. When templates are used with VelocityView, an attacker who can modify template contents could execute arbitrary Java code or system commands with the servlet container's privileges.
Originally disclosed on GitHub Security Lab
Velocity SecureUberspector prevents access to dangerous classes and packages by checking if any methods are invoked on the blocked classes. However Velocity fails to inspect the complete class hierarchy of the object where the method is invoked.
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 blocklist check only compared the invoked object's own class against the list, not its superclasses or interfaces, so subclasses of blocked classes such as ClassLoader were not blocked.
Impact
This issue may lead to Remote Code Execution with the same privileges as the account running the Servlet container.
What the attacker needed
Ability to modify template contents; Velocity templates used with VelocityView; servlet container exposes InstanceManager
How it was found
- Access the servlet context through a template variable such as $request.servletContext.
- Use the servlet context to reach the container's InstanceManager attribute.
- Call newInstance on the InstanceManager to create a ScriptEngineManager.
- Obtain a JavaScript engine and evaluate code 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.
Velocity is a template engine that lets web pages include simple code. A security feature called SecureUberspector tries to block dangerous Java classes, but it only checks the exact class name and not its parent classes. Because of this gap, someone who can edit a template could run their own Java code 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.