Skip to content

oauthex: skip empty list elements in WWW-Authenticate - #1356

Closed
akshita317 wants to merge 1 commit into
modelcontextprotocol:mainfrom
akshita317:oauthex-empty-list-elements
Closed

akshita317 wants to merge 1 commit into
modelcontextprotocol:mainfrom
akshita317:oauthex-empty-list-elements

Conversation

@akshita317

Copy link
Copy Markdown
Contributor

RFC 9110, section 5.6.1, requires recipients to accept and ignore empty list elements. splitChallenges looked only at the text right after a comma, so in

WWW-Authenticate: Bearer realm="example",, error="insufficient_scope"

the second comma ended the Bearer challenge. The rest was parsed as a separate challenge with scheme ",", and error was no longer a Bearer parameter. On a 403, AuthorizationCodeHandler.Authorize then found no insufficient_scope error and skipped step-up authorization.

This skips empty elements both when deciding whether a comma separates challenges and when parsing a challenge's parameters (including a leading , right after the scheme).

Tests:

  • TestSplitChallenges: empty elements between params and between challenges.
  • TestParseWWWAuthenticateEmptyListElements: leading, doubled, and trailing commas around both challenges; error="insufficient_scope" stays on the Bearer challenge. Fails without the change.

AI assistance: prepared with Claude Code.

RFC 9110, section 5.6.1, requires recipients to accept and ignore empty
list elements, such as the extra comma in

	Bearer realm="example",, error="insufficient_scope"

splitChallenges looked only at the text right after a comma, so the
second comma made it end the Bearer challenge there. The rest was
parsed as a separate challenge with scheme ",", and error was no
longer a Bearer parameter. On a 403, AuthorizationCodeHandler.Authorize
then saw no insufficient_scope error and skipped step-up authorization.

Skip empty elements when deciding whether a comma separates
challenges, and when parsing the parameters of a challenge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@akshita317

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #1351, which fixes the same bug (and was opened first). Sorry for the noise.

@akshita317 akshita317 closed this Oct 9, 2026
@akshita317
akshita317 deleted the oauthex-empty-list-elements branch October 9, 2026 15:30
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.

1 participant