René's URL Explorer Experiment


Title: fix(server): discard a session whose establishing request was refused by sainikhiljuluri · Pull Request #3229 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix(server): discard a session whose establishing request was refused by sainikhiljuluri · Pull Request #3229 · modelcontextprotocol/python-sdk

X Title: fix(server): discard a session whose establishing request was refused by sainikhiljuluri · Pull Request #3229 · modelcontextprotocol/python-sdk

Description: Fixes #3228 Problem A stateful streamable-HTTP session is minted, registered in _server_instances and given a running task before the request is validated. Every check — Host / DNS-rebinding, Accept, Content-Type, JSON parse, JSON-RPC shape, and the "Missing session ID" check for non-initialize POSTs — lives downstream in the transport, so it runs only after the session already exists. Every request the server itself refuses therefore left a live, non-terminated session behind, and nothing reclaimed it: session_idle_timeout defaults to None and is not reachable from streamable_http_app() (#2455). A refused 406 also handed back a usable Mcp-Session-Id, and a follow-up request on that never-initialized id was served 200. Solution Track the status of the response to the establishing request; if it is >= 400, drop the session and terminate the transport. Chosen over the alternative — "only a POST carrying initialize may establish a session" — because that requires the manager to peek the body, which currently lives in the transport (is_initialization_request). This shape needs no body parsing and closes the same vectors. If you would rather have the stricter shape, say so and I will rewrite it; it would also subsume #3129. Scope: correctness, not a DoS fix Worth stating plainly, because an earlier draft of my own report got this wrong. This does not close an availability hole: on the same no-auth server, 200 valid initialize requests create 200 sessions, so unbounded session growth is already reachable with entirely legitimate traffic. The real gap there is the absence of a session cap plus an unreachable idle reaper, which is #2455 and is untouched here. What this fixes is that the server contradicts itself — requests it refuses leave state behind, a 421 from the default-on DNS-rebinding protection creates a session anyway, and a refusal returns a working session handle. How to test uv sync --frozen --all-extras --dev uv run --frozen pytest tests/server/test_streamable_http_manager.py tests/server/test_streamable_http_router.py -q uv run --frozen --python 3.10 --all-extras --dev pytest -q -n auto ./scripts/test # coverage + strict-no-cover Verified on this branch: ./scripts/test → 100.00%, TOTAL 49628 Stmts 0 Miss 3920 Branch 0 BrPart, strict-no-cover clean Full suite on a real Python 3.10 interpreter → 5586 passed, 10 skipped, 1 xfailed ruff check / ruff format --check → clean pyright --pythonversion 3.10 → the only 2 errors are pre-existing and unrelated (tests/transports/stdio/test_lifecycle.py uses os.waitid, absent on macOS) Against a default-configured server, every session-less vector before and after: vector status before after GET no session id 400 leaked 0 DELETE no session id 400 leaked 0 POST non-initialize 400 leaked 0 POST malformed body 400 leaked 0 POST bad Accept 406 leaked 0 GET bad Host (421) 421 leaked 0 A legitimate initialize still returns 200 with a session header, and a follow-up tools/list on that session is still served 200. Tests test_refused_request_leaves_no_session_behind — five parametrized vectors, each asserting the status and manager._server_instances == {}. Red before this change (all five fail), green after. It pins the same property the suite already asserts by name for the 413 path in test_oversized_content_length_is_rejected_before_body_read_or_session_creation. test_router_reports_a_stream_closure_it_did_not_cause — covers the router's "unexpected closure" branch. Worth explaining: that branch was previously reached only incidentally, by leaked sessions whose streams closed at teardown without ever being terminated. Now that refused sessions are terminated properly, nothing reaches it by accident, so it gets a deliberate test instead of losing coverage. A note on the existing test helper _open_session previously obtained a session via a request the transport rejects — it POSTed an empty body, was answered 400/406, and used the session id that came back anyway. Eight tests depended on that, so they fail against any correct fix. It now performs a real initialize. The reply is an SSE stream, so the body is followed by an http.disconnect, which ends the stream and lets handle_request return while the session lives on in the manager's task group. test_idle_session_is_reaped was building its session the same way and is switched over too. That the suite encoded the buggy behaviour as the way to obtain a session is plausibly why this went unnoticed. Incidental Removes a stale # pragma: no cover on the DELETE header-validation path, now covered by the new parametrized test. Removes four # pragma: no branch markers made unnecessary by the rewritten helper. No new # pragma, # type: ignore, or # noqa anywhere in the diff. Disclosure Written with AI assistance (Claude Code). Filed by me as the human contributor — I own this change and will answer any questions on the implementation or the trade-offs above.

