Skip to content

fix: don't leak internal error detail in GET /v0/servers 500 response#1338

Merged
rdimitrov merged 1 commit into
mainfrom
fix/list-servers-500-error-leak
Jun 5, 2026
Merged

fix: don't leak internal error detail in GET /v0/servers 500 response#1338
rdimitrov merged 1 commit into
mainfrom
fix/list-servers-500-error-leak

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

Fixes the information-disclosure regression introduced by #1335 (item 1 of #1337).

ListServersError passed the raw err into huma.Error500InternalServerError(...). huma serializes extra error args into the response body's errors array (ErrorModel.Errors, json:"errors,omitempty"), so on the public, unauthenticated GET /v0/servers endpoint a genuine DB failure echoed the internal wrapped error from internal/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

  • Drop err from the 500 call so only the generic message is returned; keep log.Printf for the server-side detail — matching the sibling handlers (servers.go:190/220, edit.go, status.go).
  • Add a regression test (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 WriteHeader claim, statusClientClosed const 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

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>
@rdimitrov
rdimitrov merged commit fecef4f into main Jun 5, 2026
6 checks passed
@rdimitrov
rdimitrov deleted the fix/list-servers-500-error-leak branch June 5, 2026 07:08
rdimitrov added a commit that referenced this pull request Jul 10, 2026
Addresses review findings on the org-namespace-admin-only change:

- Don't leak internal error detail in the github-at 401. The handler passed
  the wrapped err (which can include the raw upstream GitHub response body from
  readErrorBody) into huma.Error401Unauthorized, and huma serializes extra err
  args into the response body (CWE-209) — the same leak fixed for GET /v0/servers
  in #1338. Log it server-side and return only a generic message. Regression
  test added (github_at_internal_test.go), mirroring #1338.

- Fail closed on a SAML/SSO-enforcement 403 (X-GitHub-SSO header) instead of
  treating it as a missing-scope 403 and silently degrading a legitimate Owner
  to personal-only with no signal.

- Re-check membership state=active client-side, not only via the query param,
  so a dropped/changed param can't grant a pending (not-yet-accepted) owner
  invitation.

- Cap the org-memberships pagination loop (previously unbounded) and fail closed
  if the cap is hit with full pages, rather than returning a possibly-truncated
  grant.

- In buildPermissions, skip an org whose name fails validation instead of
  returning nil for the whole set, so one unexpected org name can't strip the
  caller's personal namespace or their other valid org grants.

- Correct the role comment: GET /user/memberships/orgs returns "admin"/"member",
  not "billing_manager".

Adds tests for pending-state exclusion, billing_manager exclusion, and
Retry-After / SSO 403 fail-closed handling.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /v0/servers 500 path leaks internal error detail to client (follow-up to #1335)

1 participant