Return 401 for missing/malformed Authorization header#3948
Open
buildingvibes wants to merge 2 commits intozio:mainfrom
Open
Return 401 for missing/malformed Authorization header#3948buildingvibes wants to merge 2 commits intozio:mainfrom
buildingvibes wants to merge 2 commits intozio:mainfrom
Conversation
When an endpoint requires authentication and the Authorization header is missing or malformed, return 401 Unauthorized with a WWW-Authenticate header per RFC 7235 Section 3.1, instead of the generic 400 Bad Request. Handles MissingHeader, MissingHeaders, MalformedHeader, and DecodingErrorHeader cases for the Authorization header specifically. Fixes zio#3235
✅ Deploy Preview for zio-http ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Author
|
recheck |
Author
|
Hi! Just checking in - all CI checks are passing (40+ jobs across Scala 2.12/2.13/3.3 on multiple JVMs), CLA is signed, and the implementation follows the existing patterns for error handling in Endpoint.scala. This fixes #3235 where missing/malformed Authorization headers return 400 instead of the correct 401. Happy to address any feedback! |
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 #3235. When an endpoint requires authentication via
.header(HeaderCodec.authorization)or.auth(AuthType.Bearer), a request without a valid Authorization header now returns 401 Unauthorized instead of 400 Bad Request, per RFC 7235 Section 3.1.Changes
Endpoint.scalaisAuthorizationErrorhelper that detects when a codec error is related to the Authorization header (handlesMissingHeader,MissingHeaders,MalformedHeader, andDecodingErrorHeader)catchAllCauseerror handler that returns 401 withWWW-Authenticateheader for auth-related errorsAuthType.scalawwwAuthenticateHeadermethod that generates the appropriateWWW-Authenticatechallenge value (e.g.,Bearer realm="restricted")Tests
RFC Compliance