Files or directories become accessible to unauthorized actors due to the product's operation, violating security protocols.
1@throws[IOException]
2def nonComplaint(request: HttpServletRequest, response: HttpServletResponse): Unit = {
3 try {
4 val jspFile = request.getParameter("jspFile")
5 var requestDispatcher = request.getRequestDispatcher(jspFile)
6 // Noncompliant: Granting access to file to unauthorized users.
7 requestDispatcher.include(request, response)
8 requestDispatcher = request.getSession.getServletContext.getRequestDispatcher(jspFile)
9
10 } catch {
11 case e: Exception =>
12 System.out.println(e)
13 }
14}
1@throws[IOException]
2def complaint(request: HttpServletRequest, response: HttpServletResponse): Unit = {
3 try {
4 val jspFile = request.getParameter("jspFile")
5 val sanitizedPath = sanitizePath(jspFile)
6 var requestDispatcher = request.getRequestDispatcher(sanitizedPath)
7 // Compliant: Sanitizing the file path before using it with the RequestDispatcher.
8 requestDispatcher.include(request, response)
9 requestDispatcher = request.getSession.getServletContext.getRequestDispatcher(sanitizedPath)
10
11 } catch {
12 case e: Exception =>
13 System.out.println(e)
14 }
15}