Skip to content

ValidateRemoteURL misses empty-host, trailing-dot, zone-ID, and non-standard IP forms #6197

Open

Description

@premctl

Summary

ValidateRemoteURL (cmd/thv-operator/pkg/validation/url_validation.go) blocks internal/private endpoints by matching the parsed hostname against a CIDR list (when net.ParseIP succeeds) or a hostname blocklist (otherwise). Several host forms fall through net.ParseIP into the hostname path and match nothing there, bypassing the blocklist entirely. All of these are pre-existing and independent of the new allowPrivateEndpoint flag (#5784 / #6195) — they are accepted in both flag states:

Form Example Why it slips through
Empty hostname http://:8080/ u.Host is ":8080" (non-empty, passes the host check) but u.Hostname() is "", which matches no blocklist entry. Go's HTTP client dials loopback for an empty host.
Trailing dot (FQDN root) http://localhost./ "localhost." fails the exact match against "localhost" and the "."+blocked suffix match; resolvers treat it as localhost. Applies to every blocked name (metadata.google.internal., etc.).
IPv6 zone ID http://[fe80::1%25eth0]/ net.ParseIP rejects zone IDs, so a link-local literal drops into the hostname path and is never checked against fe80::/10.
Non-standard IP forms http://2130706433/, http://0177.0.0.1/ Decimal/octal forms fail net.ParseIP and match no blocked hostname; whether they reach loopback depends on the consuming HTTP stack/resolver.

These were identified during the review of #6195 and deliberately not fixed there: that PR's contract was flag-off behavior byte-for-byte identical to main, and closing these holes changes validation outcomes in both flag states, so it warrants its own change and test matrix.

Suggested direction

  • Reject an empty u.Hostname() explicitly (the current u.Host == "" check does not cover http://:port).
  • Normalize (or reject) a single trailing dot before blocklist matching.
  • Parse host literals with netip.ParseAddr, which accepts zone IDs — check the address part against the CIDR sets, or reject zoned literals outright.
  • Consider rejecting any host that is neither a valid DNS name nor an address netip.ParseAddr accepts — a shape allowlist also disposes of the decimal/octal forms without enumerating them.

Unit tests should cover each form in both AllowPrivateEndpoint states (all should be rejected in both).

Context: validateHostNotInternal and the blocklists live in cmd/thv-operator/pkg/validation/url_validation.go; the validator intentionally performs no DNS resolution, and nothing here requires adding any.

Activity

  1. added
    needs-triage
    on Aug 5, 2026
  2. reyortiz3 commented on Aug 17, 2026

    @reyortiz3
    Collaborator

    Thanks for the thorough writeup, @premctl — and for catching these while working on #6195. The four forms you've laid out (empty host, trailing-dot FQDN, IPv6 zone ID, and decimal/octal literals) all look like real gaps in validateHostNotInternal, independent of the allowPrivateEndpoint flag.

    Given your context from #6195, would you be interested in sending a PR for this? Your suggested direction sounds right to us: explicit empty-Hostname() rejection, trailing-dot normalization, netip.ParseAddr for zone-ID-aware literals, and a shape check to catch non-standard IP forms. If so, please cover all four forms in both AllowPrivateEndpoint states in the test matrix. Happy to give early feedback on approach before you go deep — and if you'd rather we take it, just let us know and we'll pick it up.

  3. premctl commented on Aug 19, 2026

    @premctl
    ContributorAuthor

    Thanks @reyortiz3 — happy to take it. Two things before I go deep: one ordering point, one design question.

    Ordering vs #6195

    #6195 is approved and green but not merged yet. The matrix you're asking for needs ValidateRemoteURLOptions from that PR — on main today ValidateRemoteURL still takes a single argument, so there aren't two flag states to matrix over. Either:

    Either works; let me know which you'd rather review.

    Design question: how wide should the shape check be?

    Three of the four have an obvious narrow fix and I'd just write them:

    • Empty hostname — explicit u.Hostname() == "" rejection alongside the existing u.Host == "" check.
    • IPv6 zone ID — parse literals with netip.ParseAddr and match the address part against the CIDR sets. fe80::/10 is in alwaysBlockedCIDRs post-Allow opt-in private endpoints for remote URLs #6195, so [fe80::1%25eth0] is rejected in both flag states.
    • Trailing dot — strip a single trailing dot before blocklist matching, rather than rejecting it. Rejecting would break a case Allow opt-in private endpoints for remote URLs #6195 exists to serve: http://backend.ns.svc.cluster.local./mcp is an ordinary resolver-emitted form and should be allowed when AllowPrivateEndpoint is on, not rejected. So: normalize, then the existing flag semantics apply unchanged.

    The fourth is the one I'd like your call on:

    (a) Shape allowlist — reject any host that is neither accepted by netip.ParseAddr nor a syntactically valid DNS name. Disposes of 2130706433 and 0177.0.0.1 without enumerating numeric encodings, and closes the rest of that family pre-emptively. Cost: it rejects hosts that work today and that nobody reported — most concretely, labels containing underscores (my_service.internal), which are RFC 1123-invalid but common in internal DNS.

    (b) Narrow — reject only hosts that are entirely numeric or dotted-numeric but fail netip.ParseAddr. Kills the two reported forms, touches nothing else.

    I lean (a), with underscores explicitly permitted so the common internal-DNS case survives — it's the version that doesn't need revisiting the next time someone finds a novel encoding. But (a) is the only piece here with a blast radius outside the reported bug, so it's your call rather than mine; happy to go (b) if you'd rather keep this strictly to the reported forms.

    Test matrix

    All four forms × both AllowPrivateEndpoint states, all rejected — each bottoms out in alwaysBlockedCIDRs/alwaysBlockedHostnames (localhost, 127.0.0.0/8, fe80::/10), so the flag relaxes none of them. Plus a fifth row for the positive trailing-dot case above: backend.ns.svc.cluster.local. allowed with the flag on, rejected with it off.

    One caveat carried over from the issue: whether 2130706433 actually reaches loopback is resolver-dependent — Go's pure-Go resolver won't take it, glibc's inet_aton path will. I'm treating it as defense-in-depth rather than a confirmed reachable SSRF, and the tests will assert validator behavior, not reachability.

  4. reyortiz3 commented on Aug 21, 2026

    @reyortiz3
    Collaborator

    Hi @premctl !, sorry it took a bit longer.

    • Ordering: Allow opt-in private endpoints for remote URLs #6195 was approved and merged by a teammate, so this is covered.
    • Design: The three proposed fixes sound reasonable (Empty hostname, IPv6 zone ID, and stripping single trailing dot). I also lean towards (a) with the exception of permitting underscores.
  5. added
    p2
    and removed
    needs-triage
    on Aug 24, 2026
  6. blkt commented on Aug 24, 2026

    @blkt
    Contributor

    @premctl I'm assigning this to you for tracking, just tidying up the board. Please let us know if this is a problem and you don't plan to work on this anymore.

  7. reyortiz3 commented on Aug 26, 2026

    @reyortiz3
    Collaborator

    Hi @premctl , thanks again for submitting this issue to help improving Toolhive , much appreciated 🙏 !

    Our Head of Product @Derek2Tu would like to chat with you. If you're ok (totally optional), I can have Will from the client engagement team help set that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions