Blog

Custom Subdomains Match Exactly One Label, on Purpose

September 5, 2026Xerat022 min read
Share

Claim a slug and your mock also answers at <slug>.mockbase.org instead of only mockbase.org/mock/<id>. The routing behind that is a single Host-header check, and it's stricter than it might look — deliberately.

The check

MockBase reads the incoming Host header, strips any port, lowercases it, and checks that it ends with .<base_host>. Whatever's left after removing that suffix has to be a single label — one segment, no dots — for the match to count. demo.mockbase.org resolves; demo.staging.mockbase.org does not, even though it technically "ends with" the base host too. If subdomain routing is disabled entirely (no base host configured), the check short-circuits and nothing matches.

Only when a request's Host header cleanly decomposes into exactly <label>.<base_host> does MockBase look up which mock owns that label and route the request to it.

Why "exactly one label" is the actual security property

The naive version of this feature — "does the Host header contain our domain?" — is a substring check, and substring checks on hostnames are a classic way to accidentally let something like mockbase.org.attacker.com or an unexpected multi-level subdomain slip through logic that wasn't built to handle it. Requiring the leftover portion to be a single, dot-free label rules that class of mismatch out structurally: there's no substring matching involved at all, just "does the host end with this exact suffix, and is there exactly one label in front of it."

It also means slug claims can't collide in confusing ways. A slug is a single label, claimed by exactly one mock at a time — there's no ambiguity about whether foo.bar.mockbase.org belongs to the owner of foo or bar, because that host simply never matches the routing rule in the first place.

What it costs you

No nested subdomains, no wildcard slugs, no multi-level namespacing under your own slug. For a feature whose entire job is "give this one mock a memorable, stable address," that's the right trade — the routing stays a single unambiguous string comparison instead of a general-purpose hostname parser, which is exactly the kind of code you want to be boring.

X

Xerat02

Building MockBase.