Overview
Expression Language (EL) Injection occurs when an application incorporates untrusted user input into strings that are later interpreted by an Expression Language engine. ELs are often used in Java EE frameworks (like JSF, JSP), Spring Expression Language (SPeL), and some templating systems to provide dynamic functionality. If user input containing EL syntax (e.g.,${...}, #{...}, *{...}) is evaluated, attackers can execute arbitrary code, access sensitive objects, or manipulate application behavior. ⚙️💉
Business Impact
Successful EL Injection can lead to:- Remote Code Execution (RCE): Attackers can often access underlying platform objects and methods, potentially executing arbitrary commands on the server.
- Information Disclosure: Accessing sensitive application objects, configuration settings, or environment variables.
- Logic Manipulation: Altering application flow or data by triggering unexpected method calls.
- Denial of Service: Executing expressions that consume excessive resources.
Reference Details
CWE ID: CWE-917
OWASP Top 10 (2021): A03:2021 - Injection
Severity: Critical (often leads to RCE)
Framework-Specific Analysis and Remediation
This vulnerability is highly dependent on the specific framework and how it parses and evaluates expressions. Key defenses include:- Avoiding Evaluation of User Input: The safest approach is never to include untrusted data in strings that will be evaluated by an EL engine.
- Using Safe EL Subsets/Contexts: Some frameworks allow configuring restricted EL contexts that limit access to dangerous objects or methods.
- Input Sanitization/Escaping: Escaping EL control characters (
$,#,{,}) in user input before it’s processed by the EL engine. This is less reliable than avoiding evaluation. - Keeping Frameworks Updated: Patches often fix EL injection vulnerabilities discovered in framework components.
- Java
- Python
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Common in Java EE (JSF, JSP using${} or #{}) and Spring applications using Spring Expression Language (SPeL - #{}, *{}). User input might end up in dynamically generated error messages, custom components, or unsafe template processing.Vulnerable Scenario 1: JSF/JSP Error Message
An error message reflects user input without sanitization, and the page renders EL.Vulnerable Scenario 2: Spring Expression Language (SPeL) in Custom Annotation/Logic
A developer usesSpelExpressionParser to evaluate an expression partly constructed from user input.Mitigation and Best Practices
- JSF/JSP: Avoid including raw user input in messages or components rendered on pages where EL is evaluated. If necessary, sanitize the input to remove or escape
${,#{,{,}characters. Use standard JSF components which often handle escaping. - SPeL: Do not construct SPeL expressions by concatenating user input. Use safe contexts (
SimpleEvaluationContext) instead ofStandardEvaluationContextif possible, asSimpleEvaluationContextrestricts access to dangerous features likeT()operator (type references) and bean references. If you must use user input, treat it strictly as data, not part of the expression logic (e.g., pass it as a variable to the context).
Secure Code Example
Testing Strategy
Identify all points where user input might be reflected in JSF/JSP pages or used inSpelExpressionParser.parseExpression(). Submit payloads designed to trigger EL evaluation:- Simple math:
${7*7},#{7*7} - Java method calls (JSF/SPeL):
${customer.getName()},#{T(java.lang.System).getenv()} - OS commands (SPeL):
#{T(java.lang.Runtime).getRuntime().exec('id')}Check if the expressions are evaluated or if errors related to parsing/execution occur.