Open Graph Description: Fixes #3228 Problem A stateful streamable-HTTP session is minted, registered in _server_instances and given a running task before the request is validated. Every check — Host / DNS-rebinding, Accep...

X Description: Fixes #3228 Problem A stateful streamable-HTTP session is minted, registered in _server_instances and given a running task before the request is validated. Every check — Host / DNS-rebinding, Accep...

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

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:d4312d9e-a086-b657-2e4e-e3c88b771c0f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id986C:16213B:50A5E:6B92B:6B00B81C
html-safe-noncee7c4889c90d625a0c63ca98a3f411b020ce572bfd5939b6c3575fef880fe7347
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODZDOjE2MjEzQjo1MEE1RTo2QjkyQjo2QjAwQjgxQyIsInZpc2l0b3JfaWQiOiI1NDA0MjY3NDE4MDMxNzk4MzAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac72d5f593c1b209e03c6eda14bdec180d9a24aafc61aee3f81839a1afb40eb2b7
hovercard-subject-tagpull_request:4173163057
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/3229/files
twitter:imagehttps://avatars.githubusercontent.com/u/67470882?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/67470882?s=400&v=4
og:image:altFixes #3228 Problem A stateful streamable-HTTP session is minted, registered in _server_instances and given a running task before the request is validated. Every check — Host / DNS-rebinding, Accep...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2
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
release5429cbfc6aca8c7b9a086a3c8f47400346f38cc9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3229%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3229%2Ffiles
Sign uphttps://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/3229/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
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
sainikhiljulurihttps://github.com/sainikhiljuluri
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
sainikhiljuluri:fix/discard-session-when-establishing-request-refusedhttps://github.com/sainikhiljuluri/python-sdk/tree/fix/discard-session-when-establishing-request-refused
Conversation 3 https://github.com/modelcontextprotocol/python-sdk/pull/3229
Commits 3 https://github.com/modelcontextprotocol/python-sdk/pull/3229/commits
Checks 29 https://github.com/modelcontextprotocol/python-sdk/pull/3229/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/3229/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files
fix(server): discard a session whose establishing request was refused https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#top
Show all changes 3 commits https://github.com/modelcontextprotocol/python-sdk/pull/3229/files
9970afd fix(server): discard a session whose establishing request was refused sainikhiljuluri Jul 30, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3229/commits/9970afde23e7bdbfffce7173d634d6a441f1c939
f31c7f5 test(server): cover unimplemented methods in the refused-request check sainikhiljuluri Aug 13, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3229/commits/f31c7f591235297fb538e7705a928cdc2e15f954
ed73cf3 test(server): cover client disconnect during session establishment sainikhiljuluri Aug 21, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3229/commits/ed73cf36d771e14827872183dbe15fca8c0b81d7
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3229/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
streamable_http_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
test_streamable_http_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
test_streamable_http_router.py https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-19d95b11a9e1249b7955143f91e9e2f482f5b09493dc88875c57b3ee08d58c08
src/mcp/server/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
View file https://github.com/sainikhiljuluri/python-sdk/blob/ed73cf36d771e14827872183dbe15fca8c0b81d7/src/mcp/server/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3229/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
src/mcp/server/streamable_http_manager.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
View file https://github.com/sainikhiljuluri/python-sdk/blob/ed73cf36d771e14827872183dbe15fca8c0b81d7/src/mcp/server/streamable_http_manager.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3229/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
tests/server/test_streamable_http_manager.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
View file https://github.com/sainikhiljuluri/python-sdk/blob/ed73cf36d771e14827872183dbe15fca8c0b81d7/tests/server/test_streamable_http_manager.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3229/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
tests/server/test_streamable_http_router.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-19d95b11a9e1249b7955143f91e9e2f482f5b09493dc88875c57b3ee08d58c08
View file https://github.com/sainikhiljuluri/python-sdk/blob/ed73cf36d771e14827872183dbe15fca8c0b81d7/tests/server/test_streamable_http_router.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3229/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-19d95b11a9e1249b7955143f91e9e2f482f5b09493dc88875c57b3ee08d58c08
https://github.com/modelcontextprotocol/python-sdk/pull/3229/files#diff-19d95b11a9e1249b7955143f91e9e2f482f5b09493dc88875c57b3ee08d58c08
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3229/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.