Skip to content

oauthex: accept empty list elements in WWW-Authenticate - #1351

Merged
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
akshita317:oauthex/empty-list-elements
Oct 19, 2026
Merged

guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
akshita317:oauthex/empty-list-elements

Conversation

@akshita317

Copy link
Copy Markdown
Contributor

RFC 9110, section 5.6.1.2, requires a recipient to accept empty list elements, such as the extra comma in a=1,, b=2. ParseWWWAuthenticate did not.

After a second comma, splitChallenges saw , b=2 as the start of a new challenge, so a server sending

WWW-Authenticate: Bearer realm="x",, resource_metadata="https://example.com/.well-known/oauth-protected-resource"

parsed as a Bearer challenge without resource_metadata, plus a second challenge with scheme ",". AuthorizationCodeHandler.Authorize then never saw the resource metadata URL from the challenge. An empty element right after the scheme (Bearer ,realm="x") produced a parameter named ,realm.

This skips empty list elements both where splitChallenges looks ahead after a comma and where parseSingleChallenge consumes one.

Tests (each fails without the change):

  • TestParseWWWAuthenticateEmptyListElements: empty elements before, between and after params and between challenges keep resource_metadata on the Bearer challenge.
  • TestSplitChallenges: an empty element between params does not split the challenge.
  • TestParseSingleChallenge: empty elements around params are ignored.

AI assistance: prepared with Claude Code.

🤖 Generated with Claude Code

RFC 9110, section 5.6.1.2, requires a recipient to accept empty list
elements, such as the extra comma in "a=1,, b=2". ParseWWWAuthenticate
did not: after a second comma, splitChallenges saw ", b=2" as the start
of a new challenge, so

	Bearer realm="x",, resource_metadata="https://..."

parsed as a Bearer challenge without resource_metadata plus a challenge
with scheme ",". An empty element right after the scheme
("Bearer ,realm=x") produced a parameter named ",realm".

Skip empty list elements both where splitChallenges looks ahead after a
comma and where parseSingleChallenge consumes one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@guglielmo-san
guglielmo-san merged commit ac7c421 into modelcontextprotocol:main Oct 19, 2026
9 checks passed
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.

2 participants