Repository navigation
fix: enforce SSRF destination policy on convert_uri HTTP(S) fetches - #2621
FailSafe (failsafesecurity) wants to merge 1 commit into
Conversation
Caller-supplied HTTP(S) URIs were forwarded to requests with no destination allowlist, no timeout and default redirect following, letting the unauthenticated markitdown-mcp convert_to_markdown tool reach loopback, private ranges and cloud metadata endpoints and return their bodies. - Reject loopback, link-local (incl. 169.254.169.254), RFC1918, IPv6 ULA/link-local, reserved and otherwise non-globally-routable destinations; non-public targets require an explicit allow_private_networks opt-in that the MCP server does not set. - Handle redirects manually and re-validate the destination policy on every hop (requests no longer follows redirects itself). - Apply an explicit finite connect/read timeout to every request. - Add regression tests covering internal/redirect/opt-in behavior. Finding: SSRF: unauthenticated MCP convert_to_markdown fetches arbitrary internal URIs without destination policy or timeout
|
FailSafe (@failsafesecurity) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
XU (kokokoXUY)
left a comment
There was a problem hiding this comment.
Verified the destination policy over real sockets instead of mocks. Loopback, localhost, link-local (including 169.254.169.254), RFC1918, 0.0.0.0, [::1] and [::ffff:127.0.0.1] are refused with the new message; every outbound GET carries allow_redirects=False and timeout=(10, 30); a relative redirect and a five-hop chain resolve through _fetch_http; a redirect to file: is rejected by scheme; an endless loop ends with Too many redirects (more than 5); and the opt-in flag restores loopback access. test_convert_uri_ssrf.py passes here (15 passed), and the patch applies cleanly to current main (git apply --check).
The remaining gap is on the path the threat model cares about. _validate_fetch_destination inspects the addresses returned by one getaddrinfo call, but the socket is opened later, and the connection path resolves the host again. With a resolver that answers 93.184.216.34 for the validation lookup and 127.0.0.1 for the connection lookup, convert_uri returned the internal server body: markdown='INTERNAL-SECRET-TOKEN-42'. A hostname the caller controls, or an attacker domain with a short TTL, therefore still reaches internal services. Connecting to a validated address, or re-checking the peer with socket.getpeername() after connect, would close that.
Two smaller items. A 302 with no Location header comes back as a closed response, and the failure surfaces later as UnsupportedFormatException: Could not convert stream to Markdown, which reads as a format problem rather than a redirect problem. And the CLI has no opt-in, so markitdown http://127.0.0.1:8080/page now exits 1 with an unhandled ValueError traceback where current main converted it (exit 0); a --allow-private-networks flag, or catching ValueError in __main__.main(), would keep local-server conversions usable.
One scope note for the SSRF description: file: still reaches convert_uri by design (the MCP tool advertises it), so an unauthenticated MCP client can read local files even with network egress closed. That is not a regression from this change, but the two are worth stating together. I also ran the MCP-side test from the stacked #2622 against this head: 7 passed.
本 repo 已停用 issues,接續開發報告依規定寫在本 commit 訊息。 # 接續開發報告 2026-10-25 ## 一、線索與處理 - open/draft PR:無。PR #1 已關閉未合併,內容已 squash 進 main(bebd625), head 分支 ci/job-names-20261024 已不在遠端。 - 非預設分支:只有 claude/gifted-dirac-r9vpm0(本 session 工作分支,內容已 fast-forward 進 main)。 - open issue:無(issues 已停用)。 - main 紅燈 Dependency freshness:ruff 0.17.2。對 E9+F gate 全綠,記入 .github/dependency-deferrals.json(deferredLatest),未調高下限 → 已轉綠。 - main 紅燈 Upstream check:20 commit/153 PR/40 issue 未審 → 第三輪審查完成,已轉綠。 - HANDOFF.md/TODO.md:不存在。程式碼 TODO/FIXME 7 處皆為上游產品碼,不動。 - REVIEW.md:R-01~R-10 已修,無未修項。 - 2026-09-30 待辦 microsoft#2506:觸發條件成立(上游整併測試依賴它),已採用(4a377f9)。 ## 二、做了什麼(bebd625..本 commit) - 上游 commit:cherry-pick -x 本輪 20 筆中 19 筆(9a15f66..e211f83),microsoft#2731 部分採用(3e440d7), 補採 microsoft#2506(4a377f9)。 - 例外移植上游 OPEN PR,皆先重現缺陷、附 PR 測試: - microsoft#2674(1029094):短 UTF-8 文字被誤判 UTF-16 亂碼。 - microsoft#2742(9947ed1):UTF-8 BOM 殘留。 - microsoft#2738(38a2ae6):Outlook MSG 尾端 NUL。 - microsoft#2620(0d1140c):大寫副檔名音訊不轉譯。 - 依賴(c561006): - requirements 跟隨上游 magika/mammoth/certifi,補列 ocr 漏的 PyMuPDF、Pillow。 - dependabot 補 ocr 與 sample-plugin 目錄。 - ruff 延後。 - 文件(8f1db57、3382745、b618bc9、本 commit): - microsoft#1913 英文段落併入 README.en.md。 - 繁中 README text_content → markdown。 - DECISIONS/UPSTREAM/baseline 推進水位。 - CI(d4c2b7a):移除 microsoft#2586 帶進 tests.yml 的 Linux 專用 apt-get 步驟(R-09)。 - 驗證: - 每批推送前由全新審查員審 diff 並等 Windows CI 完成(一次 NO-SHIP,修正後重審 ship)。 - 維護 gate 與 Windows CI py3.10–3.14 全綠。 - 產品測試(Linux 雲端)1312 passed/12 skipped/2 failed,2 個失敗皆因沙箱無對外網路。 ## 三、上游結論 - 水位:commit 7482c09、PR microsoft#2765、issue microsoft#2762。 - commit:採用 18、部分採用 1(microsoft#2731 ARM/pre-commit CI 不適用),microsoft#2733 版本 bump 不適用。 - PR: - MERGED 12,例外移植 4。 - 其餘 OPEN 不 fork-ahead,等上游合併。 - 無 merge ref 12 筆多為重複,不採。 - issue:已修 2(microsoft#2646、microsoft#2719),16 筆對應 OPEN PR,其餘為不適用、觸發條件或垃圾。 - 逐筆見 docs/DECISIONS.md 2026-10-25。 ## 四、刻意不做(理由/觸發條件) - microsoft#2756 ZIP 檔名:會把 Big5「臺灣報告.pdf」解成亂碼(誤判為 shift_jis_2004)。 觸發:上游合併時先補 cp950 測試,或改為優先 metadata_encoding/locale。 - microsoft#2621/microsoft#2622 SSRF 政策:牽動 MCP/URI 擷取。 觸發:上游合併,或本 fork 對外提供 MCP HTTP 服務。 - microsoft#2679/microsoft#2723 cp1252 偵測:可能影響 CJK 舊碼頁。觸發:上游合併後跑 CJK charset 測試。 - microsoft#2407 youtube-transcript-api ~=1.2.3:維持本 fork >=1.0.0+freshness-hold。 - microsoft#2740 Python 3.15:上游 CI 加 3.15 時同步 ci.yml。 ## 五、需要維護者決定 1. 雲端 session 對 microsoft/markitdown 無 API 權限(只能匿名 git 讀取)。 本輪 PR/issue 清單取自本 fork Upstream check log,狀態以 refs/pull/*/merge 判斷。 2. 產品程式變動只在 Linux 跑過;ci.yml 只跑維護 gate。請在 Windows 11 本機跑 pwsh -NoProfile -File tools\test_product.ps1 -AllPackages。 3. 「不 fork-ahead」政策的 4 筆例外移植;若不同意可 revert 1029094、9947ed1、38a2ae6、0d1140c。 STATUS: NEEDS-MAINTAINER Windows 11 本機跑 test_product.ps1 -AllPackages;確認是否接受 4 筆上游 open PR 例外移植 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014CWBckUdMZcCAsc15iaJtm
本 repo 已停用 issues,接續開發報告依規定寫在本 commit 訊息。 # 接續開發報告 2026-10-25 ## 一、線索與處理 - open/draft PR:無。PR #1 已關閉未合併,內容已 squash 進 main(bebd625), head 分支 ci/job-names-20261024 已不在遠端。 - 非預設分支:只有 claude/gifted-dirac-r9vpm0(本 session 工作分支,內容已 fast-forward 進 main)。 - open issue:無(issues 已停用)。 - main 紅燈 Dependency freshness:ruff 0.17.2。對 E9+F gate 全綠,記入 .github/dependency-deferrals.json(deferredLatest),未調高下限 → 已轉綠。 - main 紅燈 Upstream check:20 commit/153 PR/40 issue 未審 → 第三輪審查完成,已轉綠。 - HANDOFF.md/TODO.md:不存在。程式碼 TODO/FIXME 7 處皆為上游產品碼,不動。 - REVIEW.md:R-01~R-10 已修,無未修項。 - 2026-09-30 待辦 microsoft#2506:觸發條件成立(上游整併測試依賴它),已採用(4a377f9)。 ## 二、做了什麼(bebd625..本 commit) - 上游 commit:cherry-pick -x 本輪 20 筆中 19 筆(9a15f66..e211f83),microsoft#2731 部分採用(3e440d7), 補採 microsoft#2506(4a377f9)。 - 例外移植上游 OPEN PR,皆先重現缺陷、附 PR 測試: - microsoft#2674(1029094):短 UTF-8 文字被誤判 UTF-16 亂碼。 - microsoft#2742(9947ed1):UTF-8 BOM 殘留。 - microsoft#2738(38a2ae6):Outlook MSG 尾端 NUL。 - microsoft#2620(0d1140c):大寫副檔名音訊不轉譯。 - 依賴(c561006): - requirements 跟隨上游 magika/mammoth/certifi,補列 ocr 漏的 PyMuPDF、Pillow。 - dependabot 補 ocr 與 sample-plugin 目錄。 - ruff 延後。 - 文件(8f1db57、3382745、b618bc9、本 commit): - microsoft#1913 英文段落併入 README.en.md。 - 繁中 README text_content → markdown。 - DECISIONS/UPSTREAM/baseline 推進水位。 - CI(d4c2b7a):移除 microsoft#2586 帶進 tests.yml 的 Linux 專用 apt-get 步驟(R-09)。 - 驗證: - 每批推送前由全新審查員審 diff 並等 Windows CI 完成(一次 NO-SHIP,修正後重審 ship)。 - 維護 gate 與 Windows CI py3.10–3.14 全綠。 - 產品測試(Linux 雲端)1312 passed/12 skipped/2 failed,2 個失敗皆因沙箱無對外網路。 ## 三、上游結論 - 水位:commit 7482c09、PR microsoft#2765、issue microsoft#2762。 - commit:採用 18、部分採用 1(microsoft#2731 ARM/pre-commit CI 不適用),microsoft#2733 版本 bump 不適用。 - PR: - MERGED 12,例外移植 4。 - 其餘 OPEN 不 fork-ahead,等上游合併。 - 無 merge ref 12 筆多為重複,不採。 - issue:已修 2(microsoft#2646、microsoft#2719),16 筆對應 OPEN PR,其餘為不適用、觸發條件或垃圾。 - 逐筆見 docs/DECISIONS.md 2026-10-25。 ## 四、刻意不做(理由/觸發條件) - microsoft#2756 ZIP 檔名:會把 Big5「臺灣報告.pdf」解成亂碼(誤判為 shift_jis_2004)。 觸發:上游合併時先補 cp950 測試,或改為優先 metadata_encoding/locale。 - microsoft#2621/microsoft#2622 SSRF 政策:牽動 MCP/URI 擷取。 觸發:上游合併,或本 fork 對外提供 MCP HTTP 服務。 - microsoft#2679/microsoft#2723 cp1252 偵測:可能影響 CJK 舊碼頁。觸發:上游合併後跑 CJK charset 測試。 - microsoft#2407 youtube-transcript-api ~=1.2.3:維持本 fork >=1.0.0+freshness-hold。 - microsoft#2740 Python 3.15:上游 CI 加 3.15 時同步 ci.yml。 ## 五、需要維護者決定 1. 雲端 session 對 microsoft/markitdown 無 API 權限(只能匿名 git 讀取)。 本輪 PR/issue 清單取自本 fork Upstream check log,狀態以 refs/pull/*/merge 判斷。 2. 產品程式變動只在 Linux 跑過;ci.yml 只跑維護 gate。請在 Windows 11 本機跑 pwsh -NoProfile -File tools\test_product.ps1 -AllPackages。 3. 「不 fork-ahead」政策的 4 筆例外移植;若不同意可 revert 1029094、9947ed1、38a2ae6、0d1140c。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014CWBckUdMZcCAsc15iaJtm STATUS: NEEDS-MAINTAINER Windows 11 本機跑 test_product.ps1 -AllPackages;確認是否接受 4 筆上游 open PR 例外移植
Summary
MarkItDown.convert_uriforwarded caller-supplied HTTP(S) URIs directly torequestswith no destination allowlist, no timeout, and default redirectfollowing. The unauthenticated
markitdown-mcpconvert_to_markdowntoolinherits this behavior, so any client that can reach the MCP endpoint can make
the server fetch loopback, RFC1918/link-local, and cloud metadata addresses
(e.g.
169.254.169.254) and receive their response bodies verbatim.Finding
cmuvhxvzs01pxs001oe795svlPoC summary
A caller invokes the MCP tool with
uri=http://169.254.169.254/latest/meta-data/iam/security-credentials/(or
http://127.0.0.1:<port>/…, or an attacker-controlled open redirect). Thestock
requests.Sessioncreated atMarkItDown.__init__performs the requestwith no policy, follows redirects blindly (so a pre-fetch check on the original
URI alone would be insufficient), and applies no timeout, allowing credential
exfiltration and worker pinning.
Fix
In
packages/markitdown/src/markitdown/_markitdown.py:_validate_fetch_destination()resolves the targethost and rejects loopback, link-local (including the cloud metadata address),
RFC1918/private, IPv6 ULA/link-local, reserved, and other non-globally-routable
addresses. Non-public destinations require an explicit
allow_private_networksopt-in that the MCP server does not set.
_fetch_http()setsallow_redirects=Falseand followsredirects manually, re-applying the full destination policy on every hop, so an
open redirect cannot pivot into the internal network.
timeout.
markitdown-mcpalready mapsValueErrorfromconvert_urito a tool error, sothe unauthenticated tool inherits the policy with no bypass.
Tests
packages/markitdown/tests/test_convert_uri_ssrf.py(15 tests) covers rejection ofinternal targets and non-HTTP schemes, the opt-in override, that no socket is
opened for an internal target, that an explicit timeout is sent, and that a
redirect to an internal host is refused on the hop.
All tests pass locally (
pytest packages/markitdown/tests/test_convert_uri_ssrf.py).