Skip to content

[Bugs] safe-fetch: allowlist normalisation and edge-case tests - #1158

Merged
Aymericr merged 2 commits into
mainfrom
cursor/safe-fetch-allowlist-normalise-5540
Oct 27, 2026
Merged

Aymericr merged 2 commits into
mainfrom
cursor/safe-fetch-allowlist-normalise-5540

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Small follow-up to #1157 for packages/mcp/src/lib/safe-fetch.ts.

  • Doc: the PASCAL_ALLOWED_ASSET_ORIGINS line in the module doc now says that listed origins skip the port limit.
  • Allowlist normalisation: each entry is reduced to new URL(entry).origin. So entries written with the default port (:443), in uppercase, with a trailing slash or with a path still match.
    • Entries without an origin (cdn.example.com, cdn.example.com:443, not a url) are skipped with one safe_fetch_allowlist_entry_ignored warning each. The parsed list is cached per raw value, so a bad entry doesn't warn on every fetch.
    • An allowlist with no valid entry still blocks everything (fail closed).
  • Edge-case tests:
    • A DNS answer or failure that arrives after the timeout: the fetch still fails as fetch_timeout, no request is sent, and there's no unhandled rejection.
    • The abort listener is removed once each lookup settles, on success, redirect and DNS failure. untilAborted now removes it before passing the result on, instead of in a later .finally tick, so the cleanup happens right away.
    • A redirect hop to a forbidden port is blocked before its host is resolved.
    • https://host:80 is treated as a web port and keeps the explicit port.
    • Allowlist near-misses are rejected: suffix host, prefix host, truncated host, a different port and a different scheme. An allowlisted :8443 origin doesn't admit the default port.

How to test

  1. cd packages/mcp && bun test src/lib/safe-fetch.test.ts: all 46 tests pass.
  2. With main's safe-fetch.ts, the two normalisation tests fail. The other new tests cover behaviour that was already correct, so they pass on main too.
  3. 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

Medium Risk
Changes SSRF URL allowlist parsing and DNS timeout wiring in MCP vision fetches; behavior is more permissive for correctly formatted allowlist entries but still fail-closed on invalid config.

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

Each entry is reduced to new URL(entry).origin, so entries written with
the default port, in uppercase, with a trailing slash or a path still
match. Entries without an origin are skipped with one warning each; an
allowlist with no valid entry still blocks everything. The doc now says
listed origins skip the port limit. Tests cover normalisation, invalid
entries and near-miss origins (prefix and suffix hosts, port, scheme).
…p and ports

Covers a DNS answer or failure that arrives after the timeout, removal
of the abort listener once each lookup settles, a redirect hop to a
forbidden port, and https on port 80. The abort listener is now removed
before the lookup's result is passed on rather than in a later tick.
@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:42:26.283406Z 1fdfdf1 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.

  • Normalising each allowlist entry with new URL(entry).origin is the right call. Bare hosts and host:port entries come out as an opaque null origin, so skipping them with a warning is correct, and an allowlist with only bad entries still fails closed.
  • Caching the parsed list per raw env value keeps the warning to once per bad entry without hiding a changed env value.
  • Removing the abort listener inside the settle handlers, instead of in a later .finally tick, is a tidy fix, and the listener-count test pins it down.
  • The near-miss tests (suffix, prefix, truncated host, other port, other scheme) and the late-DNS-after-timeout test are good coverage for an SSRF guard.

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

@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: 1fdfdf1078

ℹ️ 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".

if (!trimmed) continue
let origin = 'null'
try {
origin = new URL(trimmed).origin

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize the shared allowlist consistently

When an operator uses one of the newly supported forms—such as https://cdn.example.com/, uppercase, a path, or an explicit default port—safeFetch now accepts the origin, but packages/core/src/schema/asset-url.ts still compares PASCAL_ALLOWED_ASSET_ORIGINS entries as raw strings. Consequently, an MCP save_scene containing an item or material URL from that same CDN is rejected during AnyNode validation even though vision fetches accept it. Normalize this shared environment setting in core as well, or centralize the parsing so both consumers enforce the same contract.

Useful? React with 👍 / 👎.

@Aymericr
Aymericr merged commit 2171388 into main Oct 27, 2026
5 checks passed
@Aymericr
Aymericr deleted the cursor/safe-fetch-allowlist-normalise-5540 branch October 27, 2026 12:19
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