Repository navigation
[Bugs] safe-fetch/core: shared allowlist parser and hardening - #1161
Conversation
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.
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 triage review: looks good to me, no blocking findings.
- One parser for
PASCAL_ALLOWED_ASSET_ORIGINSin core, reused bysafeFetch, 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_ignoredlog that printed the raw entry (and any credentials in it). - Restricting entries to
http:/https:closes theblob:https://…origin-borrowing case. Anhttp:entry only has an effect insafeFetch, since core enforces the allowlist onhttps: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. mcpalready 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
left a comment
There was a problem hiding this comment.
[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:andfile:are now rejected withscheme_not_allowed. That tightenssafeFetch, whereblob:https://xused to granthttps://x. In core it makes no practical difference. - Userinfo / credentials. This is a difference to know about.
- A bare
user:secret@hostparses as the schemeuser:, so it's rejected. - A full
https://user:secret@cdn.example.comis accepted, with its origin reduced tohttps://cdn.example.comand the credentials dropped without any warning. The oldsafeFetchdid 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_ignoredissue reported by index would tell the operator their entry isn't doing what they think.
- A bare
- Wildcards. No change:
https://*.example.comis 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 ofhttps://cdn.example.com.safeFetchdid 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 (
:443for https,:80for http), and other ports are kept (:8443stays distinct). The:443case is a widening in core, which used to match nothing, and is unchanged insafeFetch. - IP-literal entries (e.g.
https://10.0.0.1) are accepted into the list, as before. InsafeFetchthey still can't reach a private host, becauseresolveCheckedAddressesblocks 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:
:78says "no https: origin is permitted", but insafeFetchit blockshttp: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
- A whitespace-only
PASCAL_ALLOWED_ASSET_ORIGINS(e.g." "or" , ") now means an allowlist with no entries in scene asset URL validation. It admits nohttps:asset URL, where it used to mean unset (anyhttps:origin).safeFetchalready behaved this way. - 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. - Only
http:/https:entries are honoured.blob:https://…and other schemes are ignored with a warning. - 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.
What does this PR do?
Follow-up to #1158.
PASCAL_ALLOWED_ASSET_ORIGINSis now read one way by both consumers: the scene asset URL validator (packages/core/src/schema/asset-url.ts) and the MCP server'ssafeFetch(packages/mcp/src/lib/safe-fetch.ts).parseAllowedOriginsandallowedOriginsFromare exported from@pascal-app/core/schema.new URL(entry).origin, so a trailing slash, uppercase or:443no longer stops a scene asset URL on that CDN from validating.safeFetchdrops its own parser and uses this one.mcpalready depends on@pascal-app/core/schema, so there's no new dependency edge, and the release workflow bumps the@pascal-app/corepeer range in lockstep.{ index, reason }, with reasonnot_a_urlorscheme_not_allowed, never by value. That way an entry likeuser:secret@hostorftp://user:secret@hostcan't put credentials in logs.http:andhttps:entries count. Anything else is rejected with a warning. That includesblob:https://…, which would otherwise borrow an https origin.safeFetchfirst reads each lookup's answer or error. It fails if the removal is missing or deferred to a later tick, as with the earlier.finallyversion.How to test
cd packages/core && bun test src/schema/asset-url.test.ts: 49 tests pass, including:GuideNodewith a CDN URL validating under ahttps://cdn.pascal.app/,HTTPS://CDN.PASCAL.APPorhttps://cdn.pascal.app:443entry;blob:,ftp:andws:entries;cd packages/mcp && bun test src/lib/safe-fetch.test.ts: 46 tests pass. I also brokeuntilAbortedin four ways locally:.finallyfails the listener test;bun run check, plusturbo run test check-typesfor@pascal-app/core,@pascal-app/mcpandeditor.Screenshots / screen recording
N/A — non-visual change
Checklist
bun devbun checkto verify)mainbranchNote
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.