Repository navigation
fix(a2a): parse quoted values and escapes in WWW-Authenticate headers - #9111
Mehedi Hasan (Mahdi-Hasan) wants to merge 1 commit into
Conversation
parse_www_authenticate split the header with regexes that ignored quoting.
A comma inside a quoted value, such as the sentence RFC 6750 allows in
error_description, cut the value at the comma and turned the following
words into extra challenges ("which", "is"). An empty quoted value came
back as None, an escaped quote ended the value early, and a scheme sent
without parameters ("Bearer") was dropped.
Read the header with a small scanner instead: quoted strings with
backslash escapes, comma separated parameters, and one challenge per
scheme token, including schemes with no parameters. Unquoted values and
the returned shape are unchanged.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Strix Security Review✅ No open security findings. PR summary: Rewrites `parse_www_authenticate` in the A2A auth utils as a quote-aware tokenizer so commas inside quoted values, escaped quotes, empty quoted values and bare schemes parse correctly, and adds a unit-test module covering those cases. Review summaryThis PR replaces the two regex Ruled out (3)
Review 1 on this PR · Reviewed by Strix |
Fixes #9108
parse_www_authenticatesplit the header with regexes that ignore quoting, so a comma inside a quoted value cut it short and created bogus challenges. It now tokenises with quote-aware parsing and handles escaped quotes, empty quoted values and bare schemes. Addslib/crewai/tests/a2a/utils/test_auth_utils.py: 6 of 10 fail onmain, all pass now; the 111 tests inlib/crewai/tests/a2apass; ruff clean.Note
Medium Risk
Changes how 401
WWW-Authenticatechallenges are parsed for A2A retry logic; behavior shifts for edge cases but aligns with intended header semantics.Overview
parse_www_authenticateno longer splitsWWW-Authenticatewith regexes that treat commas inside quoted strings as challenge separators. It now scans the header with quote-aware param matching, unescapes\"in quoted values, and still records schemes with no parameters (e.g. bareBearerorNegotiate).New patterns (
_NAME_CHARS, separator/param/scheme matchers,_QUOTED_PAIR_PATTERN) replace the old_SCHEME_PATTERN/_PARAM_PATTERNpair.lib/crewai/tests/a2a/utils/test_auth_utils.pyadds coverage for multi-challenge headers, commas in quotes, escapes, empty quoted values, and whitespace-only headers.This parser feeds
retry_on_401, so more accurate challenge dicts should reduce mis-parsed 401 metadata during A2A auth retries.Reviewed by Cursor Bugbot for commit ba8e488. Bugbot is set up for automated code reviews on this repo. Configure here.