Repository navigation
[Bugs] safe-fetch: redact logged URLs, cap drained bodies, exact 192.0 ranges - #1154
Conversation
…nges 192.0.0.0/16 was blocked where only 192.0.0.0/24 (IETF protocol assignments) and 192.0.2.0/24 (TEST-NET-1) are reserved. Rechecked the rest against the IANA IPv4/IPv6 special-purpose registries and added the missing non-globally-reachable entries: 192.88.99.0/24, 198.51.100.0/24, 203.0.113.0/24, 100:0:0:1::/64, 2001:2::/48, 2001:db8::/32, 3fff::/20, 5f00::/16.
Blocked-fetch log lines carried the full URL, which can leak presigned image tokens and credentials into hosted logs. The log now records only scheme, host and path; the error returned to the caller is unchanged.
…ning them res.resume() read redirect and error bodies to the end with no size cap. Those bodies are never used, so the response is destroyed (no keep-alive with agent: false) and zero bytes are read.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Aymericr
left a comment
There was a problem hiding this comment.
Maintainer review: looks good to me.
- The log redaction is right.
loggableUrldrops the query, userinfo and fragment, and the caller still gets the full URL in theProtocolError. res.destroy()on redirect and error responses is the right bound, sinceagent: falsemeans there's no keep-alive socket to keep.- I checked the new ranges against the IANA registries:
192.0.0.0/24,192.0.2.0/24,192.88.99.0/24,198.51.100.0/24,203.0.113.0/24,100:0:0:1::/64,2001:2::/48,2001:db8::/32,3fff::/20(theg1 & 0xf000mask is correct) and5f00::/16all match. Leaving AS112 and AMT allowed is correct too. - The tests cover each fix, and moving the public fixture off TEST-NET-3 makes sense.
One non-blocking thought: other code paths that log a ProtocolError's details would still print the full URL. That's out of scope here, but worth a quick check in a follow-up.
This changes SSRF guardrails, so under fleet rules Security has to approve it before merge. It also needs green CI, which is still running.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0405ca0701
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = await safeFetch('http://a.example/redirect', {}, deps) | ||
| expect(result.buffer.toString()).toBe('ok') | ||
| await expectBlocked(safeFetch('http://a.example/error', {}, deps), 'fetch_failed') | ||
| await new Promise((resolve) => setTimeout(resolve, 50)) |
There was a problem hiding this comment.
Remove the real-time sleep from this test
This unconditional 50 ms delay slows every suite run and directly violates repository testing rule T-001, which forbids real sleeps in tests. For these fake Readable instances, destroy() updates the inspected state synchronously, so the assertions can run immediately; if asynchronous behavior must be observed, wait for an explicit event or inject a controllable clock instead.
AGENTS.md reference: AGENTS.md:L5-L5
Useful? React with 👍 / 👎.
…ping T-001 forbids real sleeps. finished() settles immediately on destroy and only after a full 16 MB drain if the body were read, so the assertion stays deterministic.
What does this PR do?
Follow-up to #1122. It fixes the open bot findings on
packages/mcp/src/lib/safe-fetch.ts, the SSRF-safe fetch used by the hosted MCP photo and vision tools. There is one commit per fix:safe_fetch_blockedlog lines used to include the full URL. Now they record only the scheme, host and path (loggableUrl), so the query string (presigned image tokens), the userinfo and the fragment no longer reach hosted logs. TheProtocolErrorreturned to the caller still has the full URL, which the caller supplied in the first place.res.resume(), which had no size cap. They are nowres.destroy()ed, so zero bytes are read. Withagent: falsethere's no keep-alive socket to preserve. The response is a NodeIncomingMessage, so there's nores.bodyto cancel.192.0.x.xcheck blocked all of192.0.0.0/16. It now blocks only192.0.0.0/24(IETF protocol assignments) and192.0.2.0/24(TEST-NET-1). I also rechecked the other constants against the IANA IPv4/IPv6 special-purpose registries and added the entries that aren't globally reachable but were missing:192.88.99.0/24,198.51.100.0/24,203.0.113.0/24,100:0:0:1::/64,2001:2::/48,2001:db8::/32,3fff::/20and5f00::/16. Globally reachable entries (AS112, AMT and similar) stay allowed.Because
203.0.113.0/24is now blocked, the test suite's public IPv4 fixture moved from203.0.113.10to93.184.215.14.How to test
cd packages/mcp && bun test src/lib/safe-fetch.test.ts: all 34 tests pass.main'ssafe-fetch.ts:logs blocked URLs without query, fragment or userinfo: covers the host-blocked, scheme and origin-allowlist paths. The logged URL isscheme://host/path, with no token, password or fragment.never reads redirect or error bodies: a 16 MB 302 body and a 16 MB 500 body are destroyed, and 0 bytes are pulled from either.allows public addressesnow includes192.0.1.1,192.0.3.1and192.0.255.1. Theblocks …cases include192.0.0.1,192.0.2.1and the newly added ranges.bun run check,bun run skills:validate,bun run check-typesandbun run test. One unrelatedifc-convertertiming test (scaling > grows linearly…) failed once under parallel load and passed when re-run.Screenshots / screen recording
N/A — non-visual change
Checklist
bun devbun checkto verify)mainbranchNote
Medium Risk
Changes SSRF address policy and fetch behavior for hosted MCP image tools; mis-tuned ranges could block valid URLs or change what reaches internal networks, though the intent is stricter logging and tighter blocking.
Reviewed by Cursor Bugbot for commit 9119d02. Bugbot is set up for automated code reviews on this repo. Configure here.