The analyzer has detected potentially unsafe access to an object using an identifier obtained from an external source. The current user's permissions for this object are not verified before the operation is executed.
This can lead to an Insecure Direct Object Reference (IDOR) vulnerability. An attacker alters the identifier in a request and gains the ability to read, modify, or delete other users' data. For example, by entering the number of someone else's document, a user can view its contents.
This vulnerability falls under the following risk category in the OWASP Top 10 Application Security Risks 2025: A01:2025 Broken Access Control.
The example:
func getDocument(w http.ResponseWriter, r *http.Request, db *sql.DB) {
id := r.URL.Query().Get("id")
var body string
err := db.QueryRowContext(
r.Context(),
"SELECT body FROM documents WHERE id = ?",
id,
).Scan(&body)
if err != nil {
http.Error(w, "Document unavailable", http.StatusNotFound)
return
}
fmt.Fprint(w, body)
}
The handler uses the id parameter to select a document, but does not check whether the current user is authorized to read that document. If the documents are intended only for their owners, a user can retrieve someone else's data by changing the id value.
The fixed example:
func getDocument(w http.ResponseWriter, r *http.Request, db *sql.DB) {
user, ok := currentUser(r)
if !ok {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
id := r.URL.Query().Get("id")
var body string
err := db.QueryRowContext(
r.Context(),
`SELECT body FROM documents
WHERE id = ? AND owner_id = ?`,
id,
user.ID).Scan(&body)
if err != nil {
http.Error(w, "Document unavailable", http.StatusNotFound)
return
}
fmt.Fprint(w, body)
}
One way to resolve the error is to limit the selection to objects accessible to the current user.
In the corrected example, currentUser is an application function that retrieves information about the current user from a server-verified session or another trusted authentication context.
The additional condition owner_id = ? allows you to select a document only if the owner's ID matches that of the current user. The owner's ID is obtained from a trusted source.
This diagnostic rule is classified as:
|