fix: don't leak internal error detail in GET /v0/servers 500 response#1338
Merged
Conversation
ListServersError passed the raw err into huma.Error500InternalServerError, which huma serializes into the response body's `errors` array. On the public, unauthenticated GET /v0/servers endpoint this echoed internal pgx/DB error detail (e.g. from postgres.go "error iterating rows") back to clients (CWE-209). Log it server-side only, matching the sibling handlers in servers.go. Adds a regression test asserting the 500 response body does not contain the internal error string. Closes #1337 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the information-disclosure regression introduced by #1335 (item 1 of #1337).
ListServersErrorpassed the rawerrintohuma.Error500InternalServerError(...). huma serializes extra error args into the response body'serrorsarray (ErrorModel.Errors,json:"errors,omitempty"), so on the public, unauthenticatedGET /v0/serversendpoint a genuine DB failure echoed the internal wrapped error frominternal/database/postgres.go(error iterating rows: <pgx error>) back to the client. pgx/pgconn errors can carry SQLSTATE codes, constraint/table/column names, and internal messages (CWE-209).Change
errfrom the 500 call so only the generic message is returned; keeplog.Printffor the server-side detail — matching the sibling handlers (servers.go:190/220,edit.go,status.go).TestListServersError_realFailureDoesNotLeakDetail) that marshals the 500 error and asserts the internal detail is absent from the client-visible body. Existing tests only asserted status codes, which is why the leak slipped through.The 499 client-cancelled path is unchanged (the client has already disconnected, so nothing is leaked there).
Test plan
go test ./internal/api/handlers/v0/... -run ListServersError(3/3 pass)go build ./...,go vet,golangci-lint(no new findings in changed files)Note
This leaves the non-security items in #1337 (correcting the
superfluous WriteHeaderclaim,statusClientClosedconst reuse, broader cancellation-guard scope) for separate follow-up. Closing #1337 here since the only security-impacting item is addressed; reopen/split if you'd prefer to track the nits independently.Closes #1337
🤖 Generated with Claude Code