From dceb38aeb71d0bc0b2ce01d086a04240f30e89b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Mon, 30 Nov 2026 10:19:17 -0300 Subject: [PATCH] check: treat unknown related hosts as external unless they are this site 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 --- README.md | 29 ++++++++ cmd/hostshift/main.go | 10 +++ ddev/commands/host/hostshift | 128 ++++++++++++++++++++++++++++++--- internal/config/config.go | 69 ++++++++++++++++-- internal/config/config_test.go | 74 +++++++++++++++++++ test/addon-command.sh | 104 +++++++++++++++++++++++++++ 6 files changed, 397 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1ddfcf4..f15f4a7 100644 --- a/README.md +++ b/README.md @@ -485,6 +485,35 @@ carries `HOSTSHIFT_ARGS=--slug wt-a` and nothing more: the file is mounted into the container and the proxy reads it directly, which it must, since a flat canonical=variant list cannot carry aliases. +**Hostnames on the page that the map does not name.** `check` counts every +absolute-URL host in the pages it probes. A host with five or more references +that sits at or under a canonical's apex (the canonical minus one leading +`www.`) is either an alias the file forgot, which would leave live production +links in a preview, or a separate application on the client's domain: a login +app, a docs site. `check` asks the host which one it is, with one bounded +request each way (5 s, at most two same-host redirect hops, never followed off +the host). It is **this site** if its root redirects to a hostname the map +names, or if its `/wp-json/` index reports a `home` or `url` the map names. +Then `check` refuses and tells you to add it as an alias. Anything else (another +app, another WordPress, no answer) is treated as external: `check` prints a +note saying so, or that it could not reach the host, and carries on. + +To skip that request and the note, list the host under the site's `external:`. +Its links are left alone either way; `external:` only makes that explicit and +offline. A host can't be both an alias and external, and the file is refused if +it is listed as both: + +```yaml + - name: main + canonical: https://www.example.com + base: https://acme.ddev.site + external: [identity.example.com, docs.example.com] +``` + +`hostshift map --external-hosts` prints the list. The proxy reads this file +too, and a CLI or proxy image released before this key rejects it as an unknown +field. Add `external:` only once both are on a release that has it. + ### Production-canonical — only for a pristine dump The same engine pointed further: set `canonical` to the live production diff --git a/cmd/hostshift/main.go b/cmd/hostshift/main.go index 54c5aad..1c26325 100644 --- a/cmd/hostshift/main.go +++ b/cmd/hostshift/main.go @@ -669,6 +669,8 @@ func cmdMap(args []string) (int, error) { canon := fs.Bool("canonical-hosts", false, "emit every canonical-side hostname, aliases included, one per line") ext := fs.Bool("external-canonical-hosts", false, "emit the canonical hostnames that are not this project's own, one per line") + external := fs.Bool("external-hosts", false, + "emit the hostnames hostshift.yaml declares `external:`, one per line") if describe(fs, args, "print the resolved map, and where it came from") { return exitOK, nil } @@ -709,6 +711,14 @@ func cmdMap(args []string) (int, error) { } return exitOK, nil } + // Hosts under the site's domain that are someone else's application. The + // add-on's `check` skips them instead of probing whether they are this site. + if *external { + for _, h := range res.External { + fmt.Println(h) + } + return exitOK, nil + } if *pairs || *hosts { for _, s := range res.Map.Sites { if *pairs { diff --git a/ddev/commands/host/hostshift b/ddev/commands/host/hostshift index 44c3570..2e2322d 100755 --- a/ddev/commands/host/hostshift +++ b/ddev/commands/host/hostshift @@ -2702,10 +2702,87 @@ $extra_body" others="$(printf '%s' "$probe_body" | hostshift origins 2>/dev/null || true)" known_hosts=",$(printf '%s,%s,%s,' "$canon_list" "$variants" "${DDEV_HOSTNAME:-}" \ | tr -s ',' ',')," + # What hostshift.yaml says outright. `external:` hosts are someone else's + # application and are skipped without a probe or a note. The file's whole + # canonical side — aliases included, which a `--holds` flat map leaves out + # of $canon_list — is what a probe below may find a host redirecting to. + # From the file itself, not "${map_args[@]}": under --holds those are + # --from/--to, which carry neither. An older CLI without --external-hosts + # prints nothing here, and every related host is then probed as before. + external_hosts="," + site_hosts="$known_hosts" + if [ -f hostshift.yaml ]; then + external_hosts=",$(hostshift map --slug "$slug" --external-hosts 2>/dev/null \ + | paste -sd, - || true)," + site_hosts="$site_hosts$(hostshift map --slug "$slug" --canonical-hosts 2>/dev/null \ + | paste -sd, - || true)," + fi + + # hs_probe_related asks a related host whether it is this WordPress, with + # one cheap look each way: does its root redirect to a hostname this map + # names, and does its /wp-json/ index report a home or url this map names. + # Sets hs_verdict to "site" (with hs_evidence), "unreachable" or "external". + # + # This is an outbound request to the live host, from this machine — the + # thing hs_fetch_local refuses to do by following redirects. It is bounded + # instead: two requests plus at most two same-host redirect hops, 5 s each, + # GETs only, and never followed onto another host. The redirect target is + # read from curl's `redirect_url`, not fetched. + # + # Why ask at all: a host under the canonical's apex is not necessarily this + # site. A customer login app, a docs site or an auction app on another + # server is the ordinary case, and the alias remedy below is actively wrong + # for it — it rewrites the links to that app onto the local site. + hs_probe_related() { + hs_verdict="external"; hs_evidence="" + _purl="https://$1/"; _phop=0 + while :; do + _rc=0 + _pout="$(curl -sk --noproxy '*' --connect-timeout 3 --max-time 5 \ + -o /dev/null -w '%{http_code} %{redirect_url}' "$_purl" 2>/dev/null)" || _rc=$? + _pout="$(printf '%s\n' "$_pout" | sed -n '$p')" + _pcode="${_pout%% *}" + _ploc="" + case "$_pout" in *" "*) _ploc="${_pout#* }" ;; esac + if [ "$_rc" != 0 ] || [ "$_pcode" = 000 ] || [ -z "$_pcode" ]; then + # The root, not a later hop: a host that answered once is reachable. + if [ "$_phop" = 0 ]; then hs_verdict="unreachable"; return 0; fi + break + fi + case "$_pcode" in 30*) ;; *) break ;; esac + [ -n "$_ploc" ] || break + _plh="${_ploc#*://}"; _plh="${_plh%%/*}"; _plh="${_plh%%:*}" + case "$site_hosts" in + *",$_plh,"*) + hs_verdict="site" + hs_evidence="https://$1/ redirects to $_ploc" + return 0 ;; + esac + # Same host, another path (`/` to `/en/`): follow, a little. + [ "$_plh" = "$1" ] && [ "$_phop" -lt 2 ] || break + _phop=$((_phop + 1)) + _purl="$_ploc" + done + _pjson="$(curl -sk --noproxy '*' --connect-timeout 3 --max-time 5 \ + "https://$1/wp-json/" 2>/dev/null || true)" + for _pv in $(printf '%s' "$_pjson" \ + | grep -oE '"(home|url)"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null \ + | sed -e 's/^[^:]*:[[:space:]]*"//' -e 's/"$//' -e 's|\\/|/|g' || true); do + _pvh="${_pv#*://}"; _pvh="${_pvh%%/*}"; _pvh="${_pvh%%:*}" + case "$site_hosts" in + *",$_pvh,"*) + hs_verdict="site" + hs_evidence="https://$1/wp-json/ is a WordPress whose home is $_pv" + return 0 ;; + esac + done + } + while read -r cnt host; do [ -n "${host:-}" ] || continue [ "${cnt:-0}" -ge 5 ] 2>/dev/null || continue case "$known_hosts" in *",$host,"*) continue ;; esac + case "$external_hosts" in *",$host,"*) continue ;; esac case "$host" in localhost|*.localhost|*.test|127.*|*.ddev.site) continue ;; esac @@ -2739,18 +2816,47 @@ $extra_body" [ "$host" = "$apex" ] && related=1 && break case "$host" in *".$apex") related=1; break ;; esac done + # Related is not the same as this site, so ask the host before refusing. + # Only evidence that it *is* this WordPress keeps the refusal; anything + # else — another app, another WordPress, no answer — is a note. Refusing + # on a separate app blocked every unattended `init` after a db pull, and + # its remedy proxied that app's links onto the local site. if [ -n "$related" ]; then - echo "hostshift: refusing to call this healthy — $cnt reference(s) to" >&2 - echo " $host across the pages probed, first seen on" >&2 - echo " $(hs_page_carrying "$host")," >&2 - echo " which this map does not name and which is at or under the same" >&2 - echo " site as a hostname it does ($apex). They are not rewritten, so" >&2 - echo " they are live production links in a preview." >&2 - echo " Counted across:" >&2 - for pu in ${probe_urls:-}; do echo " $pu" >&2; done - echo " Add $host to hostshift.yaml — as an alias of the canonical it" >&2 - echo " belongs to — and \`ddev hostshift init && ddev restart\`." >&2 - exit 2 + hs_probe_related "$host" + if [ "$hs_verdict" = site ]; then + echo "hostshift: refusing to call this healthy — $cnt reference(s) to" >&2 + echo " $host across the pages probed, first seen on" >&2 + echo " $(hs_page_carrying "$host")," >&2 + echo " which this map does not name and which is at or under the same" >&2 + echo " site as a hostname it does ($apex). They are not rewritten, so" >&2 + echo " they are live production links in a preview." >&2 + echo " It is this site: $hs_evidence." >&2 + echo " Counted across:" >&2 + for pu in ${probe_urls:-}; do echo " $pu" >&2; done + echo " Add $host to hostshift.yaml — as an alias of the canonical it" >&2 + echo " belongs to — and \`ddev hostshift init && ddev restart\`." >&2 + case "$hs_evidence" in + *" redirects to "*) + echo " If it is a separate application that only redirects here," >&2 + echo " list it under the site's \`external:\` instead." >&2 ;; + esac + exit 2 + fi + if [ "$hs_verdict" = unreachable ]; then + why="could not reach it; treated as external" + else + why="it neither redirects to this site nor serves this WordPress's" + why="$why /wp-json/, so it is treated as external" + fi + echo "hostshift: note: $cnt reference(s) to $host across the pages" >&2 + echo " probed, first seen on $(hs_page_carrying "$host")." >&2 + echo " It is under the same site as $apex and this map does not name it," >&2 + echo " so it was checked: $why — its links" >&2 + echo " are left alone. If it is in fact this site, add it to" >&2 + echo " hostshift.yaml as an alias of the canonical it belongs to and" >&2 + echo " \`ddev hostshift init && ddev restart\`. If it is another" >&2 + echo " application, list it under the site's \`external:\` to skip this." >&2 + continue fi echo "hostshift: note: $(hs_page_carrying "$host")" >&2 echo " carries $cnt reference(s) to $host, which this map does not name" >&2 diff --git a/internal/config/config.go b/internal/config/config.go index 5e7982b..88093c2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -49,6 +49,10 @@ type SiteFile struct { Base string `yaml:"base"` Aliases []string `yaml:"aliases"` Variant string `yaml:"variant"` // explicit override for the rare case + // External names hostnames under this site's domain that are *not* this + // WordPress — a login app, a docs site — so `ddev hostshift check` neither + // probes them nor asks for them to be aliased. Nothing is rewritten for them. + External []string `yaml:"external"` } // Flags are the CLI overrides. They win over every file (PLAN §5.3). @@ -123,6 +127,10 @@ type Resolved struct { // neither is. DirectlyServed []string ExternalCanonicals []string + + // External is every site's `external:` hostnames from hostshift.yaml: hosts + // the file declares are someone else's application, not this WordPress. + External []string } // Load resolves the map for a project directory. @@ -198,11 +206,12 @@ func resolve(dir string, f Flags) (*Resolved, error) { } var ( - sites []origin.Site - up = f.Upstream - source string - layer string - pattern = DefaultVariantPattern + sites []origin.Site + up = f.Upstream + source string + layer string + pattern = DefaultVariantPattern + external []string ) // Layer 1 of §5.3, and the only place the core knows DDEV exists: a project @@ -237,6 +246,9 @@ func resolve(dir string, f Flags) (*Resolved, error) { if sites, err = holdSide(sites, hf, f.Holds); err != nil { return nil, err } + if external, err = externalHosts(hf, sites); err != nil { + return nil, err + } default: if err := fileLayerOnly("the DDEV config"); err != nil { return nil, err @@ -266,7 +278,7 @@ func resolve(dir string, f Flags) (*Resolved, error) { return nil, err } } - res := &Resolved{Map: m, Upstream: up, Source: source, Layer: layer} + res := &Resolved{Map: m, Upstream: up, Source: source, Layer: layer, External: external} // A hostshift.yaml *replaces* the DDEV layer rather than merging with it: // an explicit map is a statement about which hosts this project serves, and @@ -509,6 +521,51 @@ func sitesFromFile(f *File, pattern, slug string) ([]origin.Site, error) { return sites, nil } +// externalHosts reads every site's `external:` list as hostnames, a bare host +// or a URL whose host is taken. A host the map also names — any site's +// canonical, base, alias or variant — is refused: it cannot be both this +// WordPress and someone else's application, and which one wins would decide +// whether its links are rewritten. +func externalHosts(f *File, sites []origin.Site) ([]string, error) { + named := map[string]string{} + for _, s := range sites { + for _, o := range s.CanonicalSet() { + named[o.Host] = s.Name + } + if s.Variant.Host != "" { + named[s.Variant.Host] = s.Name + } + } + var out []string + for i, s := range f.Sites { + name := sites[i].Name + for _, raw := range s.External { + var ( + h string + err error + ) + if strings.Contains(raw, "://") { + var o origin.Origin + if o, err = origin.Parse(raw); err == nil { + h = o.Host + } + } else { + h, err = origin.NormaliseHost(strings.TrimSpace(raw)) + } + if err != nil || h == "" || strings.ContainsAny(h, "/ ") { + return nil, fmt.Errorf("site %q: external %q is not a hostname", name, raw) + } + if other, ok := named[h]; ok { + return nil, fmt.Errorf("site %q: external %q is also declared as a hostname of site %q — a host is either this site or external, not both", name, raw, other) + } + if !slices.Contains(out, h) { + out = append(out, h) + } + } + } + return out, nil +} + // holdSide makes each site's held origin its canonical (Flags.Holds), and the // canonical it replaces one of its aliases. sites are sitesFromFile's, in the // file's order. diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 95b1659..ebd5942 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -443,3 +443,77 @@ func TestOwnHostnameIsNotReportedUncovered(t *testing.T) { t.Errorf("Uncovered = %v, want just the undeclared hostname", res.Uncovered) } } + +// TestExternalHosts: `external:` names hosts under the site's domain that are +// another application. They are hostnames, not part of the map, and a host +// cannot be both external and one the map names. +func TestExternalHosts(t *testing.T) { + dir := t.TempDir() + write(t, dir, "hostshift.yaml", ` +sites: + - name: main + canonical: https://www.acme.example + base: https://acme.ddev.site + aliases: [https://acme.example] + external: [identity.acme.example, "https://Docs.acme.example/", identity.acme.example] +`) + res, err := Load(dir, Flags{Slug: "wt-a"}) + if err != nil { + t.Fatal(err) + } + if got := strings.Join(res.External, ","); got != "identity.acme.example,docs.acme.example" { + t.Errorf("External = %q, want both hosts, normalised and deduplicated", got) + } + for _, s := range res.Map.Sites { + for _, o := range s.CanonicalSet() { + if strings.HasPrefix(o.Host, "identity.") || strings.HasPrefix(o.Host, "docs.") { + t.Errorf("external host %q leaked into the map", o.Host) + } + } + } + + cases := []struct{ name, yaml, want string }{ + { + name: "also an alias", + yaml: ` +sites: + - {name: a, canonical: https://www.acme.example, base: https://a.ddev.site, aliases: [https://acme.example], external: [acme.example]}`, + want: "either this site or external", + }, + { + name: "another site's canonical", + yaml: ` +sites: + - {name: a, canonical: https://www.acme.example, base: https://a.ddev.site, external: [shop.acme.example]} + - {name: b, canonical: https://shop.acme.example, base: https://b.ddev.site}`, + want: "either this site or external", + }, + { + name: "not a hostname", + yaml: ` +sites: + - {name: a, canonical: https://www.acme.example, base: https://a.ddev.site, external: ["identity.acme.example/login"]}`, + want: "is not a hostname", + }, + { + name: "misspelled key", + yaml: ` +sites: + - {name: a, canonical: https://www.acme.example, base: https://a.ddev.site, externals: [identity.acme.example]}`, + want: "externals", + }, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + dir := t.TempDir() + write(t, dir, "hostshift.yaml", c.yaml) + _, err := Load(dir, Flags{Slug: "wt-a"}) + if err == nil { + t.Fatalf("Load accepted a config it must refuse") + } + if !strings.Contains(err.Error(), c.want) { + t.Errorf("error is %q, want it to mention %q", err, c.want) + } + }) + } +} diff --git a/test/addon-command.sh b/test/addon-command.sh index 93eb168..e6d8d3c 100755 --- a/test/addon-command.sh +++ b/test/addon-command.sh @@ -963,6 +963,32 @@ for a in "$@"; do [ "$prev" = "-D" ] && hdr="$a" prev="$a" done +# A host under the canonical's apex that the map does not name is asked whether +# it is this site. HS_CURL_RELATED answers per host, as space-separated +# `host=mode`: `redirect:` (its root redirects there), `wp:` (its +# /wp-json/ is a WordPress with that home), `app` (answers, is neither) or +# `down` (nothing answers). A host not listed falls through to the general fake. +for a in "$@"; do + case "$a" in https://*) url="$a" ;; esac +done +rhost="${url#https://}"; rhost="${rhost%%/*}" +rmode="" +for r in ${HS_CURL_RELATED:-}; do + case "$r" in "$rhost="*) rmode="${r#*=}" ;; esac +done +if [ -n "$rmode" ]; then + case "$rmode:$url" in + down:*) printf '000 '; exit 7 ;; + redirect:*/wp-json/) printf 'not here' ;; + redirect:*) printf '301 %s' "${rmode#redirect:}" ;; + wp:*/wp-json/) + h="${rmode#wp:}"; h="${h//\//\\/}" + printf '{"name":"Acme","description":"","url":"%s","home":"%s","namespaces":["wp/v2"]}' "$h" "$h" ;; + *:*/wp-json/) printf 'login' ;; + *) printf '200 ' ;; + esac + exit 0 +fi # Headers when asked for them, so a test can drive a redirect. HS_CURL_LOCATION # is served once, on the first call that asks for headers — hostshift's own # first probe does not, so keying this on the call number made it never fire and @@ -1579,9 +1605,11 @@ apexleak=' t' out="$(cd "$wt" && HS_CURL_BODY="$apexleak" \ + HS_CURL_RELATED="acme.example=wp:https://www.acme.example" \ PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? [ "$rc" = 2 ] && pass "an origin the map names nowhere is refused" \ || fail "an origin the map names nowhere is refused" "exit $rc" +contains "and the evidence is its /wp-json/ home" "WordPress whose home is https://www.acme.example" "$out" contains "and it is named with its count" "reference(s) to" "$out" contains "and the host it counted" "acme.example" "$out" contains "and the count is not attributed to one page" "across the pages probed" "$out" @@ -1612,6 +1640,78 @@ out="$(cd "$wt" && HS_CURL_BODY="$third" \ # reported as links, and a namespace URI is not one a browser dereferences. contains "and it is still counted out loud" "reference(s) to fonts.googleapis.com" "$out" +# Related is not the same as this site. A customer login app, a docs site or an +# auction app on a subdomain of the client's own domain is ordinary, and lives +# on another server. Refusing there blocked every unattended init after a db +# pull, and the remedy — alias it — would proxy that app's links onto the local +# site. So the host is asked: only evidence that it is this WordPress refuses. +appbody='a +b +c +d +e' +out="$(cd "$wt" && HS_CURL_BODY="$appbody" HS_CURL_RELATED="identity.acme.example=app" \ + PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? +[ "$rc" = 0 ] && pass "a separate app on a subdomain is a note, not a refusal" \ + || fail "a separate app on a subdomain is a note, not a refusal" "exit $rc: $out" +contains "and it says it checked and treated it as external" "so it is treated as external" "$out" +contains "and it names the override" "external:" "$out" +contains "and it still names the alias remedy if it is this site" "as an alias of the canonical" "$out" + +# ...and a different WordPress is still not this one. +out="$(cd "$wt" && HS_CURL_BODY="$appbody" \ + HS_CURL_RELATED="identity.acme.example=wp:https://www.elsewhere.example" \ + PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? +[ "$rc" = 0 ] && pass "another WordPress on a subdomain is a note" \ + || fail "another WordPress on a subdomain is a note" "exit $rc: $out" + +# ...and one that does not answer says so, rather than claiming it looked. +out="$(cd "$wt" && HS_CURL_BODY="$appbody" HS_CURL_RELATED="identity.acme.example=down" \ + PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? +[ "$rc" = 0 ] && pass "an unreachable related host is a note" \ + || fail "an unreachable related host is a note" "exit $rc: $out" +contains "and it says it could not reach it" "could not reach it; treated as external" "$out" + +# ...while a host whose root redirects to the canonical is this site, refused as +# before. +out="$(cd "$wt" && HS_CURL_BODY="$apexleak" \ + HS_CURL_RELATED="acme.example=redirect:https://www.acme.example/" \ + PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? +[ "$rc" = 2 ] && pass "a related host redirecting to the canonical is refused" \ + || fail "a related host redirecting to the canonical is refused" "exit $rc" +contains "and the evidence is the redirect" "redirects to https://www.acme.example/" "$out" +contains "and the remedy is still an alias" "as an alias of the canonical" "$out" + +# ...and a host the file lists under `external:` is neither probed nor noted. +printf 'sites:\n - canonical: https://www.acme.example\n variant: https://wt-a--acme.ddev.site\n external: [identity.acme.example]\n' \ + > "$wt/hostshift.yaml" +(cd "$wt" && "$cmd" init --slug wt-a >/dev/null 2>&1) || true +env_args="$(sed -n 's/^HOSTSHIFT_ARGS=//p' "$wt/.ddev/.env")" +env_variants="$(sed -n 's/^HOSTSHIFT_VARIANTS=//p' "$wt/.ddev/.env")" +env_web="$(sed -n 's/^HOSTSHIFT_WEB_HOSTS=//p' "$wt/.ddev/.env")" +writefake +: > "$HS_FAKE_DIR/curl-hosts" +out="$(cd "$wt" && HS_CURL_BODY="$appbody" HS_CURL_RELATED="identity.acme.example=down" \ + PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? +[ "$rc" = 0 ] && pass "a host listed under external: passes" \ + || fail "a host listed under external: passes" "exit $rc: $out" +case "$out" in + *"reference(s) to identity.acme.example"*) fail "and it is not noted" "$out" ;; + *) pass "and it is not noted" ;; +esac +if grep -q "identity.acme.example" "$HS_FAKE_DIR/curl-hosts" 2>/dev/null; then + fail "and it is not probed" "$(tr '\n' ' ' < "$HS_FAKE_DIR/curl-hosts")" +else + pass "and it is not probed" +fi +printf 'sites:\n - canonical: https://www.acme.example\n variant: https://wt-a--acme.ddev.site\n' \ + > "$wt/hostshift.yaml" +(cd "$wt" && "$cmd" init --slug wt-a >/dev/null 2>&1) || true +env_args="$(sed -n 's/^HOSTSHIFT_ARGS=//p' "$wt/.ddev/.env")" +env_variants="$(sed -n 's/^HOSTSHIFT_VARIANTS=//p' "$wt/.ddev/.env")" +env_web="$(sed -n 's/^HOSTSHIFT_WEB_HOSTS=//p' "$wt/.ddev/.env")" +writefake + # A page that 302s to wp-signup.php is WordPress saying it does not know the # hostname, and on a multisite that means nothing is previewable at all. # @@ -2106,6 +2206,7 @@ sib='a d e' out="$(cd "$wt" && HS_CURL_BODY="$sib" \ + HS_CURL_RELATED="shop.example.co.uk=redirect:https://example.co.uk/shop/" \ PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? [ "$rc" = 2 ] && pass "a real sibling under the apex is still refused" \ || fail "a real sibling under the apex is still refused" "exit $rc" @@ -2159,6 +2260,7 @@ sibleak='=== a line that used to split the record === out="$(cd "$wt" && HS_CURL_BODY='

