Skip to content

Add allowed_schemes to PyJWKClient#1176

Open
davisjk wants to merge 4 commits into
jpadilla:masterfrom
davisjk:master
Open

Add allowed_schemes to PyJWKClient#1176
davisjk wants to merge 4 commits into
jpadilla:masterfrom
davisjk:master

Conversation

@davisjk
Copy link
Copy Markdown

@davisjk davisjk commented May 26, 2026

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

  • This doesn't raise an error
from jwt import PyJWKClient
client = PyJWKClient("s3://my-bucket/jwks.json", allowed_schemes=["s3"])

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_schemes to PyJWKClient.__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 thread jwt/jwks_client.py
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 thread jwt/jwks_client.py
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.
Comment thread jwt/jwks_client.py Outdated
Comment thread jwt/jwks_client.py
headers: dict[str, Any] | None = None,
timeout: float = 30,
ssl_context: SSLContext | None = None,
allowed_schemes: Iterable[str] = ("http", "https"),
auvipy and others added 2 commits May 27, 2026 21:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@davisjk
Copy link
Copy Markdown
Author

davisjk commented Jun 3, 2026

@auvipy Thanks for the findings fix

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.

Define Allowed Schemes at PyJWKClient init

3 participants