Skip to content

Commit 8dab542

Browse files
committed
fix: keep backend error detail out of 5xx response bodies
RespondWithError echoed the underlying error into the JSON body for every status code, so 500s exposed backend internals such as database connection errors. 5xx bodies now carry only the generic message; the underlying error stays in the server log. Signed-off-by: QuentinBisson <[email protected]>
1 parent ff43b38 commit 8dab542

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎go/core/internal/httpserver/middleware_error.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func (w *errorResponseWriter) RespondWithError(err error) {
7676
w.Header().Set("Content-Type", "application/json")
7777
w.WriteHeader(statusCode)
7878
errMsg := message
79-
if underlying != nil {
79+
// 5xx bodies carry only the generic message: the underlying error is
80+
// backend-internal detail (already logged above) and must not reach clients.
81+
if underlying != nil && statusCode < http.StatusInternalServerError {
8082
errMsg = message + ": " + underlying.Error()
8183
}
8284
json.NewEncoder(w).Encode(map[string]string{"error": errMsg}) //nolint:errcheck

0 commit comments

Comments
 (0)