Repository navigation
[Bugs] safe-fetch: allowlist normalisation and edge-case tests - #1158
Conversation
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.
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 review: looks good to me.
- Normalising each allowlist entry with
new URL(entry).originis the right call. Bare hosts andhost:portentries come out as an opaquenullorigin, 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
.finallytick, 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.
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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 👍 / 👎.
What does this PR do?
Small follow-up to #1157 for
packages/mcp/src/lib/safe-fetch.ts.PASCAL_ALLOWED_ASSET_ORIGINSline in the module doc now says that listed origins skip the port limit.new URL(entry).origin. So entries written with the default port (:443), in uppercase, with a trailing slash or with a path still match.cdn.example.com,cdn.example.com:443,not a url) are skipped with onesafe_fetch_allowlist_entry_ignoredwarning each. The parsed list is cached per raw value, so a bad entry doesn't warn on every fetch.fetch_timeout, no request is sent, and there's no unhandled rejection.untilAbortednow removes it before passing the result on, instead of in a later.finallytick, so the cleanup happens right away.https://host:80is treated as a web port and keeps the explicit port.:8443origin doesn't admit the default port.How to test
cd packages/mcp && bun test src/lib/safe-fetch.test.ts: all 46 tests pass.main'ssafe-fetch.ts, the two normalisation tests fail. The other new tests cover behaviour that was already correct, so they pass onmaintoo.turbo run test check-types --filter=@pascal-app/mcp.Screenshots / screen recording
N/A — non-visual change
Checklist
bun devbun checkto verify)mainbranchNote
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.