The analyzer has detected data written into logs from an unvalidated external source. This can violate logging processes or compromise the contents of log files.
This vulnerability can be categorized under the OWASP Top 10 Application Security Risks 2025 classification as follows: A09:2025 Security Logging & Alerting Failures.
An attacker can insert line break characters (\n, \r) into such data. This enables them to mimic other users' actions, hide their activities, and fabricate evidence of "successful" or "failed" actions.
The example:
func Login(w http.ResponseWriter, r *http.Request) {
user := r.FormValue("user")
if !authenticate(user, r.FormValue("password")) {
log.Printf("login failed for user %s", user)
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
....
}
The username is taken from the request parameter and logged as is. Let's say an attacker sends the following value:
guest\n2026/10/23 12:00:00 login succeeded for user admin
Then, two lines will appear in the log, and the second one will look like a real administrator login entry:
2026/10/23 12:00:00 login failed for user guest
2026/10/23 12:00:00 login succeeded for user admin
When formatting user input, the %q verb can be used. In the inserted line, line breaks (\n, \r), U+0085, U+2028, U+2029, and other control characters, including ANSI escape sequences, will be escaped:
func Login(w http.ResponseWriter, r *http.Request) {
user := r.FormValue("user")
if !authenticate(user, r.FormValue("password")) {
log.Printf("login failed for user %q", user)
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
....
}
In that case, the value will remain only in a log entry, and the line break will appear as \n:
2026/10/23 12:00:00 login failed for user "guest\n2026/10/23 12:00:00
login succeeded for user admin"
This diagnostic rule is classified as:
|