Photo by FlyD on Unsplash

DNS Rebinding Attacks: When Browsers Trust the Wrong Answer


A DNS rebinding attack exploits the gap between how browsers enforce security boundaries and how DNS caching works. The attack allows a malicious website to bypass same-origin policy protections and make requests to services on a victim’s private network—all without the user installing anything or clicking suspicious links.

The Core Vulnerability

Browsers use the same-origin policy to prevent scripts from one domain from accessing data from another. Origin is determined by scheme, domain, and port. A script from attacker.com cannot read responses from 192.168.1.1 because they’re different origins.

DNS rebinding exploits a loophole in this model. The browser checks the origin when a script loads, but DNS resolution happens separately and can change over time. An attacker who controls both a domain and its authoritative nameserver can manipulate which IP address that domain resolves to, effectively changing the meaning of “origin” mid-session.

Attack Flow

The attacker registers evil.com and configures their nameserver to respond with very short TTL values—often zero or one second. When a victim visits evil.com, their browser resolves the domain to the attacker’s public server IP and loads malicious JavaScript.

That JavaScript then makes requests back to evil.com. But before those requests resolve, the attacker’s nameserver changes the DNS answer to point to a private IP address like 192.168.1.1 (the victim’s router) or 127.0.0.1 (the victim’s own machine). The browser’s DNS cache expires due to the short TTL, queries again, and receives the new answer.

Now the JavaScript is making authenticated requests to the private IP, but the browser still considers them same-origin with evil.com because the domain name hasn’t changed. The script can read responses, exfiltrate data, or issue commands to internal services that assume requests from the local network are trustworthy.

Why Private Networks Are Vulnerable

Many devices and services on private networks have weak or no authentication. A home router’s admin panel might only check that requests come from the LAN. Internal APIs at companies might assume the corporate network perimeter provides security. IoT devices often ship with default credentials or no authentication at all.

These services are invisible to the internet at large due to NAT and firewalls. But they’re fully accessible to the victim’s browser, which sits inside the trusted network. DNS rebinding transforms the browser into a confused deputy—a legitimate entity tricked into misusing its authority.

Defense Mechanisms

Modern browsers include partial mitigations. Chrome and Firefox refuse to resolve to certain private IP ranges when the originating page came from a public IP. But this protection is incomplete—it doesn’t cover all RFC1918 space, doesn’t block localhost, and can be bypassed using IPv6 or intermediate DNS servers.

Applications can defend themselves by validating the Host header in HTTP requests. If a service only expects to be accessed via IP address, it should reject requests with a hostname. DNS pinning—where the browser caches DNS results longer than the TTL suggests—provides some protection but breaks legitimate use cases.

The most robust defense is proper authentication. Services should never assume network location equals trust. Even internal tools should require authentication tokens, and those tokens should be HttpOnly cookies or bearer tokens that JavaScript cannot read.

Emerging Threats

DNS rebinding has gained renewed attention with the rise of local development servers and browser-based tooling. Tools like Webpack dev server, Jupyter notebooks, and language servers often bind to localhost with no authentication, assuming local access equals safety. An attacker can rebind to 127.0.0.1 and access these services as if they were the developer.

Web3 applications face similar risks. Cryptocurrency wallet browser extensions often communicate with local RPC nodes. If an attacker can rebind to the node’s port, they might read private keys or sign transactions on the user’s behalf.

Cloud metadata services present another target. AWS EC2 instances have access to 169.254.169.254 for retrieving credentials and configuration. While AWS now requires special headers or token-based authentication for sensitive endpoints, older applications might still be exploitable.

The Broader Pattern

DNS rebinding illustrates a recurring problem in security architecture: ambient authority. The browser assumes its network location grants it appropriate access to nearby resources. The same-origin policy tries to contain this authority, but DNS’s mutable nature creates a bypass.

This pattern appears elsewhere—cookies sent automatically based on domain, confused deputy problems in capability systems, and mobile apps assuming localhost means local control. The lesson is that security boundaries should be explicit and cryptographic, not implicit and topological. Trust should derive from presented credentials, not from network proximity or naming conventions.

DNS rebinding remains a relevant attack vector precisely because it exploits this architectural mismatch. As more services move to localhost-first architectures and edge computing blurs network boundaries, understanding these attacks becomes essential for building defensible systems.