Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 6 min read

Why fetch(webhookUrl) Is a Trap: SSRF and DNS Rebinding in a Self-Hosted PaaS

Sooner or later, a self-hosted control plane has to make outbound requests to URLs provided by its users. A team configures a Discord or custom webhook for alerts. Someone enters an S3-compatible endpoint for nightly ba

Sooner or later, a self-hosted control plane has to make outbound requests to URLs provided by its users.

A team configures a Discord or custom webhook for alerts. Someone enters an S3-compatible endpoint for nightly backups. Another user pastes a Git repository URL or connects a cloud sync target.

The naive implementation fits on one line:

await fetch(userProvidedUrl, { method: "POST", body });

The problem is where that request runs.

It runs inside the management panelβ€”on a machine that often has access to 127.0.0.1, internal Docker networks, private VPN interfaces, local databases, or cloud provider metadata endpoints at 169.254.169.254.

If a user supplies a URL and the panel blindly calls fetch(), that user may be able to turn the control plane into a proxy into the server's private network.

This is the problem behind outbound SSRF guards and pinned HTTP in Nitrobase.

Nitrobase has only recently launched and is still in Beta. These guards do not eliminate every risk of running third-party workloads on a VPS. Their narrower job is to keep user-supplied outbound URLs from quietly reaching internal addresses unless private-network access is explicitly enabled.

Why string checks and startsWith("127.") break immediately

The first instinct when guarding URLs is usually a quick string check:

// Fragile: misses mapped, encoded, and alternate IP representations
if (host === "localhost" || host.startsWith("127.") || host.startsWith("192.168.")) {
  throw new Error("blocked");
}

Text matching misses how operating systems and network stacks actually parse IP addresses.

Consider how many ways an address can still reach loopback or link-local metadata:

  • localhost. with a trailing dot, or sub.localhost;
  • IPv4-mapped IPv6 such as [::ffff:127.0.0.1] or [::ffff:169.254.169.254];
  • SIIT translation addresses like [::ffff:0:127.0.0.1];
  • IPv4-compatible IPv6 notation ([::127.0.0.1]);
  • NAT64 (64:ff9b::/96) and 6to4 (2002::/16) encodings with embedded IPv4 bits;
  • CGNAT space (100.64.0.0/10), 0.0.0.0/8 ("this network"), and IPv6 unique-local (fc00::/7) or link-local (fe80::/10).

Instead of matching text patterns, Nitrobase parses IPv4 strings into four bytes and expands IPv6 stringsβ€”including :: compression, embedded IPv4 tails, and %zone IDsβ€”into eight 16-bit hextets. Any embedded IPv4 address inside a transition format is extracted and evaluated against the blocked IPv4 CIDR ranges too.

User hostname string
        |
        v
Normalize brackets, trailing dot, zone ID
        |
        +--> Parse IPv4 bytes -----> check private/CGNAT/metadata CIDRs
        |
        +--> Parse IPv6 hextets ---> unwrap mapped/NAT64/6to4 IPv4 ---> check CIDRs

Parsing addresses rather than regexing strings closes an entire class of trivial bypasses before any DNS query even happens.

Checking the URL at save time is not enough

Even when every literal IP range is covered, a hostname introduces a timing gap:

Time 0 (Save webhook):    evil.example.com  ──DNS──►  93.184.216.34 (public: allowed)

Time 1 (Send alert):      evil.example.com  ──DNS──►  127.0.0.1     (private: danger!)

This is DNS rebinding.

An attacker controls the domain's authoritative nameserver with a short TTL. When Nitrobase validates the webhook or S3 endpoint during configuration save, DNS returns a normal public IP. Later, when a backup job or notification fires, DNS returns 127.0.0.1 or 169.254.169.254.

A similar trap happens with rotating DNS records: a single domain configured with two A recordsβ€”one public, one internal. If validation checks only addresses[0], the connection phase might pick addresses[1].

Nitrobase handles this in two stages:

Stage Purpose What it checks
Save time Fast feedback in the UI Rejects private literals, unresolved hosts, and any DNS answer containing a private IP
Send / connect time Prevents TOCTOU & rebinding Resolves fresh, rejects if any address is private, and pins the connection to one checked IP

An endpoint that returns a mix of public and private DNS records is rejected entirely when private networking is off.

Pinning the socketβ€”and why runtimes complicate it

Resolving a hostname once in application code does not automatically stop the HTTP client from resolving it a second time when opening the TCP socket.

Naive check-then-fetch:
  1. dns.lookup(host)  -> 93.184.216.34 (ok!)
  2. fetch(url)        -> OS calls dns.lookup(host) AGAIN -> 127.0.0.1 (rebound!)

