Information Exposure Through Error Message
ID |
go.information_exposure_through_error_message |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Information Leak |
Language |
Go |
Tags |
ASVS50:v16.4.1, CWE:209, NIST.SP.800-53, OWASP:2025:A06, PCI-DSS:6.5.5 |
Rationale
Error messages are an integral part of application development, used to communicate issues in the code to the developers. However, in a production environment, overly detailed error messages can become a security liability. For example, stack traces or database exception messages can disclose information about file paths, internal IP addresses, stack traces, database structure, or library versions, all of which can be exploited if in the hands of a malicious user.
The exposure happens when those details reach whoever sent the request, in the HTTP response. Details written to a server-side log are the recommended remediation, not the flaw, so they are not reported. A stack trace in the response is reported with a higher severity than an exception message.
The risk is the error detail reaching whoever sent the request. This detector reports a stack trace
(debug.Stack()) returned in an HTTP response (http.Error, ResponseWriter.Write, fmt.Fprint* to an
http.ResponseWriter, gin c.JSON / c.String…):
func handler(w http.ResponseWriter, r *http.Request) {
defer func() {
if p := recover(); p != nil {
http.Error(w, fmt.Sprintf("panic: %v\n%s", p, debug.Stack()), http.StatusInternalServerError) // FLAW
}
}()
// ...
}
A stack trace always reveals file paths, packages and code structure, so it is reported with high severity.
An err / err.Error() in the response is not reported: in Go that is idiomatic and mostly carries an
application-authored message. Logging the stack trace server-side (log.Printf("%s", debug.Stack())) is not
reported either, as that is the recommended remediation, nor is a response inside a debug-only branch.
Remediation
To remediate instances of information exposure through error messages, the primary action is to limit the detail provided in exceptions sent to the end-user. Consider the following steps:
-
Generic Error Messages: Ensure that user-facing error messages do not reveal detailed system information. Use generic language and avoid technical specifics.
-
Centralized Error Handling: Employ a global exception handling strategy using a framework that standardizes error responses across your applications.
-
Logging: Utilize logging frameworks to log detailed error information securely, ensuring logs do not expose sensitive data.
-
Security Review: Review all instances where exceptions are caught and handled, ensuring they follow the guidelines above, particularly in areas of code that are publicly accessible.
Following these steps reduces the risk of sensitive data exposure through error messages, thereby strengthening the security posture of the application.
References
-
CWE-209 : Generation of Error Message Containing Sensitive Information.
-
OWASP Top 10 2025 - A06 : Insecure Design.