# Expression Language Injection > Attacker input is evaluated by a JVM expression engine — OGNL, SpEL, MVEL, JSP/Jakarta EL — which exposes `java.lang.Runtime` and 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.vm` Velocity template renders `$!queryString` into an OGNL context; the `SafeExpressionUtil` safety check is bypassable, so a crafted `queryString` POST to `doenterpagevariables.action` evaluates attacker OGNL. Patch replaced `value='$!queryString'` with the literal `value=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, SpEL `SimpleEvaluationContext` (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. ## Related - [[Remote Code Execution]] · [[Server-Side Template Injection]] · [[Code Injection]] · [[Log4Shell]] ## Sources - [[raw/rapid7.com/rapid7-analysis-cve-2021-26084-confluence-server-ognl-injection-9372|Rapid7 Analysis: CVE-2021-26084 Confluence Server OGNL injection]] - [[raw/securitylab.github.com/command-injection-and-rce-in-metaspore-ghsl-2025-035-to-037-3523|Command Injection and RCE in MetaSpore (SpEL via Consul)]] - [[raw/rapid7.com/rapid7-analysis-cve-2021-44228-log4shell-9374|Rapid7 Analysis: CVE-2021-44228 (Log4Shell / Struts 2)]]