Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

Two traps in a domain checker: a blank WHOIS line and a fake TLD

Two bugs in DomainHunter share one trait: neither crashes. The WHOIS bug would quietly send a query to a "host" that is not a host, and the DNS bug would tell you that example.notatld is available to register. Both come from reading a response a little too optimistically. Both are guarded by a few lines in availability.py, and both guards come with a comment that names the trap.

Project
DomainHunter
Date
Sep 2026
Stack
Python, WHOIS, DNS over HTTPS
Commit
8c24558

A word on sources first. The repository is a single commit, 8c24558 (Sep 2026), so there is no history of when I met these problems. What I can show is the code as it stands and the reasoning I left in its comments.

What broke

For extensions without RDAP, DomainHunter falls back to WHOIS on port 43. WHOIS has no directory of servers built in, so the tool first asks IANA's WHOIS server, whois.iana.org, who is responsible for the extension. IANA replies with a block of text, and one line of it is whois: followed by the host name.

For some extensions, .ga among them, that line is blank. The field name is there and the value is not. A regex written the natural way, with \s* after the colon to skip spaces, treats the newline as whitespace too. It steps over the end of the line and happily captures whatever comes next, which is the name of the next field. The result is a "WHOIS host" that is really the next line's label.

I reran this idea on a constructed sample, not a real IANA reply: a whois: line with nothing after it, followed by a status: line. A pattern with \s* after the colon returns status: as its capture. That is the failure the comment in the code describes.

The second trap lives in the DNS fallback, the last-resort source for registries that publish neither RDAP nor WHOIS. A name that does not exist in DNS returns NXDOMAIN, and the tool reads NXDOMAIN as "free". That is reasonable for a real extension. For an extension that does not exist at all, such as one with a typo, DNS also returns NXDOMAIN, and the tool would report a name you cannot register as available.

What the code showed

The WHOIS host discovery in whois_host reads:

python
# \s* would run across the newline and swallow the next field name
# for TLDs whose whois: line is blank (.ga and friends).
m = re.search(r"^whois:[^\S\r\n]*(\S+)[^\S\r\n]*$", text, re.M | re.I)
if m and "." in m.group(1):
    host = m.group(1)

[^\S\r\n] reads as "not a non-whitespace character, and not a carriage return or newline", which is whitespace excluding line breaks: spaces and tabs only. On a blank whois: line the pattern sees the end of the line, cannot match a host, and returns nothing. The extra test "." in m.group(1) is a second guard. A real host name has a dot, and a stray field label such as status: does not.

The DNS side is in root_zone() and dns():

python
tld = domain.rsplit(".", 1)[-1]
root = self.root_zone()
if root and tld not in root:
    return Result(domain, UNKNOWN, "dns", f".{tld} is not a real tld")

root_zone() downloads IANA's list of every real top-level domain from data.iana.org/TLD/tlds-alpha-by-domain.txt, lowercases it into a set, and caches it for the run. The docstring spells out the reason: without it, a name under a non-existent extension returns NXDOMAIN and would be reported free.

  1. 01

    Take the extension

    the part after the last dot of the name

  2. 02

    Load the root zone

    IANA's list of real TLDs, fetched once and cached

  3. 03

    Check membership

    an extension not in the list gives unknown, not free

  4. 04

    Ask DNS

    only then DoH queries, NXDOMAIN means free, delegated means taken

Figure 1. What the DNS check does before it trusts NXDOMAIN.

The check order matters here as well. check asks RDAP, then WHOIS, then DNS, and DNS only runs when both of the others returned unknown. A typo extension would fall through RDAP (no server), through WHOIS (no WHOIS host for the extension) and land on DNS. That is where the root zone check catches it. I reasoned that path from the code and did not trace it on a live run.

The fix

Both guards ship in 8c24558, so there is no diff to compare. I can still describe what each one prevents:

  • The regex change stops a blank whois: line from yielding a wrong host. When no valid host is found, whois_host returns None and whois reports "no whois server for tld", an unknown that the next source can take over.
  • The root zone check turns a would-be "free" for a fake extension into unknown, with a detail that says what is wrong: ".xyzzy is not a real tld".

In both cases the answer degrades to unknown, which in this tool is a legitimate result and not a failure. That is the design rule from the case study: if nobody answered, say so.

What I would do differently

Two things in the code are softer than I would like. First, root_zone() returns an empty set when the IANA download fails, and the guard is written if root and tld not in root. An empty set is falsy, so when the download fails the typo check silently turns itself off. For a tool whose rule is "never guess", that fails open. I would make a failed download produce unknown for DNS results, not a skipped check.

Second, whois_host stores the result in a cache even when the lookup raised an error, so a temporary network failure would pin None for that extension for the rest of the run. A cache should remember answers, not errors.

And both guards deserve a test with the real shapes: a blank whois: block and a made-up extension. They are the kind of code a later refactor can break without any visible symptom.

Where this fits

These two checks are small, but they decide whether a tool that says "available" can be trusted. The full DomainHunter case study shows how RDAP, WHOIS and DNS fit together, and how the same never-guess rule shapes the pricing side.

Read `whois_host` and `dns` in `availability.py` to see both guards and the comments that explain them.

View the code on GitHub

#python#whois#dns#regex#domains

Keep reading

Have a project in mind?