﻿# V5909\. OWASP\. Possible XSS vulnerability\. Potentially tainted data might be used to inject a malicious script\.

The analyzer has detected that data received by the server from an external source could be used as executable code on the client side\. This could create an opportunity for an XSS attack\.

XSS vulnerabilities fall under the following category in the OWASP Top 10 Application Security Risks 2025: [A05:2025 Injection](https://top10.owasp.org/2025/A05_2025-Injection/)\.  

The example:

```cpp
func ProcessRequest(w http.ResponseWriter, r *http.Request) {
  cookie, err := r.Cookie("userName")
  ....
  w.Header().Set("Content-Type", "text/html")

  w.Write([]byte("<html><body><p>Welcome, " + 
                 cookie.Value + 
                 "</p></body></html>"))
}
```

In the code, the username is retrieved from the request and then immediately inserted into the HTML markup\. If, instead of a username, the `cookie` contains HTML markup such as `<script>alert("XSS Injection")</script>`, rendering this HTML will execute third\-party, potentially malicious code\.

To fix this potential vulnerability, escape all special HTML characters in data received from an external source before inserting it into HTML\. You can do this using the [`html.EscapeString`](https://pkg.go.dev/html#EscapeString) function:

```cpp
func ProcessRequest(w http.ResponseWriter, r *http.Request) {
  cookie, err := r.Cookie("userName")
  ....
  w.Header().Set("Content-Type", "text/html")

  userName := html.EscapeString(cookie.Value)

  w.Write([]byte("<html><body><p>Welcome, " + 
                 userName + 
                 "</p></body></html>"))
}
```

For more information about XSS attacks and how to protect against them, visit the [OWASP Cheat Sheet Series page](https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html)\.