fix(openapi): keep blank values in parse_qs (refs #4056)#4076
Open
MukundaKatta wants to merge 1 commit intoPrefectHQ:mainfrom
Open
fix(openapi): keep blank values in parse_qs (refs #4056)#4076MukundaKatta wants to merge 1 commit intoPrefectHQ:mainfrom
MukundaKatta wants to merge 1 commit intoPrefectHQ:mainfrom
Conversation
The HeadlessOAuth callback handler in src/fastmcp/utilities/tests.py
called parse_qs() without keep_blank_values=True, so an explicitly-empty
query parameter (e.g. ?state= or ?error_description=) was silently
dropped. Real OAuth providers can emit empty values, and downstream code
uses .get("state", [None])[0] to distinguish "not present" (None) from
"present but empty" (""). Without the flag, both cases collapsed to None.
This is the same defect class that PR PrefectHQ#4069 fixed in
src/fastmcp/resources/template.py; this commit applies the same fix to
the remaining parse_qs call site so behavior is consistent across the
code base.
Adds three regression tests in tests/utilities/test_tests.py covering
blank state, missing state, and blank error_description.
Contributor
|
Thanks for the report. This issue goes beyond what our contributor guidelines ask for — we just need a short problem description and an MRE. Please see our contributing guidelines and condense this issue. We'll triage it once it's trimmed down. |
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
HeadlessOAuth.callback_handlerparses OAuth callback query strings withparse_qs(parsed.query)withoutkeep_blank_values=True.That drops explicitly empty values, so
?code=abc&state=is treated the same as a missingstate, and?error=invalid_request&error_description=falls back toUnknown errorinstead of preserving the provider's empty description.MRE
Fix
Add
keep_blank_values=Trueto the remainingparse_qscall insrc/fastmcp/utilities/tests.py.Tests
Added focused coverage for:
stateround-tripping as""statestill returningNoneerror_descriptionstaying blank instead of using the fallbackRefs #4056. This PR is intentionally scoped to the remaining
HeadlessOAuth.callback_handlercall site; #4069 handled the template parser path.