Skip to content

fix(auth): match complete WWW-Authenticate auth-params, never inside a quoted value - #3871

Closed
DZH166 wants to merge 1 commit into
modelcontextprotocol:mainfrom
DZH166:fix/www-authenticate-auth-param
Closed

DZH166 wants to merge 1 commit into
modelcontextprotocol:mainfrom
DZH166:fix/www-authenticate-auth-param

Conversation

@DZH166

@DZH166 DZH166 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

extract_field_from_www_auth() builds rf'{field_name}=(?:"([^"]+)"|([^\s,]+))' and runs re.search over the whole header, so the requested parameter name matches in three unintended places:

  • as a suffix of another auth-param: for x_scope="admin", scope="files:read", asking for scope returns admin (and x_resource_metadata= redirects RFC 9728 discovery to another URL);
  • as plain text inside another parameter's quoted value: error_description="... scope=admin ..." answers for scope;
  • the quoted alternative cannot express an empty value (scope="" returns the two quote characters) or a quoted-pair escape (scope="a\"b" truncates at the backslash).

The extracted scope feeds the authorization request (and the SEP-2350 step-up union) and the extracted resource_metadata feeds discovery URL selection, so both follow a decoy parameter.

before: scope read out of error_description ('admin' instead of 'files:read');
        x_scope="admin" answers for scope; x_resource_metadata redirects discovery;
        scope="" -> '""'
after : every parameter is matched as a complete auth-param name

Fix

Parse the header into auth-params (token = ( token / quoted-string ), RFC 7235 §2.1), honouring quoted-pair escapes and empty quoted values, and look up the requested name exactly.

Tests

tests/client/test_auth.py gains cases for suffix names, text inside a quoted value, empty quoted values, escaped quotes and unterminated quotes. A standalone script reproduces the behaviour before/after (exit 1 -> 0); the header parser is covered by the added tests.

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and this PR doesn't link an open issue yet.

  • If you're already assigned to an issue for this, add Fixes #<n> to the description and the PR will reopen on its own.
  • If there's no issue yet, please open one instead: what you ran into, why it matters for your use case, and a minimal reproduction. That context is super important to us and is what we use to decide what to prioritise.
  • If there's an issue but you're not assigned, add Fixes #<n> anyway so they're linked, then engage on the issue itself by confirming the repro or describing the approach you'd take. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. If you are assigned, this PR reopens automatically.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant