René's URL Explorer Experiment


Title: fix: add SSRF redirect protection to httpx client factory by dgenio · Pull Request #2180 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix: add SSRF redirect protection to httpx client factory by dgenio · Pull Request #2180 · modelcontextprotocol/python-sdk

X Title: fix: add SSRF redirect protection to httpx client factory by dgenio · Pull Request #2180 · modelcontextprotocol/python-sdk

Description: What changed Adds a RedirectPolicy enum and redirect validation event hook to create_mcp_http_client() in src/mcp/shared/_httpx_utils.py to protect against SSRF attacks via HTTP redirects. Changes: src/mcp/shared/_httpx_utils.py: Added RedirectPolicy enum with three presets: BLOCK_SCHEME_DOWNGRADE (default) — blocks HTTPS→HTTP redirect downgrades ENFORCE_HTTPS — only allows HTTPS redirect destinations ALLOW_ALL — no restrictions (legacy behavior) Added _check_redirect() async response event hook that validates redirect targets against the configured policy using response.has_redirect_location and the Location header Added redirect_policy parameter to create_mcp_http_client() (default: BLOCK_SCHEME_DOWNGRADE) McpHttpClientFactory Protocol left unchanged — redirect_policy is an internal concern of create_mcp_http_client, not part of the caller-side contract src/mcp/client/streamable_http.py: Added docstring note on http_client parameter clarifying that user-provided clients do not receive SSRF redirect protection Added logger.debug when a user-provided client is used tests/shared/test_httpx_utils.py: 14 unit tests covering all three policies, edge cases (non-redirect responses, missing Location header), and all scheme combinations 2 integration tests using httpx.MockTransport that exercise the event hook wiring end-to-end through the real httpx client Why A malicious MCP server can respond with a 3xx redirect pointing to internal network addresses (http://169.254.169.254, http://localhost, etc.), enabling SSRF attacks. The SDK previously set follow_redirects=True with zero redirect validation. The default BLOCK_SCHEME_DOWNGRADE policy prevents the most common SSRF vector (HTTPS→HTTP downgrade to reach internal services) while remaining backward-compatible for legitimate use cases. Bug discovered during review The initial implementation used response.next_request to inspect redirect targets, but httpx never populates next_request when follow_redirects=True — causing the protection to silently bypass all checks. Fixed to use response.has_redirect_location + parse the Location header directly, matching httpx's own _build_redirect_request flow. How verified ruff check . — all checks passed ruff format --check . — no formatting issues pyright — 0 errors, 0 warnings pytest tests/shared/test_httpx_utils.py -v — 16 passed pytest tests/client/test_client.py -v — 19 passed (no regressions) Tradeoffs / risks The new redirect_policy parameter on create_mcp_http_client has a default value, so all existing callers are unaffected — no breaking change McpHttpClientFactory Protocol is not modified, preserving compatibility for downstream code implementing custom factories Users who need the legacy behavior can pass redirect_policy=RedirectPolicy.ALLOW_ALL Private/link-local IP range blocking is not included in this PR — suggested as a follow-up Scope notes RedirectPolicy is not re-exported from mcp.__init__ — create_mcp_http_client itself is also not publicly exported, so both share the same visibility via mcp.shared._httpx_utils. Public API surface expansion is suggested as a follow-up HttpResource in resources/types.py uses a bare httpx.AsyncClient() (separate concern, not addressed here) Closes #2106

Open Graph Description: What changed Adds a RedirectPolicy enum and redirect validation event hook to create_mcp_http_client() in src/mcp/shared/_httpx_utils.py to protect against SSRF attacks via HTTP redirects. Changes:...

X Description: What changed Adds a RedirectPolicy enum and redirect validation event hook to create_mcp_http_client() in src/mcp/shared/_httpx_utils.py to protect against SSRF attacks via HTTP redirects. Changes:...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2180

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:fa6bc780-7180-75c7-3d2c-8ccadbc1dc96
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id963E:26889C:F1E450:1438536:6A5BA34E
html-safe-nonce6b67630602018c17634cb0547b481d74594a2bf35e48f7914262b4349facc25a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjNFOjI2ODg5QzpGMUU0NTA6MTQzODUzNjo2QTVCQTM0RSIsInZpc2l0b3JfaWQiOiI0NjM5NTc4MDUyMTA3NzIzMDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc065901e8d4c426f3015aba58e7927e931b8c26fce553e9dce806053b2d1b094
hovercard-subject-tagpull_request:3338803597
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2180/files
twitter:imagehttps://avatars.githubusercontent.com/u/12731907?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/12731907?s=400&v=4
og:image:altWhat changed Adds a RedirectPolicy enum and redirect validation event hook to create_mcp_http_client() in src/mcp/shared/_httpx_utils.py to protect against SSRF attacks via HTTP redirects. Changes:...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c975978430e9ad293956f2bbdaf153b1bd84a99
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2180%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2180%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 259 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 306 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
dgeniohttps://github.com/dgenio
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
dgenio:feat/ssrf-redirect-protectionhttps://github.com/dgenio/python-sdk/tree/feat/ssrf-redirect-protection
Conversation 0 https://github.com/modelcontextprotocol/python-sdk/pull/2180
Commits 5 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits
Checks 26 https://github.com/modelcontextprotocol/python-sdk/pull/2180/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
fix: add SSRF redirect protection to httpx client factory https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#top
Show all changes 5 commits https://github.com/modelcontextprotocol/python-sdk/pull/2180/files
5423962 fix: add SSRF redirect protection to httpx client factory dgenio Feb 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits/542396228deef98f15756e4c2209953a46be35cc
1f1efbd fix: use Location header for redirect validation instead of next_request dgenio Feb 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits/1f1efbd91481464f34838b4a74ebabca696066fd
6fc1bc7 fix: remove redirect_policy from McpHttpClientFactory Protocol dgenio Feb 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits/6fc1bc724a813720f9eb69b0911a96470e6f8e29
06d1f1e docs: document SSRF redirect protection gap for user-provided clients dgenio Feb 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits/06d1f1e5664b623d235cba0af6fc61187fb6e820
75a4e45 test: fix coverage gaps for relative redirect and unreachable mock br… dgenio Feb 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2180/commits/75a4e4520f958e6f88acebc9bfbacfcde80507d5
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
_httpx_utils.py https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-c4baff3567caa38efcdfd8b6a554abe19fcf6429c80e6e693ed1a847a7aec431
test_httpx_utils.py https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-b0498e819959a6703b5a7ae1a5d5738d0779b500589c6fd4eca497bfa0fe32bb
src/mcp/client/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
View file https://github.com/modelcontextprotocol/python-sdk/blob/75a4e4520f958e6f88acebc9bfbacfcde80507d5/src/mcp/client/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2180/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
src/mcp/shared/_httpx_utils.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-c4baff3567caa38efcdfd8b6a554abe19fcf6429c80e6e693ed1a847a7aec431
View file https://github.com/modelcontextprotocol/python-sdk/blob/75a4e4520f958e6f88acebc9bfbacfcde80507d5/src/mcp/shared/_httpx_utils.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2180/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-c4baff3567caa38efcdfd8b6a554abe19fcf6429c80e6e693ed1a847a7aec431
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-c4baff3567caa38efcdfd8b6a554abe19fcf6429c80e6e693ed1a847a7aec431
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-c4baff3567caa38efcdfd8b6a554abe19fcf6429c80e6e693ed1a847a7aec431
tests/shared/test_httpx_utils.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-b0498e819959a6703b5a7ae1a5d5738d0779b500589c6fd4eca497bfa0fe32bb
View file https://github.com/modelcontextprotocol/python-sdk/blob/75a4e4520f958e6f88acebc9bfbacfcde80507d5/tests/shared/test_httpx_utils.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2180/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2180/files#diff-b0498e819959a6703b5a7ae1a5d5738d0779b500589c6fd4eca497bfa0fe32bb
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2180/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.