Skip to content

Servlet Reflected Cross Site Scripting Vulnerability

Description

The application is vulnerable to cross-site scripting (XSS) attacks because it directly writes user-controlled input from an HTTP request to the response without proper encoding. This allows an attacker to inject malicious JavaScript code into the response, potentially leading to unauthorized actions or data theft.

Examples

Insecure Code

scala
def handleRequest(req: HttpServletRequest, res: HttpServletResponse): Unit = {
  val writer = res.getWriter
  writer.write(req.getParameter("userInput"))
}

Secure Code

scala
def handleRequest(req: HttpServletRequest, res: HttpServletResponse): Unit = {
  val writer = res.getWriter
  writer.write(Encode.forHtml(req.getParameter("userInput")))
}

Remediation

Encode user-controlled input for HTML using a library like OWASP ESAPI or Java's built-in encoding functions before writing it to the response.

Rule Details

FieldValue
IDCODE-0086
CategoryWeb
SeverityMEDIUM
CWECWE-79
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsxss, servlet, injection
OWASPN/A