--- title: "ADR 0064: Hostnames are normalised the way a resolver reads them" --- * Status: accepted * Code: [`pkg/vcshost/vcshost.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/vcshost/vcshost.go) ## Context Hostnames reach the controller from a webhook payload and from administrator settings, and `hostpolicy` compares them with an allowlist. If the policy and the HTTP client read the same string differently, a name that looks like `github.com` can be dialled as another host. The code shows a concrete case: `strings.ToLower` maps U+0130 (capital I with dot above) to a plain `i`, while the IDNA lookup mapping yields `xn--github-qyd.com`, a different registrable name. `TestParseNormalisation` pins this. ## Decision * `normalise` runs `idnaProfile.ToASCII` (lookup mapping, bidi rule, non-strict domain name) on the raw hostname first, and only then lowercases the result. Case folding of our own never runs before the IDNA mapping. * The result must be a fixed point: a second `ToASCII` pass has to give the same name, otherwise `Parse` returns an error. * The result must also pass `validDNSHostname` (length 253 and 63 per label, characters `a-z 0-9 -`, no leading or trailing dash). IP literals skip this and keep their brackets or port. * `Parse` accepts only a bare host or an `https` URL with no path, query, fragment or credentials. `SplitURL` is the shared lenient parser and leaves scheme policy to its caller. Its callers in [`pkg/provider/github/endpoints.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/endpoints.go), [`pkg/secrets/inherit.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/secrets/inherit.go) and [`pkg/hostpolicy/hostpolicy.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/hostpolicy/hostpolicy.go) decide which schemes they take. * `publicHosts` folds `api.github.com` and `api.bitbucket.org` onto their canonical host. `Canonical` and `Allowed` apply it on both sides, so `github.com` and `api.github.com` match each other. ## Consequences * A caller that builds a URL from the raw input instead of the value `Parse` or `Canonical` returned bypasses this guarantee. The code does not enforce this; callers have to follow it. * Adding a public SaaS host means editing `publicHosts` and, for a new provider type, `TestIsPublicCoversEveryHostedProvider`.