Add allowed_schemes to PyJWKClient#1176
Open
davisjk wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an allowed_schemes parameter to PyJWKClient so callers can customize which URI schemes are permitted for the JWKS endpoint (e.g., enabling non-HTTP schemes for subclasses), addressing #1175.
Changes:
- Adds
allowed_schemestoPyJWKClient.__init__with a default of("http", "https"). - Updates scheme validation logic and the associated error message to reference the configurable schemes.
- Documents the new parameter in the constructor docstring.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
81
to
86
| scheme = urlparse(uri).scheme.lower() | ||
| if scheme not in ("http", "https"): | ||
| if scheme not in allowed_schemes: | ||
| raise PyJWKClientError( | ||
| f"Invalid JWKS URI scheme {scheme!r}: only 'http' and 'https' " | ||
| f"are supported." | ||
| f"Invalid JWKS URI scheme {scheme!r}: only " | ||
| f"{' and '.join(allowed_schemes)} are supported." | ||
| ) |
Comment on lines
77
to
80
| # urllib's default OpenerDirector also handles file://, ftp://, and | ||
| # data: URIs. Reject anything that isn't http(s) eagerly so a caller | ||
| # passing an attacker-influenced URL (e.g. taken from a `jku` token | ||
| # header) can't read local files or reach other unintended schemes. |
| headers: dict[str, Any] | None = None, | ||
| timeout: float = 30, | ||
| ssl_context: SSLContext | None = None, | ||
| allowed_schemes: Iterable[str] = ("http", "https"), |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
@auvipy Thanks for the findings fix |
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.
Summary
Fixes #1175
PyJWKClient has the allowed schemes hard coded to "http" and "https". Developers have legitimate reasons to allow other schemes or not allow "http" in order to implement sub-classes for interfacing with other URI schemes such as an S3 bucket.
Testing