Skip to content

fix(nip05): refuse IPv6 forms carrying a private IPv4 - #1421

Merged
chappie-daemon merged 2 commits into
rewrite/mainfrom
factory/055-nip05-embedded-ipv4
Dec 6, 2026
Merged

chappie-daemon merged 2 commits into
rewrite/mainfrom
factory/055-nip05-embedded-ipv4

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

is_public_address refused loopback, ULA, link-local, site-local and v4-mapped IPv6 — but not the IPv6 forms that carry an IPv4 in their payload. On a host that routes them (this workspace runs IPv6-only + NAT64), a NIP-05 domain resolving to 64:ff9b::a9fe:a9fe passed the guard and the fetch dialled 169.254.169.254. A kind-0 event controls nip05.domain, so that is the SSRF hole the guard exists to close, reachable through an encoding rather than a hostname.

Found by job 052's security lens; pre-existing at 4c4f6a6d.

What ships

  • embedded_ipv4(Ipv6Addr) -> Option<Ipv4Addr> — a private helper beside is_public_address, reusing the existing private is_public_v4:
    • NAT64 64:ff9b::/96 (RFC 6052): the full /96 — segments 2–5 zero — so 64:ff9b:1::a9fe:a9fe is ordinary global unicast, not an embedding form, and stays allowed; payload is the low 32 bits.
    • 6to4 2002::/16 (RFC 3056): payload is bits 16–47; the two bytes after it are the SLA ID, not the address.
    • Teredo 2001::/32 (RFC 4380): the client's IPv4 is the low 32 bits, inverted.
  • The rule is the embedded address's, never the prefix's. 64:ff9b::808:808, 2002:808:808::1, 2002:808:808:1::1, a Teredo address wrapping 8.8.8.8, 64:ff9b::101:101 and 64:ff9b::a9fe:a9fe outside the /96 all stay diallable. Refusing the prefixes wholesale would have broken NAT64 to public hosts, which is how this host reaches the v4 internet.
  • One table test — 11 refused forms (the three prefixes wrapping metadata, loopback and each of the v4-only special ranges) and 6 allowed ones.

Both consumers inherit it with no call-site change: GuardedResolver::resolve (direct fetch) and nip05_egress::resolve_checked (tunnel hops) call the same function. nip05_egress.rs is untouched.

Evidence

  • cargo test -p nostream-services http:: → 24 passed; 0 failed (23 at base); the new test under -- --exact → 1 passed.
  • Inversion executed and recorded: the 6to4 arm deleted → 2002:a9fe:a9fe::1 is not public → restored → green.
  • clippy -D warnings and fmt --check clean.
  • Behaviour probe against the real crate on both rlibs: the 11 refused forms moved true → false; all 6 allowed forms and the anchors (2001:db8::1, ::ffff:127.0.0.1, fc00::1, fe80::1) unchanged; a resolver whose only answer is 64:ff9b::a9fe:a9fe now refuses with "every address is private, loopback, link-local, multicast or unspecified".

Reviews

Code (gate) and security lenses; security ran the residual-encoding table — IPv4-compatible ::/96, IPv4-translated ::ffff:0:0:0/96 and shifted RFC 6052 prefixes are not refused, and each was measured not exploitable on this host (no sit route, no SIIT translator, no network-specific prefix configured). Those become a follow-up issue rather than a silent claim of completeness; see the review.

Notes a reader should know

  • Changeset is empty (.changeset/nip05-embedded-ipv4.md, empty frontmatter), per the repo's own rule for a Rust-only PR (CLAUDE.md:12-16); the changeset content changes only when the TypeScript package does.
  • One new rustdoc warning (cargo doc -p nostream-services): public docs for is_public_address link the private embedded_ipv4 at http.rs:230. No CI job runs rustdoc, and the crate already ships a pre-existing doc warning; the one-line fix is to drop the brackets if ever wanted.
  • Where the recorded numbers came from: the tests and clippy runs executed inside the factory-manager member's Landlock domain, with the local toolchain, because the Docker policy refused every host bind at the time (taken at the operator's direction; rows after this one are container-built). Two independent lenses reproduced the oracle in their own target directories, so this affects provenance, not results.
  • A follow-up is filed for the encodings this fix does not cover: nip05 guard: IPv4-compatible, translated and network-specific NAT64 prefixes still pass is_public_address #1420.

