Repository navigation
fix(nip05): refuse IPv6 forms carrying a private IPv4 - #1421
Conversation
🦋 Changeset detectedLatest commit: 9c5c762 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen 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 |
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge with no actionable issues found.
|
is_public_addressrefused 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 to64:ff9b::a9fe:a9fepassed the guard and the fetch dialled169.254.169.254. A kind-0 event controlsnip05.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 besideis_public_address, reusing the existing privateis_public_v4:64:ff9b::/96(RFC 6052): the full /96 — segments 2–5 zero — so64:ff9b:1::a9fe:a9feis ordinary global unicast, not an embedding form, and stays allowed; payload is the low 32 bits.2002::/16(RFC 3056): payload is bits 16–47; the two bytes after it are the SLA ID, not the address.2001::/32(RFC 4380): the client's IPv4 is the low 32 bits, inverted.64:ff9b::808:808,2002:808:808::1,2002:808:808:1::1, a Teredo address wrapping 8.8.8.8,64:ff9b::101:101and64:ff9b::a9fe:a9feoutside 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.Both consumers inherit it with no call-site change:
GuardedResolver::resolve(direct fetch) andnip05_egress::resolve_checked(tunnel hops) call the same function.nip05_egress.rsis untouched.Evidence
cargo test -p nostream-services http::→ 24 passed; 0 failed (23 at base); the new test under-- --exact→ 1 passed.2002:a9fe:a9fe::1 is not public→ restored → green.clippy -D warningsandfmt --checkclean.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 is64:ff9b::a9fe:a9fenow 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/96and shifted RFC 6052 prefixes are not refused, and each was measured not exploitable on this host (nositroute, 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/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.cargo doc -p nostream-services): public docs foris_public_addresslink the privateembedded_ipv4athttp.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.Closes #1402is inert here (the default branch ismain); the issue is closed by hand after merge.Summary by CodeRabbit