Files or Directories Accessible to External Parties

ID

scala.inject.scala_inject_rule_filedisclosure

Severity

high

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Inject

Language

Scala

Description

Constructing a server-side redirect path with user input could allow an attacker to download application binaries (including application classes or jar files) or view arbitrary files within protected directories.

Rationale

Constructing a server-side redirect path with user input could allow an attacker to download application binaries (including application classes or jar files) or view arbitrary files within protected directories.

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

// A forward target chosen by the caller names a file on the server, so the response can be
// made to contain a page that was never meant to be served directly.
class NavigationServlet extends HttpServlet {
  @throws[IOException]
  override def doGet(request: HttpServletRequest, response: HttpServletResponse): Unit = {
    try {
      val target = request.getParameter("target")

      // VULNERABLE: Files or Directories Accessible to External Parties
      val byPath = new ActionForward(target)
      // VULNERABLE: Files or Directories Accessible to External Parties
      val byPathRedirecting = new ActionForward(target, true)
      // VULNERABLE: Files or Directories Accessible to External Parties
      val namedByPath = new ActionForward("next", target, true)
      // VULNERABLE: Files or Directories Accessible to External Parties
      val namedByPathAgain = new ActionForward("next", target, true)
      val assignedLater = new ActionForward
      // VULNERABLE: Files or Directories Accessible to External Parties
      assignedLater.setPath(target)

      // In this overload the value lands in the NAME, not the path, so it is not reported.
      val byName = new ActionForward(target, "/next.jsp", true)

      // VULNERABLE: Files or Directories Accessible to External Parties
      val view = new ModelAndView(target)
      val emptyView = new ModelAndView
      // VULNERABLE: Files or Directories Accessible to External Parties
      emptyView.setViewName(target)
    } catch {
      case e: Exception =>
        System.out.println(e)
    }
  }

  @throws[IOException]
}

Remediation

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

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved