Improper Control of Generation of Code ('Code Injection')

ID

scala.inject.scala_inject_rule_elinjection

Severity

low

Resource

Inject

Language

Scala

Description

An expression is built with a dynamic value. The source of the value(s) should be verified to avoid that unfiltered values fall into this risky code evaluation.

Rationale

An expression is built with a dynamic value. The source of the value(s) should be verified to avoid that unfiltered values fall into this risky code evaluation.

The following code illustrates a vulnerable pattern detected by this rule:

def valueExpr(expression: String) = {
  val context = FacesContext.getCurrentInstance
  val expressionFactory = context.getApplication.getExpressionFactory
  val elContext = context.getELContext
  // VULNERABLE: Improper Control of Generation of Code ('Code Injection')
  val vex = expressionFactory.createValueExpression(elContext, expression, classOf[Nothing])
  vex.getValue(elContext).asInstanceOf[Nothing]
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

References