fix: reject stray trailing token after a valid auth-param in AuthChallengeParser#199
Merged
Merged
Conversation
…lengeParser A WWW-Authenticate / Proxy-Authenticate value of the shape `Scheme key=value <token>` — a bare token directly following a valid auth-param with no separating comma (e.g. `Bearer realm="x" garbage`) — was mishandled. The continuation loop kept the param list open only while the next non-whitespace character was a comma, so on hitting the stray token it broke out and left the cursor parked on it. The top-level loop then read that token as the scheme of a phantom second challenge, so `Digest realm=value extra` parsed into two challenges (`digest` plus a bare `extra`) instead of one malformed challenge. RFC 7235 §2.1 permits only a comma or end-of-input after an auth-param; a bare token there has no grammar production. The continuation loop now skips the malformed tail to the next top-level comma and emits the challenge with the params parsed before the garbage — consistent with the parser's existing lenient recovery, which preserves prior params. Adds regression tests for the unquoted, quoted, and comma-separated-next-challenge variants.
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.
Problem
AuthChallengeParseraccepted a malformedWWW-Authenticate/Proxy-Authenticatevalue of the shape
Scheme key=value <token>— a bare token directly following anotherwise valid auth-param with no separating comma, e.g.
Bearer realm="x" garbage.The continuation loop kept the param list open only while the next non-whitespace
character was a comma, so when it hit the stray token it broke out and left the cursor
parked on that token. The top-level parse loop then read the stray token as the scheme
of a phantom second challenge. As a result
Digest realm=value extraparsed into twochallenges (
digestwithrealm=value, plus a bareextra) instead of being treated asa single malformed challenge.
Change
RFC 7235 §2.1 permits only a comma (introducing another auth-param or the next challenge)
or end-of-input after an auth-param; a bare token in that position has no grammar
production. When the continuation loop now sees a non-comma, non-EOF character after a
valid auth-param, it skips the malformed tail to the next top-level comma via
recoverToNextChallengeand emits the challenge with the params parsed before thegarbage. This:
next outer iteration, and
recovery on malformed continuations.
Tests
Digest realm=value extra(unquoted) — one challenge,realm=value, no phantomextrascheme.Digest realm="value" extra(quoted) — same.Digest realm=value extra, Basic realm="x"— the stray token is skipped to the nextcomma and the following
Basicchallenge is still parsed.Build
Ran (scoped to the touched module):
BUILD SUCCESSFUL. No public-API change, so
apiCheckpasses against the committed.apisnapshot with noapiDumpneeded.Closes #111. Replaces #142, which targeted the old
http.authpackage path sincerelocated to
auth.