Skip to content

[Bugs] safe-fetch/core: shared allowlist parser and hardening - #1161

Merged
Aymericr merged 3 commits into
mainfrom
cursor/core-normalise-asset-origins-5540
Oct 27, 2026
Merged

Aymericr merged 3 commits into
mainfrom
cursor/core-normalise-asset-origins-5540

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up to #1158. PASCAL_ALLOWED_ASSET_ORIGINS is now read one way by both consumers: the scene asset URL validator (packages/core/src/schema/asset-url.ts) and the MCP server's safeFetch (packages/mcp/src/lib/safe-fetch.ts).

  • One shared parser in core. parseAllowedOrigins and allowedOriginsFrom are exported from @pascal-app/core/schema.
    • Each entry is normalised to new URL(entry).origin, so a trailing slash, uppercase or :443 no longer stops a scene asset URL on that CDN from validating.
    • The parsed list is cached per value, and each rejected entry warns once.
    • Unset or empty means no allowlist. A whitespace-only or all-invalid value is an allowlist with no valid entries, so it admits nothing in both places. Before, core treated a whitespace-only value as unset.
    • safeFetch drops its own parser and uses this one. mcp already depends on @pascal-app/core/schema, so there's no new dependency edge, and the release workflow bumps the @pascal-app/core peer range in lockstep.
  • Malformed entries aren't logged raw. Rejected entries are reported as { index, reason }, with reason not_a_url or scheme_not_allowed, never by value. That way an entry like user:secret@host or ftp://user:secret@host can't put credentials in logs.
  • Only http: and https: entries count. Anything else is rejected with a warning. That includes blob:https://…, which would otherwise borrow an https origin.
  • The two DNS tests now catch their regressions.
    • The listener-cleanup test observes the abort listener at the moment safeFetch first reads each lookup's answer or error. It fails if the removal is missing or deferred to a later tick, as with the earlier .finally version.
    • The late-DNS test switches back to real timers and flushes a real event-loop turn before asserting there was no unhandled rejection, instead of counting microtasks.

How to test

  1. cd packages/core && bun test src/schema/asset-url.test.ts: 49 tests pass, including:
    • a GuideNode with a CDN URL validating under a https://cdn.pascal.app/, HTTPS://CDN.PASCAL.APP or https://cdn.pascal.app:443 entry;
    • whitespace-only and all-invalid allowlists;
    • one test each for blob:, ftp: and ws: entries;
    • index-and-reason reporting for credential-bearing entries.
  2. cd packages/mcp && bun test src/lib/safe-fetch.test.ts: 46 tests pass. I also broke untilAborted in four ways locally:
    • removing the listener removal fails the listener test;
    • deferring the removal to a .finally fails the listener test;
    • rethrowing a DNS failure that arrives after the timeout fails the late-DNS test;
    • dropping the race against the abort signal fails the late-DNS and timeout tests.
  3. Ran locally: bun run check, plus turbo run test check-types for @pascal-app/core, @pascal-app/mcp and editor.

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 security-sensitive origin allowlist semantics (including whitespace-only env) for both scene URLs and SSRF fetches; behavior is intentionally stricter and aligned across consumers.

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

parseAllowedOrigins reduces each entry to new URL(entry).origin, so a
trailing slash, uppercase or the default port no longer stop a scene
asset URL on that CDN from validating. Only http: and https: entries
count (blob:, ftp:, ws: and other schemes are rejected), and rejected
entries are reported by index and reason only, never by value, so a
credential in a malformed entry is not logged. allowedOriginsFrom caches
per value and warns once; a whitespace-only or all-invalid value admits
no https origin instead of being treated as unset.
safeFetch and the scene asset URL validator now read
PASCAL_ALLOWED_ASSET_ORIGINS the same way: one shared parser, one
warning per rejected entry (index and reason, never the entry text), and
a whitespace-only value blocks everything.
The listener test now observes the abort listener at the moment
safeFetch first reads each lookup's answer or error, so a missing or
deferred removal fails it. The late-DNS test flushes a real event-loop
turn (with real timers) before asserting no unhandled rejection, instead
of counting microtasks.
@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-27T01:00:33.811539Z 3527fb6 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 triage review: looks good to me, no blocking findings.

  • One parser for PASCAL_ALLOWED_ASSET_ORIGINS in core, reused by safeFetch, with origin normalisation. This removes the drift between the scene validator and the MCP fetch path.
  • Rejected entries are now logged by index and reason only, which fixes the old safe_fetch_allowlist_entry_ignored log that printed the raw entry (and any credentials in it).
  • Restricting entries to http:/https: closes the blob:https://… origin-borrowing case. An http: entry only has an effect in safeFetch, since core enforces the allowlist on https: URLs only. That's fine, just noting it.
  • Behaviour change worth calling out in release notes: a whitespace-only value used to mean "no allowlist" in core and now admits no https origin. That's the safer default and matches safeFetch.
  • mcp already depends on @pascal-app/core/schema, so no new dependency edge.

This changes SSRF/origin-allowlist behaviour, so per the fleet rule it needs Security's approval before merge. I've asked Security to review. I'll merge once CI is green and that approval is in. No screenshots needed, it's non-visual.

