Expression Language Injection
Attacker input is evaluated by a JVM expression engine — OGNL, SpEL, MVEL, JSP/Jakarta EL — which exposes
java.lang.Runtimeand reflection, turning a single expression into unauthenticated RCE (CWE-917).
How it works
Expression languages were built to pull values out of an object graph in views and config (${user.name}, #{bean.prop}). They are Turing-complete and, by default, let an expression reach arbitrary Java: class references (@java.lang.Runtime@getRuntime(), T(java.lang.Runtime)), reflection, and static method calls. When user input is concatenated into an expression that the engine later evaluates — or when a framework double-evaluates a value — the attacker gets code execution in the JVM.
This is the JVM-specific, often unsandboxed cousin of Server-Side Template Injection (ssti topic): SSTI detection payloads (${7*7}, #{7*7}) also flag EL sinks. Where a template engine may sandbox, raw OGNL/SpEL evaluation usually does not.
Techniques / payloads
- OGNL (Struts, Confluence):
@java.lang.Runtime@getRuntime().exec('id') (#cmd='id').(#p=new java.lang.ProcessBuilder({'/bin/sh','-c',#cmd})).(#p.start()) - SpEL (Spring):
T(java.lang.Runtime).getRuntime().exec('id') #{T(java.lang.Runtime).getRuntime().exec('...')} - Detection: arithmetic probes
${7*7}/#{7*7}→49; escalate to class-reference payloads once reflected. - Delivery via config stores: if the app evaluates values fetched from a registry (Consul, Spring Cloud), a poisoned property becomes an EL payload that fires at startup — no direct request path needed.
Notable cases
- Confluence OGNL CVE-2021-26084 (CVSS 9.8, unauthenticated RCE, mass-exploited from Sept 2021, used for coin miners then ransomware). The
createpage-entervariables.vmVelocity template renders$!queryStringinto an OGNL context; theSafeExpressionUtilsafety check is bypassable, so a craftedqueryStringPOST todoenterpagevariables.actionevaluates attacker OGNL. Patch replacedvalue='$!queryString'with the literalvalue=queryString. - MetaSpore SpEL (GHSL-2025-037). An unauthenticated, exposed Consul (port 8500) key/value store feeds
spring.application.name. Setting it to#{T(java.lang.Runtime).getRuntime().exec('...')}means the next time the recommendation service connects to Consul it loads the property and evaluates the SpEL — RCE. Chained with an exposed Spring Boot Actuator (/actuator/heapdump) for credential leak. - Struts 2 — the long lineage of OGNL RCEs (e.g. the
%{...}evaluation bugs) is the archetype; also trivially vulnerable to Log4Shell since it logs OGNL-tainted values.
Defenses
- Never place user input inside an expression string. Pre-compile expressions with a fixed, allowlisted variable context.
- Use the engine’s restricted mode: OGNL
SecurityMemberAccess/ member-access denylist, SpELSimpleEvaluationContext(no type references / no reflection), disable EL where not needed. - Lock down config sources that feed evaluated properties (authenticate Consul/registries, don’t expose Actuator).
- Patch framework EL CVEs immediately — they are among the fastest-weaponized RCEs.