-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Validates registered redirect_uris for DCR are a secure schema with no fragments #3206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Varshith-Kali
wants to merge
5
commits into
modelcontextprotocol:main
Choose a base branch
from
Varshith-Kali:fix/validate-redirect-uris
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c62757
Validates registered redirect_uris for DCR are a secure schema with n…
Varshith-Kali fb893dd
Fix circular import by moving validate_redirect_uri to url_validators…
Varshith-Kali 9060ac0
Fix BOM, CRLF line endings, and escaped quotes in url_validators
Varshith-Kali 0561256
Apply ruff formatting to test_routes.py
Varshith-Kali 4e77490
Only reject non-HTTP(S) schemes and fragments for redirect URIs
Varshith-Kali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| """MCP OAuth server authorization components.""" | ||
|
|
||
| from .url_validators import validate_issuer_url, validate_redirect_uri |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """OAuth 2.0 URL validation helpers for MCP authorization servers. | ||
|
|
||
| RFC 9700 4.1.1 and RFC 7591 2 require HTTPS for authorization endpoint URLs | ||
| and registered redirect_uris, with an HTTP loopback exception for local | ||
| development. | ||
| """ | ||
|
|
||
| from pydantic import AnyHttpUrl | ||
|
|
||
|
|
||
| def validate_issuer_url(url: AnyHttpUrl): | ||
| """Validate that the issuer URL meets OAuth 2.0 requirements. | ||
|
|
||
| Args: | ||
| url: The issuer URL to validate. | ||
|
|
||
| Raises: | ||
| ValueError: If the issuer URL is invalid. | ||
| """ | ||
| if url.scheme != "https" and url.host not in ("localhost", "127.0.0.1", "[::1]"): | ||
| raise ValueError("Issuer URL must be HTTPS") | ||
|
|
||
| if url.fragment: | ||
| raise ValueError("Issuer URL must not have a fragment") | ||
| if url.query: | ||
| raise ValueError("Issuer URL must not have a query string") | ||
|
|
||
|
|
||
| def validate_redirect_uri(url: AnyHttpUrl): | ||
| """Validate a registered redirect_uri for DCR. | ||
|
|
||
| RFC 9700 section 4.1.1 and RFC 7591 section 2 require HTTPS for | ||
| redirect_uris, with an HTTP loopback exception for local development. | ||
|
|
||
| Args: | ||
| url: The redirect URI to validate. | ||
|
|
||
| Raises: | ||
| ValueError: If the redirect URI uses an unsafe scheme or contains | ||
| a fragment. | ||
| """ | ||
| if url.scheme not in ("http", "https"): | ||
| raise ValueError("Redirect URI must use an HTTP(S) scheme") | ||
|
|
||
| if url.fragment is not None: | ||
| raise ValueError("Redirect URI must not contain a fragment") |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: validate_redirect_uri accepts http:// for any host, not just loopback. The docstring promises RFC 9700 HTTPS enforcement with loopback exception, but only non-HTTP(S) schemes are rejected — http://evil.com/cb passes. This exposes authorization codes to interception over plain HTTP for non-loopback redirect URIs.
Prompt for AI agents