Nitrobase's outbound HTTP client avoids fetch() for user-influenced hosts and instead uses node:http / node:https with three strict settings:

  1. Custom lookup callback (pinnedLookup): Forces the socket to connect strictly to the single pre-verified IP address instead of querying DNS again.
  2. No connection pooling (agent: false): Ensures a fresh socket check per request so stale pooled connections cannot linger across configuration changes.
  3. Socket peer verification on connect: Inspects socket.remoteAddress as soon as the TCP connection establishes.

That third check exists because of a subtle cross-runtime reality: alternative JavaScript runtimes (such as Bun's Node compatibility layer) do not always honor a custom lookup option the same way Node doesβ€”some runtimes still perform their own resolution internally.

Verifying the actual connected socket.remoteAddress catches a rebind even if the underlying socket layer bypassed pinnedLookup, tearing down the socket immediately before HTTP data is exchanged:

resolvePinned(host) -> 93.184.216.34 (verified public)
        |
        v
http.request(..., { lookup: pinnedLookup, agent: false })
        |
        v
on socket connect -> check socket.remoteAddress
        |
        +-- matches public IP  --> send request
        +-- private / empty    --> request.destroy("blocked")

Redirects and plain HTTP are part of the same boundary

Stopping DNS rebinding at the first hop does little good if the remote server can reply with a redirect:

HTTP/1.1 302 Found
Location: http://169.254.169.254/latest/meta-data/iam/security-credentials/

Standard HTTP clients like fetch() follow redirects automatically by default (redirect: "follow"). Each hop silently exits your SSRF validation unless every redirect target is re-validated through the same pipeline.

Nitrobase treats redirects on guarded outbound requests as explicit failures rather than hops to chase:

  • No auto-redirects: Using http.request / https.request means 3xx responses are returned directly and classified as a non-retryable redirect rejection.
  • HTTPS by default: Plain http:// URLs are blocked unless the user has explicitly enabled the private network option for an internal self-hosted endpoint.
  • Capped response reading: Even a valid remote server can attempt to exhaust panel memory by streaming gigabytes back. Nitrobase bounds response reads (maxResponseBytes)β€”either truncating diagnostic bodies at 64 KiB for webhooks or aborting oversized cloud-sync downloads cleanly.

Where Nitrobase applies this boundary

SSRF protection only works if every user-supplied outbound surface uses it consistently, not just webhooks:

  • Notification webhooks & chat channels: Discord, Slack, Telegram, custom signed webhooks, and SMTP hosts.
  • Backup destinations & cloud sync: Custom S3-compatible endpoints, Cloudflare R2, Backblaze B2, and Appwrite/external sync providers.
  • Git repository clones: Even Git URLs resolve the host first via resolveGitHost(), refusing hostnames that mix public and private records and rejecting non-standard credential smuggling in repository URLs.

At the same time, a self-hosted PaaS often genuinely needs to talk to an internal MinIO instance on a private VLAN or a local Gitea server over VPN.

That is why Nitrobase makes allowPrivate an explicit, per-destination setting rather than disabling checks globally. Public endpoints stay guarded; intentional internal endpoints are clearly marked as private-network connections.

What SSRF guards still do not protect against

An outbound HTTP guard narrows what a panel user can make the control plane fetch. It is not a full egress firewall.

It does not restrict what arbitrary application containers deployed on a managed VPS request from inside their own Docker networks, nor does it make an untrusted webhook endpoint safe if an administrator purposefully enables private-network mode on it. Network segmentation on the host remains the real outer perimeter.

My outbound URL checklist

Before calling an external URL from a control plane or API backend, these are the checks I want to answer:

  • [ ] Are IPv4-mapped IPv6, NAT64, 6to4, and CGNAT ranges parsed numerically rather than regexed?
  • [ ] Does validation reject hostnames whose DNS answers mix public and private IPs?
  • [ ] Is the resolved IP pinned at connect time instead of performing a second DNS lookup inside fetch()?
  • [ ] Does the socket connect listener re-verify socket.remoteAddress against private ranges?
  • [ ] Are HTTP 3xx redirects blocked instead of silently followed?
  • [ ] Is plain http:// refused for public endpoints?
  • [ ] Is the response body capped in bytes alongside a strict request timeout?
  • [ ] Is private-network access opt-in per configuration instead of an invisible fallback?

A single fetch(url) hides every single one of those decisions behind convenience. Replacing it with a pinned client turns an implicit network risk into explicit infrastructure code.

Nitrobase source code: https://github.com/AydenGroup/nitrobase

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.