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.
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("")
...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.