clean

' HS_CURL_BODY2="$sibleak" \ HS_CURL_CODES="302 200 200" HS_CURL_STATE="$hs55n" \ HS_CURL_LOCATION="https://wt-a--acme.ddev.site/fi/" \ + HS_CURL_RELATED="media.acme.example=wp:https://www.acme.example" \ PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? [ "$rc" = 2 ] && pass "a leak on the page behind a redirect is found" \ || fail "a leak on the page behind a redirect is found" "exit $rc" @@ -2186,6 +2288,7 @@ for spelling in json pct refs; do for i in 1 2 3 4 5; do body="$body $esc"; done out="$(cd "$wt" && HS_CURL_BODY="$body" \ + HS_CURL_RELATED="acme.example=wp:https://www.acme.example" \ PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? [ "$rc" = 2 ] && pass "a $spelling-escaped off-map origin is refused" \ || fail "a $spelling-escaped off-map origin is refused" "exit $rc" @@ -2244,6 +2347,7 @@ ccown='a d e' out="$(cd "$wt" && HS_CURL_BODY="$ccown" \ + HS_CURL_RELATED="shop.acme.co.uk=redirect:https://www.acme.co.uk/shop/" \ PATH="$fakedb:$fakecurl:$fakebin:$PATH" "$cmd" check --slug wt-a 2>&1)" && rc=0 || rc=$? [ "$rc" = 2 ] && pass "and a subdomain of the canonical's parent still is" \ || fail "and a subdomain of the canonical's parent still is" "exit $rc"