Skip to content

[Bugs] safe-fetch: redact logged URLs, cap drained bodies, exact 192.0 ranges - #1154

Merged
Aymericr merged 4 commits into
mainfrom
cursor/safe-fetch-redact-cap-ranges-5540
Oct 27, 2026
Merged

Aymericr merged 4 commits into
mainfrom
cursor/safe-fetch-redact-cap-ranges-5540

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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:

  1. Redacted blocked-fetch logs. safe_fetch_blocked log 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. The ProtocolError returned to the caller still has the full URL, which the caller supplied in the first place.
  2. No unbounded body reads. Redirect and error responses used to be drained with res.resume(), which had no size cap. They are now res.destroy()ed, so zero bytes are read. With agent: false there's no keep-alive socket to preserve. The response is a Node IncomingMessage, so there's no res.body to cancel.
  3. Exact reserved ranges. The 192.0.x.x check blocked all of 192.0.0.0/16. It now blocks only 192.0.0.0/24 (IETF protocol assignments) and 192.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::/20 and 5f00::/16. Globally reachable entries (AS112, AMT and similar) stay allowed.

Because 203.0.113.0/24 is now blocked, the test suite's public IPv4 fixture moved from 203.0.113.10 to 93.184.215.14.

How to test

  1. cd packages/mcp && bun test src/lib/safe-fetch.test.ts: all 34 tests pass.
  2. New tests, each confirmed to fail against main's safe-fetch.ts:
    • logs blocked URLs without query, fragment or userinfo: covers the host-blocked, scheme and origin-allowlist paths. The logged URL is scheme://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 addresses now includes 192.0.1.1, 192.0.3.1 and 192.0.255.1. The blocks … cases include 192.0.0.1, 192.0.2.1 and the newly added ranges.
  3. Ran locally: bun run check, bun run skills:validate, bun run check-types and bun run test. One unrelated ifc-converter timing test (scaling > grows linearly…) failed once under parallel load and passed when re-run.

Screenshots / screen recording

N/A — non-visual change

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch
Open in Web Open in Cursor 

Note

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.

…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.
@Aymericr Aymericr added the bot:bugs label Oct 26, 2026 — with Cursor
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T23:59:27.685057Z 0405ca0 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review: looks good to me.

  • The log redaction is right. loggableUrl drops the query, userinfo and fragment, and the caller still gets the full URL in the ProtocolError.
  • res.destroy() on redirect and error responses is the right bound, since agent: false means 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 (the g1 & 0xf000 mask is correct) and 5f00::/16 all 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/mcp/src/lib/safe-fetch.test.ts Outdated
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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.
@Aymericr
Aymericr merged commit f177d72 into main Oct 27, 2026
5 checks passed
@Aymericr
Aymericr deleted the cursor/safe-fetch-redact-cap-ranges-5540 branch October 27, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants