The analyzer has detected that decisions regarding user permissions are based on data sent by the client. This could result in an authorization bypass (Missing authorization).
This vulnerability falls under the OWASP Top 10 Application Security Risks 2025: A01:2025 Broken Access Control.
The example:
func DeleteAllUsers(w http.ResponseWriter, r *http.Request) {
role := r.Header.Get("X-User-Role")
if role != "admin" {
http.Error(w, "forbidden", http.StatusForbidden)
return
}
DB.Exec("DELETE FROM users")
....
}
The user's role comes from an HTTP request header, and the code uses it to determine whether to perform the deletion. However, since the client controls the header's value, this check provides no real protection.
For example, an attacker can add a header containing the required role and perform an action usually accessible only to administrators.
The example:
X-User-Role: admin
For security purposes, define permissions on the server: retrieve a role from a session, from a database, or from a token with a verified signature.
The fixed code:
func DeleteAllUsers(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("session")
if err != nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
var role, csrf string
err = DB.QueryRow(
"SELECT role, csrf_token FROM sessions WHERE token = ?",
cookie.Value,
).Scan(&role, &csrf)
sent := r.Header.Get("X-CSRF-Token")
if err != nil || role != "admin" || csrf == "" ||
subtle.ConstantTimeCompare([]byte(sent), []byte(csrf)) != 1 {
http.Error(w, "forbidden", http.StatusForbidden)
return
}
DB.Exec("DELETE FROM users")
// ...
}
The handler uses the session cookie value to locate the session in the database. Then, it retrieves the user's role and CSRF token. It performs the deletion only if it successfully retrieves the session, the user's role is admin, and the non-empty token stored in the database matches the value in the X-CSRF-Token header. The OWASP Authorization Cheat Sheet also recommends checking permissions on every request and denying access by default.
This diagnostic rule is classified as:
|