On-ramp · Lesson 05
A name is not an address, and the answer can change
A gateway checks that the host in a tool's URL is on the allow-list, files.acme.example, and lets the call through. The tool service then looks the name up and gets an internal address, because the name's record was changed an hour ago. The check was correct about the name and said nothing about where the connection went.
What DNS answers
A client asks a resolver: "what are the addresses for this name?" The resolver walks the hierarchy or answers from cache and returns records (RFC 1035, 1987). The ones you need:
| Record | Meaning | Example |
|---|---|---|
A |
the name's IPv4 addresses | files.acme.example. 300 IN A 203.0.113.7 |
AAAA |
its IPv6 addresses | ... AAAA 2001:db8::7 |
CNAME |
this name is an alias for another | docs.acme.example. CNAME acme.github.example. |
The number is the TTL, in seconds: how long a cache may keep the answer. A name may have several addresses, and a program picks one or tries them in turn:
import socket
print(socket.getaddrinfo("localhost", 80, proto=socket.IPPROTO_TCP)[:2])
# [(AF_INET6, ..., ('::1', 80, 0, 0)), (AF_INET, ..., ('127.0.0.1', 80))]
One name, two addresses, one of them IPv6. A check that looks only at the IPv4 one has checked half of it.
Three consequences for a control
- A name is checked, an address is connected. The two steps are separate lookups, and the answer can differ between them (DNS rebinding: a record with a TTL of a few seconds, answered as the allowed public address to the check and as an internal address to the connection). The only sound design resolves once, checks the address, and connects to that address with the name carried in the
Hostheader and TLS server name. Module 12 lesson 7 builds exactly that. - Where the name came from matters. A CNAME chain can lead from an allowed name to a name its owner does not control. Allow-listing a name is trusting everyone who can edit its zone and every zone it aliases into.
- Special address ranges are special. Loopback (
127.0.0.0/8,::1), private (10/8,172.16/12,192.168/16), link-local (169.254/16) and the cloud metadata address are never a legitimate destination for an agent talking to the outside world.
Reading an address as a number
http://2130706433/ and http://0x7f.1/ both mean 127.0.0.1 to many URL parsers and to inet_aton, and neither looks like an IP. The rule from lesson 1 applies: compare what you will connect to, in one canonical form, produced by the parser that will connect.
Expert: caches, split horizons and what you cannot see
Resolvers cache (and a stub resolver in your container caches again), so a TTL of 30 seconds is an upper bound on how long that resolver keeps an answer, not on how long your process does: a connection pool may hold an address for hours. Split-horizon DNS gives inside and outside clients different answers for one name, so "what does this name resolve to?" has no single answer without saying from where. DNS over HTTPS (RFC 8484) moves the lookup into an HTTPS connection to a resolver of the application's choice, which takes it out of the network's view and out of its egress rules.
Check yourself
files.acme.examplehas two records,A 203.0.113.7andAAAA ::1. A gateway resolves the name, checks only its IPv4 address and then lets the HTTP library connect to the name. Where can the connection go, and what must the gateway do instead?- Why can "block private addresses" at the gateway still be bypassed by a name under an allowed domain?
- What does a TTL of 0 do for the attacker's version of the attack, and what does it do for a legitimate operator who wants to move a service?
Answers
- To
::1, loopback on the machine that connects: the library gets both addresses and may try the IPv6 one first, asgetaddrinfolisted::1first forlocalhost. The check passed203.0.113.7and never saw the loopback address. The gateway must check every address the name returns, refuse the name if any is special, and connect to the address it checked rather than hand the name back to the library. - The block applies to addresses, and a name-based check never sees the address the tool connects to. Whoever controls the allowed domain's zone, or any zone it aliases into through a CNAME, can point a name at
10.0.0.5or the metadata address. Only a gateway that resolves the name itself, checks that address and connects to it closes the gap. - For the attacker, TTL 0 tells caches not to keep the answer, so each lookup returns to the attacker's server and the check and the connection a moment later can get different addresses. For the operator it makes a move take effect almost at once, at the cost of a lookup per connection, and only for clients that honour it: a connection pool may hold the old address for hours.