Repository navigation
fix(server): answer an unreadable form body as invalid_request - #512
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
FormRequestFromHTTP, and the PushAuthorizationRequestFromHTTP, TokenEndpointRequestFromHTTP and BeginBackchannelAuthenticationRequestFromHTTP constructors built on it, returned plain errors for a body they couldn't take: not form-encoded, unreadable, over 1 MiB, or malformed. So server.WriteError, whose doc says every error this package returns is a *Error, answered the client's mistake with a 500 server_error. Each is now a 400 invalid_request *Error with a fixed public description; the detail stays in the cause, for logs. BeginAuthorizationRequestFromHTTP already did this. The demos' badRequest helpers and the conformance AS's err.Error() echo (which sent the internal message to the client) give way to server.WriteError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
osanderson
force-pushed
the
fix/server-fromhttp-errors
branch
from
October 2, 2026 06:11
e7cf95e to
ee2f80a
Compare
|
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
This addresses DevX review item 5.
FormRequestFromHTTP, and the three constructors built on it (PushAuthorizationRequestFromHTTP,TokenEndpointRequestFromHTTP,BeginBackchannelAuthenticationRequestFromHTTP), returned plainfmterrors for a body they couldn't take. So the naturalserver.WriteError(w, err)answered a malformed request with a 500server_error, contrary toWriteError's doc ("every error this package's own methods return" is a*Error).BeginAuthorizationRequestFromHTTP(#505) already returned a 400*Error.Each failure is now a 400
invalid_request*Error. Its public description is fixed and doesn't echo input, and the detail stays in the cause for logs:It isn't breaking: the functions still return
error, now always a*server.Error.Call sites:
badRequesthelpers (log plus a generic 400) are deleted, and the call sites useserver.WriteError.cmd/conformance-as: the PAR, token and CIBA handlers usedwriteRawOAuthError(..., err.Error()), which sent the internal error text to the client. They now usewriteOAuthJSONError(server.WriteError).Tests
TestFromHTTPBodyFailuresAreInvalidRequest: five failures (wrong content type, malformed name, malformed value, oversized, unreadable body) across all four constructors. Each is a 400invalid_request*server.Error, andWriteErrorwrites 400"invalid_request".go test ./server/... ./cmd/...passes.🤖 Generated with Claude Code