Repository navigation
Conversation
|
@shaikn6 is attempting to deploy a commit to the Comp AI - PoC Team on Vercel. A member of the Team first needs to authorize it. |
shaikn6
force-pushed
the
fix/safe-fetch-dns-pin
branch
from
November 15, 2026 17:51
8e14111 to
a40484c
Compare
shaikn6
marked this pull request as draft
November 15, 2026 17:52
resolvesToPublicHost resolved the hostname and checked the addresses, then fetch resolved the hostname again at connect time. A name that passed the public check could resolve to a private or metadata address on the second lookup, so safeFetch could still connect to an internal host. safeFetch now resolves the host once and issues the request through node:http/node:https with a pinned lookup that returns only those vetted addresses, and a servername so TLS still validates against the hostname. The check runs again on every redirect hop. This works on both Node and Bun (Bun's fetch ignores a dispatcher, so no undici dependency is used). Adds a test for the public-host guard and the safeFetch refusals.
shaikn6
force-pushed
the
fix/safe-fetch-dns-pin
branch
from
November 15, 2026 18:23
a40484c to
c636f8b
Compare
shaikn6
marked this pull request as ready for review
November 15, 2026 18:24
Comp Review ·
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use case
I run the CRM self-hosted. The agent and tracking fetch external URLs through
safeFetch. I wantsafeFetchto stop an SSRF reaching internal or cloud-metadata hosts, including when DNS answers change between the check and the connect.Problem
safeFetchresolves the host inresolvesToPublicHost, checks every address is public, then callsfetch.fetchresolves the host again at connect time. A name that passes the public check resolves to a private or metadata address on the second lookup, andsafeFetchconnects to the internal host. This is a DNS-rebinding TOCTOU. Severity: Medium. Three callers take an attacker-controlled URL (tracked site inapps/api/src/tracking/tracking.service.ts, MCP OAuth metadata inpackages/auth/src/mcp-oauth.ts, company domain via favicon/blob),http:is allowed, and favicon/blob persist the bytes.Fix
safeFetchresolves the host once and issues the request throughnode:http/node:httpswith a pinnedlookupthat returns only those vetted addresses.fetchis no longer used, so there is no second resolution. Forhttpsit setsservernameto the hostname, so SNI and certificate validation still run against the hostname while the socket goes to a vetted IP. The public-address check runs again on every redirect hop. A latent bug is fixed too: the lookup honorsoptions.all.No new dependency. An earlier revision used an
undicidispatcher, but Bun'sfetchignores thedispatcher, so the dispatcher approach was inert in this repo's runtime.node:http/node:httpswith a pinnedlookupworks on both.Validation
cd packages/db && bun test test/safe-fetch.spec.ts test/favicon.spec.ts-> 9 pass, 0 fail.tsc --noEmiton the file is clean.bun 1.3.14andnode v26:safeFetch("https://example.com/")returns 200 and a 577-byte body over a pinned IP;safeFetchto a loopback literal returns null; a non-http scheme returns null.node:https.requestwith a pinnedlookup+servernamewas confirmed to connect to the pinned IP and still validate the certificate against the hostname on both runtimes.Issues