The analyzer has detected an unverified data from an external source to generate a redirect URL. This can lead to an Open Redirect vulnerability if the data is compromised.
This vulnerability falls under the following category of the OWASP Top 10 Application Security Risks 2025: A01:2025 Broken Access Control.
The example:
func Login(w http.ResponseWriter, r *http.Request) {
next := r.URL.Query().Get("next")
http.Redirect(w, r, next, http.StatusFound)
....
}
The redirect URL is taken from the next parameter of the HTTP request and passed to the http.Redirect function without any validation. Using external data in this way is dangerous: an attacker can send a user a link to a trusted website that redirects the user to a third-party site once clicked. Such links are often used for phishing, since the URL starts with the domain of the legitimate website.
Instead of the expected relative path, an attacker could pass the address of a third-party website. Here are examples of malicious next values for the code above:
https://attacker.example/login
//attacker.example/login
/\attacker.example/login
The last two values do not contain a scheme, but the browser still treats them as redirects to another domain, so a check such as "the address begins with /" is not sufficient.
To protect against such attacks, compare the address against a predefined list of allowed values:
var allowed = []string{"/home", "/profile"}
func Login(w http.ResponseWriter, r *http.Request) {
next := r.URL.Query().Get("next")
if !slices.Contains(allowed, next) {
next = "/home"
}
http.Redirect(w, r, next, http.StatusFound)
}
In this case, http.Redirect can only accept one of the values from the allowed list.
This diagnostic rule is classified as:
|
Was this page helpful?