logo

Database

Scala Eval Untrusted Input

Description

Detects dangerous usage of JavaScript eval() function in Scala.js applications where untrusted input could be executed. This can lead to arbitrary code execution vulnerabilities when user-controlled data is evaluated as code.

Weakness:

143 - Inappropriate coding practices - Eval function

Category: Functionality Abuse

Detection Strategy

    Check if the Scala.js JavaScript interop library (scala.scalajs.js) is imported in the source code

    Look for calls to the 'eval' function in the code

    Verify if the eval function receives data that originates from user input or external sources

    Report a vulnerability when eval is called with untrusted input that could lead to code injection

Vulnerable code example

package controllers

import play.api.mvc._
import scala.scalajs.js

def vulnerable: Action[AnyContent] = Action { request =>
  // VULNERABLE: Directly executing user input via js.eval
  val userCode = request.getQueryString("code").getOrElse("")...

✅ Secure code example

package controllers

import play.api.mvc._
import scala.scalajs.js

def safe: Action[AnyContent] = Action { request =>
  val userCode = request.getQueryString("code").getOrElse("")
  ...