Skip to content

nip05 guard: v6 embedded-IPv4 forms (NAT64, 6to4, Teredo) pass is_public_address #1402

Done

Description

@chappie-daemon

Found by job 052's security lens (review-security.md) while porting nip05.proxy; the check is pre-existing at base 4c4f6a6d, not introduced by that job.

crates/nostream-services/src/http.rs:225-246 — is_public_address refuses loopback, unspecified, multicast, fc00::/7, fe80::/10, fec0::/10, and v4-mapped forms (which it unwraps to the v4 check). It does not refuse v6 forms that carry an IPv4 address inside them:

  • 64:ff9b::/96 — the well-known NAT64 prefix (64:ff9b::a9fe:a9fe is 169.254.169.254);
  • 2002::/16 — 6to4 (v4 in bits 16–47);
  • 2001::/32 — Teredo.

On a host that routes those prefixes (this workspace already runs IPv6-only + NAT64 — docs/infra/nostream-dev-nat64.md), a hostname resolving to one of them passes is_public_address and the fetch connects to the wrapped address. NIP-05 documents are author-controlled (nip05.domain in a kind-0 event), so this is the SSRF class the guard exists to stop, reachable against metadata and loopback services that a NAT64/DNS64 network publishes to v6 clients.

Acceptance

  • is_public_address (or a helper beside it) refuses 64:ff9b::/96, 2002::/16 and 2001::/32 by embedding-form, not by hostname: a unit test asserts each prefix's v4 payload is extracted and checked with is_public_v4, so 64:ff9b::a9fe:a9fe, 2002:a9fe:a9fe::1 and a Teredo address wrapping 10.0.0.1 are refused while 64:ff9b::808:808 (8.8.8.8) is allowed.
  • The test fails on the base implementation and its inversion (drop one prefix arm) reddens it.
  • The NIP-05 fetch path and the admin reverify path both inherit it — one call site each, asserted by the existing guard test plus the new table.
  • If a prefix cannot be refused without breaking a legitimate use, say which and why in the PR; do not silently narrow the guard.

Out of scope: the nip05.proxy tunnel's own behaviour (job 052), which re-checks every hop through the same function and so inherits this fix.


For whoever picks this up

  • What is wrong: A NIP-05 hostname that resolves to an IPv6 address carrying an IPv4 address inside it (NAT64 64:ff9b::/96, 6to4 2002::/16, Teredo 2001::/32) passes the public-address guard, so the fetch connects to the loopback, private or metadata address it wraps.
  • Done looks like: is_public_address (or a helper it calls, like is_public_v4) extracts the IPv4 address embedded in each of the three prefixes, inverting Teredo's client field, and applies the existing v4 rules. A new test embedded_ipv4_v6_forms_are_refused in the tests module of crates/nostream-services/src/http.rs asserts 64:ff9b::a9fe:a9fe, 2002:a9fe:a9fe::1 and a Teredo address wrapping 10.0.0.1 (e.g. 2001:0:4136:e378:8000:63bf:f5ff:fffe) are refused, while 64:ff9b::808:808 is allowed; it fails against the current predicate. Both consumers, GuardedResolver::resolve() and nip05_egress::resolve_checked(), call the same function, so the one table covers both.
  • Where it lives: crates/nostream-services/src/http.rs — is_public_address(), with the v4 rules in is_public_v4(); called from GuardedResolver::resolve() and is_redirect_target_safe() in the same file, and from resolve_checked() in crates/nostream-services/src/nip05_egress.rs.
  • Intent: fix(nip05): refuse a verification host that resolves to a private address #1278 — the guard exists because an author-controlled NIP-05 domain must not reach loopback, private ranges or cloud metadata; this is the same SSRF through an IPv6 encoding.

Activity

  1. added
    bug
    security
    rewrite
    rust
    on Dec 5, 2026
  2. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    CollaboratorAuthor

    Job 055 opened at 2fc08dff; recon running (worktree factory/055-nip05-embedded-ipv4). Expected cost $2.20.

  3. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    CollaboratorAuthor

    Build started: private embedded_ipv4 helper wired into the v6 arm of is_public_address; the rule is "refuse iff the embedded v4 is not public", with public-embedded forms kept allowed. Oracle is cargo test -p nostream-services http:: 23 → 24 passed.

  4. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    CollaboratorAuthor

    Review round 1: security lens PASS (three residual encodings measured not exploitable on this host, follow-up to be filed); code lens running as the gate; architecture, performance, ux and ui stood down on measured counts (review-plan.json).

  5. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    CollaboratorAuthor

    Shipped as b323c67d3e2a1a8b05677fbd647909217f56e5db (PR #1421, merge commit; branch head 9c5c7629, two commits on base 2fc08dff).

    What landed: embedded_ipv4(Ipv6Addr) -> Option<Ipv4Addr> beside is_public_address — NAT64 64:ff9b::/96 (full /96, low 32 bits), 6to4 2002::/16 (bits 16–47, SLA ignored), Teredo 2001::/32 (client low 32 bits inverted) — judged by the existing is_public_v4. The rule is the embedded address's, never the prefix's: 64:ff9b::808:808 and 64:ff9b:1::a9fe:a9fe stay allowed while 64:ff9b::a9fe:a9fe and the 6to4/Teredo equivalents wrapping private, loopback, CGN, benchmarking, 0/8 or broadcast addresses are refused.

    Evidence: cargo test -p nostream-services http:: 24 passed (23 at base); three executed inversions red→green (builder's 6to4 arm; code lens's NAT64 arm, Teredo !, and the /96 guard); clippy both CI forms and fmt clean; Rust Checks green on the merge.

    Reviews: code (gate) and security lenses both PASS. The security lens measured three residual encodings (IPv4-compatible ::/96, IPv4-translated ::ffff:0:0:0/96, shifted RFC 6052 NAT64 prefixes) as not exploitable on this host and they are filed as #1420 rather than silently declared impossible.

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

Metadata

Metadata

Labels

bugrewriterustsecurity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions