Skip to content

check: treat unknown related hosts as external unless they are this site - #16

Merged
oxyc merged 1 commit into
masterfrom
feat/unknown-subdomains-external
Nov 30, 2026
Merged

oxyc merged 1 commit into
masterfrom
feat/unknown-subdomains-external

Conversation

@oxyc

@oxyc oxyc commented Nov 30, 2026

Copy link
Copy Markdown
Member

check used to refuse (exit 2) when a page had 5 or more references to a host at or under the canonical's apex that the map doesn't name, and it told you to add that host as an alias. That's a false positive on sites that link to a separate app on their own domain, such as identity.example.com or a docs site on another server. It also blocks unattended tooling that runs init after a db pull. Following the advice would make things worse, because it rewrites the app's links onto the local site.

Change

  • Probe before refusing (ddev/commands/host/hostshift, hs_probe_related). Each related unknown host gets bounded requests: 5 s each, at most two same-host redirect hops, never followed onto another host, and the redirect target is read from curl's redirect_url rather than fetched. The host counts as this site if its root redirects to a hostname the map names, or if https://<host>/wp-json/ reports a home or url the map names. In that case check refuses as before, with the evidence added to the message.
  • Otherwise the host is treated as external. That covers another app, another WordPress, a non-WordPress site and a timeout. check prints a note and carries on. If the host can't be reached, the note says "could not reach it; treated as external". The note still points at the alias remedy in case the host really is this site, and names external:.
  • external: per site in hostshift.yaml (internal/config/config.go). Listed hosts are skipped with no probe and no note. Entries can be bare hosts or URLs. Each one is normalised, and the file is refused if a host is also a canonical, base, alias or variant of any site. Typos are still caught by KnownFields. hostshift map --external-hosts prints the list for the add-on.
  • The rules in the earlier comments are unchanged: strip only one www., skip localhost/.test/.ddev.site.

Compatibility

The proxy image reads hostshift.yaml too. A CLI or image released before this key rejects external: as an unknown field. The README says to add it only once both are on a release that includes it. An older CLI on the host just prints nothing for --external-hosts, so every related host gets probed.

Tests

  • test/addon-command.sh: the fake curl gets a per-host seam (HS_CURL_RELATED=host=redirect:<url>|wp:<home>|app|down). New cells cover: an external app gives a note and exit 0, another WordPress gives a note, an unreachable host gives a note, a redirect to the canonical gives a refusal, a /wp-json/ home equal to the canonical gives a refusal, and a host listed in external: stays silent and is never fetched. The existing refusal cells now declare that their host is this site.
  • internal/config: TestExternalHosts covers normalisation and dedupe, the alias/external conflict, the conflict with another site's canonical, a non-hostname entry, and a misspelled key.
  • Local: make test-addon all passed (including the poisoned-curl check), go test ./... ok, go vet clean, gofmt -l clean.

🤖 Generated with Claude Code

A host at or under the canonical's apex that the map does not name made
check exit 2 and advise adding it as an alias. On sites that link to a
separate app on their own domain (a login app, a docs site) that refusal
blocked unattended init after a db pull, and the alias remedy would have
rewritten the app's links onto the local site.

check now asks the host first, with bounded requests: it is this site if
its root redirects to a hostname the map names, or its /wp-json/ index
reports such a home or url. Only then does it refuse as before. Anything
else prints a note (saying so explicitly when the host is unreachable)
and continues.

hostshift.yaml gains an optional per-site external: list that skips the
probe and the note. It is validated like the other keys, and a host can't
be both external and a hostname the map names. map --external-hosts
prints it for the add-on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oxyc
oxyc merged commit 1784884 into master Nov 30, 2026
7 of 8 checks passed
@oxyc
oxyc deleted the feat/unknown-subdomains-external branch November 30, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant