# Cwe 917 Expression Language Injection

> Use this skill when you need to remediate CWE-917 (Expression Language Injection) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing expression language injection issues.

- Skill: `developerscoffee/cwe-917-expression-language-injection` (Agent Skill)
- Install (CLI): `npx skillmds@latest add developerscoffee/cwe-917-expression-language-injection`
- Raw SKILL.md: https://api.skillmd.com/api/skills/developerscoffee/cwe-917-expression-language-injection/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- License: MIT
- Author: DevelopersCoffee (https://skillmd.com/u/developerscoffee)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/developerscoffee/cwe-917-expression-language-injection

---


# CWE-917 Expression Language Injection

## Description

Expression Language Injection

Reference:
https://cwe.mitre.org/data/definitions/917.html


**OWASP Category**: A03:2021 – Injection


---

## Vulnerable Pattern


### ❌ Example 1: Vulnerable Pattern

```java
// VULNERABLE: Using StandardEvaluationContext allows access to dangerous types
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("input", userInput);
Expression expression = parser.parseExpression(userExpression);
Object result = expression.getValue(context);
```


**Why it's vulnerable:** This pattern is vulnerable to Expression Language Injection




---

## Deterministic Fix


### ✅ Secure Implementation: Secure Implementation

```java
// SECURE: SimpleEvaluationContext restricts type access
SimpleEvaluationContext context = SimpleEvaluationContext
    .forReadOnlyDataBinding()
    .withInstanceMethods()
    .build();
// Only allow safe expressions, reject user-controlled expression strings
Expression expression = parser.parseExpression(PREDEFINED_EXPRESSION);
Object result = expression.getValue(context, targetObject);
```


**Why it's secure:** Implements proper protection against Expression Language Injection




---

## Detection Pattern

Look for these patterns in your codebase:


```bash
# Find StandardEvaluationContext usage
grep -rn "StandardEvaluationContext" --include="*.java"
```


```bash
# Find SpEL parsing with user input
grep -rn "parseExpression" --include="*.java" | grep -E "getParameter|request"
```



---

## Remediation Steps


1. Replace StandardEvaluationContext with SimpleEvaluationContext

2. Use forReadOnlyDataBinding() to restrict property access

3. Never parse user-controlled expression strings

4. Whitelist allowed expression patterns if dynamic expressions are required


---

## Key Imports

```java

import org.springframework.expression.spel.support.SimpleEvaluationContext;

import org.springframework.expression.spel.standard.SpelExpressionParser;

```

---

## Verification

After remediation:


- Run SAST scanner to confirm vulnerability is resolved

- Review all instances of the vulnerable pattern

- Add unit tests that verify the secure implementation

- Check for similar patterns in related code


---

## Trigger Examples

```
Fix CWE-917 vulnerability
Resolve Expression Language Injection issue
Secure this Java code against expression language injection
SAST reports CWE-917
```

---

## Common Vulnerable Locations

| Layer | Files | Patterns |
|-------|-------|----------|

| Controller | `*Controller.java` | User input handling |

| Service | `*Service.java` | Business logic |

| Repository | `*Repository.java` | Data access |


---

## References


- [CWE-917: Expression Language Injection](https://cwe.mitre.org/data/definitions/917.html)

- [Spring SpEL Documentation](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions)


---

**Source**: Generated by [Java CWE Security Skills Generator](https://github.com/DevelopersCoffee/java-cwe-security-skills)
**Last Updated**: 2026-03-07