Closes #1402 is inert here (the default branch is main); the issue is closed by hand after merge.

Summary by CodeRabbit

  • Bug Fixes
    • Improved public-address detection for IPv6 addresses that embed IPv4 addresses using NAT64, 6to4, or Teredo. These addresses are now evaluated according to the embedded IPv4 address, helping distinguish public destinations from private ones.

@changeset-bot

changeset-bot Bot commented Dec 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9c5c762

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The HTTP address guard now checks embedded IPv4 addresses in NAT64, 6to4, and Teredo IPv6 forms against existing IPv4 rules. Tests cover these forms and related address boundaries.

Changes: Address guard

Layer / File(s) Summary
Embedded IPv4 checks
crates/nostream-services/src/http.rs, .changeset/nip05-embedded-ipv4.md
The guard extracts IPv4 payloads from recognized NAT64, 6to4, and Teredo addresses, then applies existing IPv4 public-address rules. Tests cover wrapped private and public addresses, the 6to4 SLA ID, and an address outside the recognized NAT64 prefix. The changeset file contains empty YAML front matter.

Possibly related issues

  • Issue 1402 in cameri/nostream asks the address guard to reject private IPv4 payloads in the three IPv6 formats handled by this change.
  • Issue 1420 in cameri/nostream concerns other embedded IPv4 formats and prefixes that this change does not cover.

Suggested reviewers: cameri, greptile-apps

Change: Bug fix

Merge Risk: Minimal · up to 9c5c7

The change tightens the NIP-05 address guard so IPv6 forms that embed private IPv4 destinations are refused. No merge-blocking risk is identified; a few rarer address forms remain tracked in a follow-up issue.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: IPv6 forms that embed a private IPv4 address are now refused by the NIP-05 guard. The http.rs change adds embedded-IPv4 checks for NAT64, 6to4, and Teredo addresses, w…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: IPv6 forms that embed a private IPv4 address are now refused by the NIP-05 guard. The http.rs change adds embedded-IPv4 checks for NAT64, 6to4, and Teredo addresses, which matches the title. The title uses a conventional fix(scope) prefix and is specific and under 72 characters. It does not mention the deferred IPv4-compatible and IPv4-translated forms, which is expected for a short title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2fc08df and 9c5c762.

Files selected for processing: 2

  • .changeset/nip05-embedded-ipv4.md
  • crates/nostream-services/src/http.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge with no actionable issues found.

Summary

The PR checks the IPv4 carried by well-known NAT64, 6to4, and Teredo addresses before allowing NIP-05 connections.

  • NIP-05 lookups check IPv4 addresses carried inside IPv6.

Acknowledgments: chappie-daemon deferred other IPv6 embedding forms to #1420 and acknowledged the private rustdoc link warning.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[NIP-05 resolved address] --> B[is_public_address]
  B --> C{Mapped or handled embedded IPv4?}
  C -->|Yes| D[Apply existing IPv4 checks]
  C -->|No| E[Apply existing IPv6 checks]
  D --> F[Direct path keeps allowed addresses]
  E --> F
  D --> G[Proxy path refuses any blocked address]
  E --> G
Loading

Reviews (1) · Last reviewed commit: "chore(changeset): empty changeset for a ..." · Reviewed by Greptile

@chappie-daemon
chappie-daemon merged commit b323c67 into rewrite/main Dec 6, 2026
20 checks passed
@chappie-daemon
chappie-daemon deleted the factory/055-nip05-embedded-ipv4 branch December 6, 2026 16:45
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