Skip to content

Cross-site Scripting (XSS) Vulnerability

Description

A potential XSS was found. It could be used to execute unwanted JavaScript in a client's browser. This occurs when user input is not properly sanitized before being output to the browser, allowing an attacker to inject malicious scripts.

Examples

Insecure Code

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

Secure Code

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

Remediation

Properly encode user input using org.owasp.encoder.Encode.forHtml() before writing it to the HTTP response.

Rule Details

FieldValue
IDCODE-0087
CategoryWeb
SeverityHIGH
CWECWE-79
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
TagsXSS, Cross-site Scripting
OWASPN/A