Share some knowledge, skills and others — security research, pentesting notes and more.

← Home

19 November 2026

DNS Rebinding: When a Domain Name Becomes a Tunnel into Your LAN

by allencharp

The One-Line Version

The attacker owns a domain, points it at their server just long enough to plant some JavaScript, then quietly repoints the same name at 127.0.0.1. The browser still thinks it is talking to the site you opened, so the script can read services that were never meant to be reachable from the internet.

The whole trick rests on one mismatch: the browser’s security guard reads names, while the network follows addresses.

Same-Origin Policy Reads Names, Not Addresses

Same-Origin Policy (SOP) decides “same site” by comparing scheme, host and port. The IP that actually answered is not in the tuple — that omission is what rebinding exploits.

One Name, Two Answers

The attacker controls the authoritative DNS for evil.com, so they decide what IP it resolves to — and can change it at will with a near-zero TTL.

One domain name, two DNS answers

  1. Victim opens http://evil.com → attacker’s server → malicious JS loads. Origin recorded: http://evil.com.
  2. TTL expires. The script requests http://evil.com/admin again; the answer is now 127.0.0.1.
  3. The hostname is still evil.com, so the browser treats it as same-origin and lets the script read the response — which came from a local service.

Why the Browser Allows the Read

The script never asks for 127.0.0.1 — it always fetches evil.com. The address change happens a layer below, in DNS.

Why the browser allows the response

The origin check compares two strings (http://evil.com vs http://evil.com). They match, so it passes. That DNS resolved the second one to loopback is invisible to the check. The guard authorises a name; the network follows an address. The gap is the vulnerability.

Where the Attacker’s DNS Comes From

Most people resolve through 8.8.8.8. But that is a recursive resolver — a runner, not an authority. It walks root → .com → the authoritative server for evil.com, whose NS records were set by the attacker when they registered the domain. You never bypass 8.8.8.8; the rules simply lead to the domain owner, who says whatever they like. TTL=0 keeps those answers from being cached, so the second lookup picks up the changed IP.

What It Buys the Attacker

Not browser cookies — the victim’s browser becomes a hand reaching into places only the victim can reach: local admin panels on 127.0.0.1:8080, the home router, internal Redis / Docker API / Elasticsearch, cloud metadata at 169.254.169.254. These are often unauthenticated precisely because someone decided they were “internal only”. Rebinding is the browser-side cousin of SSRF.

Defense: One Central Layer, One Real Layer

The target is not just 127.0.0.1 — a name can be rebound to any address the victim’s browser can reach: localhost, the home router, internal servers, cloud metadata. Every unauthenticated service reachable from a browser is a candidate. You do not fix that by hardening each one blindly; two layers cover it.

Central mitigation — the internal DNS resolver. Refuse any answer where a public domain resolves into a private range (127/8, 10/8, 172.16/12, 192.168/16, 169.254/16). One rule covers every target above — this is the “rebinding protection” switch in Pi-hole and enterprise gateways. Moving DNS onto the internal network is not the fix; adding this rule is. Browser-side DNS pinning and Private Network Access preflight help too, but have been bypassed before — treat them as a third layer, not the control.

The real fix — make each service refuse strangers. Rebinding can change the IP behind a name, but it cannot change the Host header: the script fetched http://evil.com/admin, so the service receives Host: evil.com even though the connection came from the victim’s own machine. Reject hosts you do not recognise:

server {
    listen 8080 default_server;      # match the service's actual port
    return 403;                       # unmatched Host → deny
}
server {
    listen 8080;
    server_name localhost 127.0.0.1 internal.example.local;
    ...
}

Two traps in those lines. First, the default_server block with return 403 must exist and be explicit — if no server is marked default, Nginx silently uses the first block for unmatched hosts, and if that is your real service you have blocked nothing. Second, the listen port must match the service; correct logic on the wrong port protects nothing. Note that server_name matching ignores the port, so Host: localhost:8080 still matches server_name localhost.

Self-check — a normal page instead of 403 means the service trusts whatever Host it is handed:

curl -H "Host: evil.com" http://127.0.0.1:8080/admin -i

Origin helps on writes, Sec-Fetch-Site does not. During rebinding the browser considers the request same-origin, so Sec-Fetch-Site arrives as same-origin — it cannot detect this attack and is a CSRF control, not a rebinding one. Origin carries http://evil.com on POST-like requests and can be allowlisted, but safe GETs send no Origin at all. Neither replaces Host validation.

Authentication is the more general fix. Even if a rebound request reaches the service, a login or token stops the read. Most internal services are hit precisely because someone decided “it is on the LAN, no auth needed”. Bind dev servers to 127.0.0.1, authenticate internal admin interfaces, require IMDSv2 for cloud metadata.

The audit question: do not ask “what IP is it bound to” — ask “can a cross-origin request from evil.com read anything here?” If it needs a session, rebinding fails. If it answers unauthenticated, it needs fixing. Any trust check that lives inside the code it checks is defeatable — the trust anchor belongs on the server.

Rebinding Is Not Replay

Technique What changes Whom it fools Fix
Rebinding domain stays, answer swapped browser — “same origin” Host validation, auth, DNS filter, PNA
Replay nothing — old valid message resent “this is fresh” nonce, timestamp, DNSSEC
Cache poisoning a forged answer injected resolver — “genuine” ID/port randomisation, DNSSEC

Replay is the locker-code trick: watch someone enter 9527, enter it again later — it works only when old codes are never invalidated. Rebinding changes no content, only which machine the name points to.

Testing It

For authorised testing only: Singularity of Origin (1.2.3.4, by nccgroup) automates the setup. Pair it with Burp to check whether the target validates Host and Origin — that check tells you whether the finding is real.

One Sentence to Remember

Rebinding wins because the browser authorises a name while the network follows an address — so the durable fix is to stop trusting the name at the service boundary, not to make the name behave.

tags: web-security - dns - same-origin-policy - rebinding - ssrf