Skip to content

[Bugs] safe-fetch: IPv6 special ranges, DNS abort, log trimming - #1157

Merged
Aymericr merged 4 commits into
mainfrom
cursor/safe-fetch-ipv6-dns-abort-log-trim-5540
Oct 27, 2026
Merged

Aymericr merged 4 commits into
mainfrom
cursor/safe-fetch-ipv6-dns-abort-log-trim-5540

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up to #1154 for packages/mcp/src/lib/safe-fetch.ts, with one commit per finding:

  • IPv6 2001::/23. Blocks the whole IETF protocol assignments block. Before this, only Teredo (2001::/32) and benchmarking (2001:2::/48) were blocked. The entries IANA lists as globally reachable stay allowed: 2001:1::1–2001:1::3, 2001:3::/32, 2001:4:112::/48, 2001:20::/28 and 2001:30::/28.
  • DNS abort. The DNS lookup now races the fetch's abort signal, which the timeout fires. dns.lookup can't be cancelled, so before this a resolver that never answered kept the fetch open past timeoutMs. It now fails as fetch_timeout and never sends a request.
  • Ports. Only ports 80 and 443 (or the scheme's default port) are fetched, so a public host's other services can't be reached through the image fetch. An origin listed in PASCAL_ALLOWED_ASSET_ORIGINS may still name any port, since the operator has trusted it explicitly. The rejection reason is url_port_not_allowed.
  • Log trimming. loggableUrl caps the logged path at 128 characters. Blocked non-http(s) URLs such as data: and javascript: carry their payload in the path, so they now log only the scheme and host (for example data: or ftp://a.example).

How to test

  1. cd packages/mcp && bun test src/lib/safe-fetch.test.ts: all 38 tests pass.
  2. These tests fail against main's safe-fetch.ts:
    • blocks IETF protocol assignments 2001::/23
    • a DNS lookup that never answers still times out: uses Bun fake timers with a resolver that never settles.
    • only web ports are fetched unless the origin is allowlisted
    • truncates long logged paths and logs only scheme and host for other schemes
    • the updated logs blocked URLs without query, fragment or userinfo
  3. allows public addresses now also covers the 2001::/23 exceptions and 2001:200::1, the first address past the block.
  4. Ran locally: Biome on the changed files, plus turbo run test check-types --filter=@pascal-app/mcp.

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

High Risk
Changes security-critical URL fetch validation for user-supplied image URLs; stricter port and IPv6 rules may block previously allowed asset URLs unless allowlisted.

Reviewed by Cursor Bugbot for commit bb56dd8. Bugbot is set up for automated code reviews on this repo. Configure here.

The IETF protocol assignments block was only partly covered (Teredo and
benchmarking). The whole /23 is now blocked, except 2001:1::1-3,
2001:3::/32, 2001:4:112::/48, 2001:20::/28 and 2001:30::/28, which IANA
lists as globally reachable.
… a path

Blocked-fetch logs now cap the path at 128 characters. data: and
javascript: URLs carry their payload in the path, so blocked non-http(s)
schemes log only scheme and host.
…lowlisted

A public host's other services (SSH, Redis, admin ports) are no longer
reachable through the image fetch. An origin listed in
PASCAL_ALLOWED_ASSET_ORIGINS may still name any port.
dns.lookup cannot be cancelled, so a resolver that never answered held
the fetch past its timeout. The lookup now races the fetch's abort
signal and fails as fetch_timeout.
@Aymericr Aymericr added the bot:bugs label Oct 27, 2026 — with Cursor
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T00:23:24.991264Z bb56dd8 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 2001::/23 carve-outs match the IANA special-purpose registry (2001:1::1–3 anycast, 2001:3::/32 AMT, 2001:4:112::/48 AS112, 2001:20::/28 ORCHIDv2, 2001:30::/28 drone remote ID), and the tests cover both edges, including 2001:200::1 just past the block.
  • Racing the DNS lookup against the abort signal is the right fix, since dns.lookup can't be cancelled. Rethrowing on signal.aborted keeps it reported as fetch_timeout rather than dns_lookup_failed.
  • The port check runs in assertAllowedUrl, so redirect hops are covered too, and allowlisted origins can still use any port.
  • Log trimming for data:/javascript: URLs is a nice cleanup.

No visual change, so screenshots aren't needed. This is SSRF hardening, so I'm asking Security to approve it. It can merge once CI is green and that approval is in.

@Aymericr
Aymericr merged commit 90b8545 into main Oct 27, 2026
5 checks passed
@Aymericr
Aymericr deleted the cursor/safe-fetch-ipv6-dns-abort-log-trim-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