@Aymericr
Aymericr merged commit 4937ea9 into main Oct 27, 2026
5 checks passed

@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] Cross-review at 3527fb6

Approved at 3527fb6. All notes below are non-blocking.

CI at this head: ci ✅, quality ✅, cli-smoke ✅, Changed paths ✅, Cursor Bugbot ✅ (no findings). mergeable_state is clean. The earlier triage COMMENT review on this PR was posted at this same SHA.

Security approved at 3527fb6 (written). If the head moves, Security needs to re-check.

Parser vs. the old code (packages/core/src/schema/asset-url.ts:38-61)

I checked each case against the old core reader (exact string compare) and the old safeFetch parser (new URL(e).origin, skipping 'null').

  • Non-http(s) schemes (:54). ftp:, ws:, blob:https://…, javascript: and file: are now rejected with scheme_not_allowed. That tightens safeFetch, where blob:https://x used to grant https://x. In core it makes no practical difference.
  • Userinfo / credentials. This is a difference to know about.
    • A bare user:secret@host parses as the scheme user:, so it's rejected.
    • A full https://user:secret@cdn.example.com is accepted, with its origin reduced to https://cdn.example.com and the credentials dropped without any warning. The old safeFetch did the same. The old core never matched such an entry, so this is a widening in core.
    • The credentials are never sent or logged, so it isn't a leak. Still, a userinfo_ignored issue reported by index would tell the operator their entry isn't doing what they think.
  • Wildcards. No change: https://*.example.com is still accepted as a literal origin (* isn't a forbidden host code point), as before in both places. It never expands to subdomains, so it can't widen access. Rejecting * hosts with a reason would make the misconfiguration visible.
  • Paths, query and fragment. These are stripped to the origin: https://cdn.example.com/assets/ grants all of https://cdn.example.com. safeFetch did the same before. In core, such an entry used to match nothing, so it's a widening there, and path-scoped allowlisting was never supported in either place.
  • Ports. The default port is normalised (:443 for https, :80 for http), and other ports are kept (:8443 stays distinct). The :443 case is a widening in core, which used to match nothing, and is unchanged in safeFetch.
  • IP-literal entries (e.g. https://10.0.0.1) are accepted into the list, as before. In safeFetch they still can't reach a private host, because resolveCheckedAddresses blocks the address after the allowlist check (packages/mcp/src/lib/safe-fetch.ts:254-270). Being allowlisted only skips the port limit.

Both callers

Core (asset-url.ts:86-88, :106-108) and safeFetch (safe-fetch.ts:208-212) call the same allowedOriginsFrom with the same variable and module cache, so the parse is now identical. They differ only in where the list is enforced, and that's by design and pre-existing: core enforces it on https: asset URLs only, since http: there is limited to localhost (:100-104). safeFetch enforces it on http: and https:. So an http: entry only affects safeFetch.

Logs

Rejected entries are warned as {index, reason} only (asset-url.ts:75), and the empty-list warning has no value (:78). blocked() logs loggableUrl(url) and the request origin (safe-fetch.ts:182-191, :211), never an allowlist entry. The tests assert that secret/hunter2 doesn't appear in the warn or error output. No raw entry reaches the logs.

  • Nit: :78 says "no https: origin is permitted", but in safeFetch it blocks http: too.

Abort-listener cleanup (safe-fetch.ts:224-236, unchanged here)

The listener is removed synchronously inside settle before resolve/reject, and { once: true } removes it on abort. A late settle after an abort calls removeEventListener as a no-op, and the attached then handles the late rejection. There's no leak and no unhandled rejection. The strengthened test (safe-fetch.test.ts:653-722) observes the attached count at the first read of .address / .message and asserts [0, 0, 0]. That really would fail on a deferred .finally removal.

Late-DNS test (safe-fetch.test.ts:616-651)

Using real timers plus two setImmediate turns is a real improvement over counting microtasks, so the unhandled-rejection assertion now means something.

It does not exercise a rebinding, though. The late answer is PUBLIC_V4, and the test asserts that no request is made at all after the timeout. Rebinding is covered elsewhere, and unchanged: "pins the connection to the checked addresses even if DNS changes afterwards" (:245) and the real-socket pinnedLookup test (:725). Optional: make the late answer 127.0.0.1, so the test also shows that a late private answer can't be used.

Release notes: behavior changes

  1. A whitespace-only PASCAL_ALLOWED_ASSET_ORIGINS (e.g. " " or " , ") now means an allowlist with no entries in scene asset URL validation. It admits no https: asset URL, where it used to mean unset (any https: origin). safeFetch already behaved this way.
  2. Entries are normalised in scene asset validation. A trailing slash, uppercase, :443, a path, or userinfo in an entry now admits that origin, where before it matched nothing.
  3. Only http:/https: entries are honoured. blob:https://… and other schemes are ignored with a warning.
  4. The log line changed. [pascal-mcp] safe_fetch_allowlist_entry_ignored {"entry":…} is now [pascal] asset_allowlist_entry_ignored {"index":n,"reason":…}, so any log-based alert on the old name needs updating.

No merge from me.

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