Expression language injection happens when an application hands attacker-controlled text to an interpreter such as OGNL, SpEL, MVEL or a logging lookup engine, which then evaluates it as code with the privileges of the application and every credential it holds. It is the weakness class behind several of the most damaging Java server compromises of the last decade, including repeated Apache Struts and Atlassian Confluence remote code execution flaws, Spring Cloud vulnerabilities and Log4Shell. This guide explains how the class works, where it hides, how to detect it in code and in production, and how to remove or contain it. It deliberately contains no working payloads.
The guide covers expression languages embedded in frameworks and libraries. Template engines such as Jinja2, Freemarker and Velocity are a close relative and are covered in our Server-Side Template Injection (SSTI) Guide, which this page links to rather than repeats.
Key takeaways
- MITRE classifies this weakness as CWE-917, Improper Neutralization of Special Elements used in an Expression Language Statement, a child of command injection (CWE-77) and a peer of template injection (CWE-1336).
- The root cause is always the same: text from an untrusted source reaches an evaluator that can navigate objects, call methods or resolve remote resources.
- Expression evaluators run inside the application process, so a successful injection inherits its environment variables, mounted secrets, cloud instance credentials and service account tokens. Treat every EL injection as a non-human identity compromise, not only a code execution bug.
- Framework sandboxes (Struts exclusion lists, Spring's
SimpleEvaluationContext) reduce exposure but their own documentation describes them as best-effort. The durable fix is to stop evaluating untrusted input. - CISA lists multiple EL injection flaws in its Known Exploited Vulnerabilities catalogue, several with known ransomware use, so patch latency on Struts, Confluence, Spring and Log4j components is a measurable risk.
What expression languages are and why they are dangerous
An expression language is a small embedded language that lets a framework resolve values at runtime: read a property from an object, call a getter, compare two values, or build a string. Java frameworks use them heavily because they make configuration, view rendering and data binding concise.
- OGNL (Object-Graph Navigation Language) is the expression layer in Apache Struts and parts of Atlassian Confluence. It navigates the object graph on the value stack and, unless restricted, can reach classes, static members and constructors.
- SpEL (Spring Expression Language) powers
@Valueannotations, Spring Security access expressions, Spring Cloud routing and many integration features. - MVEL is a dynamically typed expression language embedded in rule engines and workflow products, where business users or integrations often supply rule text.
- Jakarta Expression Language (formerly JSP EL / Unified EL) resolves
${...}and#{...}constructs in JSP and Jakarta Faces pages and in Bean Validation message interpolation. - Lookup and interpolation engines, such as the Log4j 2 lookup mechanism that resolved
${...}patterns including JNDI references, are not usually called expression languages, but they share the same property: a string becomes an instruction.
The danger lies in reach. A templating engine that only substitutes variables is fairly harmless. An evaluator that can traverse from a request object to the class loader, invoke arbitrary methods, or fetch and instantiate remote objects turns any injection point into remote code execution. Once code runs, the attacker holds whatever the process holds: database connection strings, API keys loaded from environment variables, Kubernetes service account tokens, and cloud role credentials obtained from the instance metadata service.
How injection reaches the evaluator
EL injection rarely looks like a classic injection bug in code review, because the developer often never wrote an explicit "evaluate" call. The common paths are:
- Direct evaluation of user input. Code passes a request parameter, header or message field to
parseExpression,Ognl.getValueor an MVEL compile call, typically to support "flexible" filters, dynamic routing or user-defined rules. - Forced or double evaluation. A framework evaluates an expression whose result is itself treated as a new expression. Struts tag attributes that use forced evaluation syntax are the textbook case; the Apache Struts project warns never to use the value of an incoming request parameter as input for forced expression evaluation.
- Error and message interpolation. Validation messages, localisation strings and error pages that interpolate user-supplied values, then pass the result through an EL resolver. The Struts security guidance specifically warns that passing request parameters to
getText(...)can allow OGNL injection. - Header, path and routing expressions. Gateways and function routers that let a header or route definition carry an expression. Spring Cloud Function (CVE-2022-22963) and Spring Cloud Gateway (CVE-2022-22947) both appear in the CISA KEV catalogue in this family.
- Logging and lookup resolution. A logging library resolves lookup syntax inside logged data. Log4Shell (CVE-2021-44228) is the observed example CWE-917 itself cites: the library did not neutralise
${xyz}-style expressions in logged content. - Stored expressions. Rule text, workflow definitions, dashboard filters or report templates stored in a database and edited by lower-privileged users, then evaluated by a high-privilege service.
The last path matters for identity teams. When an integration or partner account can edit stored rules, the permission "edit a rule" is effectively "run code as the rules service account". Access reviews that treat rule editing as a low-risk business permission miss this.
Notable incidents and the KEV record
The following vulnerabilities in this class are listed in the CISA Known Exploited Vulnerabilities Catalog. Dates are when CISA added each entry.
| CVE | Product | Mechanism | KEV added | Known ransomware use |
|---|---|---|---|---|
| CVE-2017-5638 | Apache Struts | OGNL evaluation in request handling | 2021-11-03 | Known |
| CVE-2018-11776 | Apache Struts | OGNL evaluation via namespace handling | 2021-11-03 | Unknown |
| CVE-2021-26084 | Atlassian Confluence Server and Data Center | OGNL injection | 2021-11-03 | Known |
| CVE-2021-44228 | Apache Log4j2 | Lookup resolution with JNDI (Log4Shell) | 2021-12-10 | Known |
| CVE-2022-22947 | Spring Cloud Gateway | Code injection via SpEL in route definitions | 2022-05-16 | Unknown |
| CVE-2022-26134 | Atlassian Confluence Server and Data Center | OGNL injection, unauthenticated | 2022-06-02 | Known |
| CVE-2022-22963 | Spring Cloud Function | SpEL in routing expression | 2022-08-25 | Unknown |
| CVE-2023-22527 | Atlassian Confluence Data Center and Server | Template injection reaching OGNL | 2024-01-24 | Known |
Two patterns stand out. First, the same products recur: Struts and Confluence have each produced several OGNL flaws, because the evaluator is deeply embedded and each sandbox layer has been bypassed in turn. Second, the gap between disclosure and mass exploitation is short, typically days. Our Apache Struts Security and Confluence Data Center Hardening Guide pages cover product-specific hardening in more depth.
A note on Spring4Shell (CVE-2022-22965): it is often grouped with SpEL flaws but is a data binding issue that reached the class loader, not expression evaluation. It belongs in the same review conversation (attacker-controlled property paths) but needs different fixes.
Log4Shell and JNDI lookups
Log4Shell deserves its own section because it moved the attack surface from request handlers to anything that is logged. According to the Apache Log4j security page, JNDI features used in configurations, log messages and parameters did not protect against attacker-controlled LDAP and other JNDI endpoints, which allowed arbitrary code execution. The project lists the affected log4j-core ranges as 2.0-beta9 up to 2.3.1, 2.4 up to 2.12.2 and 2.13.0 up to 2.15.0, fixed in 2.3.1 (Java 6), 2.12.2 (Java 7) and 2.15.0 (Java 8 and later).
The first fix was incomplete. CVE-2021-45046 affected non-default configurations where a Pattern Layout used a Thread Context lookup and an attacker controlled Mapped Diagnostic Context (MDC) input; it was fixed in 2.16.0 for Java 8. CVE-2021-45105, a recursion denial of service through self-referential lookups, was fixed in 2.17.0, and CVE-2021-44832, where someone with write access to logging configuration could use a JDBC Appender with a JNDI data source, was also fixed in 2.17.0 by limiting JNDI data source names to the java protocol.
The lessons carry beyond Log4j:
- Any library that interpolates
${...}in data, not only in configuration, is a candidate evaluator. Inventory them. - Configuration-only mitigations are fragile. The Log4j project states that config-only mitigations are insufficient in releases older than 2.12.2 (Java 7) and 2.16.0 (Java 8 and later). Upgrade rather than toggle.
- Outbound network egress controls were among the most effective compensating controls, because the JNDI path needed the vulnerable host to reach an attacker server. Default-deny egress on application tiers remains one of the cheapest defences against the whole class.
- Log4j 1 is affected only when it uses JMSAppender, according to the project, but Log4j 1 is end of life and should be replaced regardless.
Prevention: remove evaluation of untrusted input
CWE-917 lists three mitigations: avoid putting user-controlled data into an expression interpreter where possible; if it must be used, validate that it will not be evaluated as an expression or encode it so that it is not; and disable EL processing where the framework allows it, for example by setting isELIgnored to true on a JSP page. In practice that becomes a short hierarchy:
- Do not evaluate. Replace user-defined expressions with a fixed set of named operations, a structured filter object (field, operator, value) validated against an allow-list, or a purpose-built query language with a parser you control. Most "we need flexible expressions" requirements are satisfied by ten or fewer operators.
- Treat expressions as code, not data. If business users must author rules, store them as versioned artefacts with change review, and restrict who can edit them in the same way you restrict who can deploy code. Authorship should be an identity-governed permission with an owner and a review cycle.
- Separate data from expressions. Pass user values into an expression as variables bound by the application, never by concatenating them into the expression string.
- Turn evaluation off where it is not needed. Disable EL in JSP pages that do not need it, remove lookup features from logging patterns, and avoid framework features that re-evaluate results.
- Restrict what the evaluator can reach. Only as a last line, use the framework's restricted context or allow-list, and design the exposed objects carefully, as the next section describes.
Hardening OGNL in Apache Struts
The Apache Struts security guide documents several settings that narrow what OGNL can reach. Apply them as a baseline on every Struts application, and keep the framework current.
| Setting | Recommended value or action | Notes from the Struts documentation |
|---|---|---|
struts.devMode | false | Always disable before production; it exposes internal details and risky parameter evaluation. |
struts.allowlist.enable | Enable | Classes used in OGNL expressions must belong to allow-listed classes and packages. Available since 6.4 and default from 7.0. |
struts.allowlist.classes and struts.allowlist.packageNames | Minimal set | Monitor logs for blocked classes and allow-list only as needed. |
struts.excludedClasses, struts.excludedPackageNames and related | Extend, never shrink | Add known dangerous classes or packages from your application to the defaults. |
struts.ognl.expressionMaxLength | As low as valid expressions allow | Defaults to 256; the project notes values above the 200 to 400 range have diminishing security value. |
struts.ognl.allowStaticFieldAccess | false | Non-primitive static fields can expose otherwise inaccessible classes. |
struts.parameters.requireAnnotations | Enable | Since 6.4, default from 7.0; limits which action properties parameters can set. |
struts.disallowProxyObjectAccess, struts.disallowDefaultPackageAccess, struts.ognl.disallowCustomOgnlMap | true | Block proxied beans, default-package classes and custom OGNL maps that bypass member access checks. |
Also audit JSPs and tag usage for forced evaluation of request values, and note the project's warning that OGNL sandboxing through a Java security manager does not work with JDK 21 and later. If you are still on Struts 2.5 or 6.x, plan the move to 7.x, where several of these protections are on by default.
Hardening SpEL in Spring applications
The Spring Framework SpEL evaluation documentation is unusually direct about the risk. It states that StandardEvaluationContext, which exposes the full language, must never be used to evaluate an expression obtained from an untrusted source, and defines a trusted source as only an application developer or an administrator responsible for configuring or operating the application. End users and external systems are untrusted.
Spring offers SimpleEvaluationContext, which excludes Java type references, constructors and bean references and requires an explicit choice of read-only data binding, read-write data binding or custom property accessors. The documentation is equally clear that this is best-effort: evaluating untrusted expressions is inherently dangerous whichever context is used, and anything reachable through the root object, accessors, method resolvers, variables or functions can be invoked.
If you cannot remove SpEL evaluation of external input, follow the documented object design rules:
- Use a dedicated root type rather than exposing entities or infrastructure types such as files or JDBC connections.
- Prefer immutable types such as Java records, while remembering that read-only binding prevents assignment but not side effects. The documentation gives
File#delete()andQueue#poll()as examples of accessor-shaped methods that SpEL invokes like getters. - Expose only the properties the expression needs, and audit accessor-shaped methods on every type reachable from the root, transitively.
- Never reuse a parsed
Expressionacross contexts with different security levels; parse a distinct instance for each, because cached state from a permissive evaluation may be reused. - Keep the parser limits low.
SpelParserConfigurationdefaults to a maximum expression length of 10,000 characters and 10,000 operations; lower them for any externally influenced path.
Search your code for annotation-driven SpEL too. @PreAuthorize, @Value and caching annotations are safe when their expressions are static strings in source, and unsafe when any part is built from request data. Our Java and Spring Security Guide covers broader Spring hardening.
MVEL, Jakarta EL and rule engines
MVEL and similar dynamic languages appear in rule engines, low-code workflow tools, data pipeline transforms and alerting products. Their typical exposure is stored expressions rather than request parameters, which makes them easy to miss in web application testing. Apply these controls:
- Inventory every product and service that accepts user-authored rules, conditions, transforms or formulas, and record which evaluator it uses and which identity it runs as.
- Check vendor documentation for a sandbox or restricted mode, and enable it. Treat any sandbox as a bonus, not a boundary.
- Run rule evaluation in a separate, low-privilege process or service with no access to production secrets and no outbound network access, so that a breakout yields little.
- For Jakarta EL, avoid building message templates from user input in Bean Validation custom constraint messages, and set
isELIgnoredon JSP pages that do not use EL.
Detection in code and in production
Detection works best in layers, because no single method covers forced evaluation, stored rules and logging lookups.
In code and the build pipeline
- Use static analysis rules for CWE-917 sinks: SpEL
parseExpressionwith aStandardEvaluationContext, OGNLgetValueandsetValue, MVEL compile and eval calls, Jakarta ELExpressionFactoryuse, and Struts forced evaluation in tag attributes. - Track taint from request, header, message queue and database fields to those sinks. Stored-rule paths need an explicit source definition, because most tools do not treat database reads as untrusted.
- Run software composition analysis to flag vulnerable Struts, Spring, Confluence plugin and Log4j versions, and include shaded or bundled copies inside fat JARs and vendor appliances.
In production
- Alert on Java application processes spawning shells or interpreters, a strong signal of post-exploitation that maps to MITRE ATT&CK T1059 Command and Scripting Interpreter.
- Alert on unexpected outbound connections from application servers, particularly LDAP, RMI and DNS lookups to unusual domains, which were the hallmark of JNDI exploitation.
- Log and review framework warnings. Struts writes a warning when an expression is blocked by exclusion or allow-list rules; a burst of these is a probing signal.
- Monitor web application firewall and reverse proxy logs for expression delimiters in parameters and headers. Use this for triage and hunting rather than as a sole control, because encodings bypass simple signatures.
- Watch for new files in web roots and for web shell behaviour, which maps to T1505.003 Web Shell.
- After any suspected exploitation, review use of the application's credentials: cloud API calls from the instance role, database logins from the service account, and token use from unfamiliar addresses.
Containing the blast radius: the identity view
The initial access technique here is T1190 Exploit Public-Facing Application, but the damage depends on what the compromised process can do. Reduce it before the next flaw lands:
- Run application servers under dedicated, least-privilege service accounts with no interactive login and no rights outside the application's own resources.
- Do not put long-lived secrets in environment variables of internet-facing services. Fetch short-lived credentials from a secrets manager or use workload identity, so stolen material expires quickly.
- Require IMDSv2 or the equivalent on cloud instances, and scope instance roles to the minimum the application needs.
- Default-deny outbound traffic from application tiers, with explicit allow-lists for the services they call.
- Prepare a rotation runbook for every credential an exposed Java service holds, so that rotation after a KEV-listed EL flaw takes hours, not weeks. Our Secrets Rotation Runbook Template is a starting point.
Common failure patterns
- Trusting the sandbox. Teams rely on exclusion lists or restricted contexts as the fix. Struts history shows exclusion lists being bypassed release after release, and Spring describes its restricted context as best-effort.
- Patching the front door only. The public Confluence or Struts instance is patched, but internal instances, vendor appliances and shaded library copies are left behind.
- Toggling instead of upgrading. Configuration switches are applied as a permanent fix for a library flaw, then silently undone by a later configuration change or found to be insufficient for the installed version.
- Ignoring stored expressions. Testing focuses on request parameters while rule and workflow editors, accessible to partners or support staff, evaluate stored text with high privilege.
- Not rotating credentials after exploitation. The vulnerability is patched and the host rebuilt, but the service account passwords, API keys and cloud credentials the process held are left in place.
- No egress control. Application servers can reach any host on the internet, which turns lookup and remote class loading flaws into immediate code execution.
Practitioner checklist
- Inventory every application and product that embeds OGNL, SpEL, MVEL, Jakarta EL or a lookup-capable logging library, including vendor appliances and bundled JARs.
- Subscribe to CISA KEV and vendor advisories for Struts, Confluence, Spring and Log4j, and set a patch target measured in days for KEV-listed EL flaws on internet-facing systems.
- Search code for expression evaluation sinks fed by request, message or database data, and replace them with structured, allow-listed operations.
- Remove
StandardEvaluationContextfrom any path that touches external input, and lower SpEL parser limits where restricted evaluation must remain. - Apply the Struts baseline: devMode off, allow-list enabled, exclusions extended, low expression length, static field access off, and no forced evaluation of request values.
- Upgrade Log4j 2 to a current release and remove context lookups that take values from external input.
- Treat rule and expression authoring as a privileged, owned, reviewed permission.
- Run evaluators with least-privilege identities, short-lived credentials and default-deny egress.
- Alert on Java processes spawning shells, unexpected LDAP or RMI egress and bursts of blocked-expression warnings.
- Keep a tested credential rotation runbook for every exposed Java service.
Standards and references
- MITRE: CWE-917 Improper Neutralization of Special Elements used in an Expression Language Statement
- Apache Struts: Security guide
- Spring Framework: SpEL Evaluation reference
- Apache Log4j: Security vulnerabilities
- CISA: Known Exploited Vulnerabilities Catalog
- MITRE ATT&CK: Exploit Public-Facing Application
- OWASP: Input Validation Cheat Sheet
- NIST: SP 800-53 Rev. 5 (SI-10 Information Input Validation, CM-7 Least Functionality)
Related NHI Mgmt Group resources: Server-Side Template Injection (SSTI) Guide · Apache Struts Security · Java and Spring Security Guide · Command Injection Guide