Details
Run with:
go test ./internal/tools/ -run TestIsInternalIP_UncoveredIPv6Forms
On v1.29.2 every subtest fails. Each failure is a documented bypass.
End-to-end repro
In an environment where the embedded IPv4 destination is reachable (e.g. a host whose network provides NAT64 to RFC 1918 / link-local):
- Send a crafted email to mailpit's SMTP listener containing an
<a href>with a bypass URL:
<a href="http://[64:ff9b::a9fe:a9fe]/latest/meta-data/iam/security-credentials/">link</a>
POST /api/v1/message/{ID}/link-check.- Observe the
doHeadHTTP HEAD response status — non-zero status (success or specific error) confirms the dial reached the destination rather than being blocked byIsInternalIP.
In environments without NAT64 / 6to4 routing the connection will time out, but the absence of a private/reserved address blocked response confirms the deny-list bypass logically; the unit test above is the canonical PoC.
Impact
Identical scope and severity model to the original GHSA-mpf7-p9x7-96r3:
- The link-check API is reachable in mailpit's default deploy without authentication (no
--ui-auth, no--smtp-authrequired). - An attacker who can deliver email to the mailpit SMTP listener (often unauthenticated in default config) and invoke the link-check API can probe internal services using any of the uncovered IPv6 forms above — either via the embedded-IPv4 mechanisms to reach IPv4 destinations like cloud metadata endpoints (
169.254.169.254,168.63.129.16), or by addressing a routable IPv6 service viafec0::/10directly. - The status-code-and-error feedback exposed by the link-check API leaks reachability information per probe.
- Damage ceiling is bounded by the mailpit response shape (status code, status text,
451 Blocked private/reserved addresssentinel) — no response body is exposed — but reachability + status-code mapping is sufficient for service discovery and for confirming cloud-metadata service identity. - Scope note:
tools.IsInternalIPis also used by the screenshot-proxy and HTML-Check-API endpoints (per maintainer disclosure). The same deny-list bypass applies to dialer decisions in those paths, but they include additional checks that mute the impact. The Link Check API remains the most revealing because its response includes the HTTP status code from the dialed destination; the other two are less directly leaky.
Severity: Moderate, mirroring the original advisory (CVSS 5.8).
Suggested remediation
The fix has two parts:
- For the IPv4-embedded-in-IPv6 forms: decode the embedded IPv4 and re-check it. This is the same pattern Python's `ipaddress.is_private` implemented in 3.13, what `code.dny.dev/ssrf` (IANA Special Purpose Registry-driven, auto-synced) implements out-of-the-box, and the behavior change being proposed for Go's stdlib at golang/go#79925.
- For the direct IPv6 prefixes: add them to the first range check alongside
cgnatRange.Contains.
Reference implementation (extends the existing helper, keeps the call-site contract identical):
// internal/tools/net.go
package tools
import (
"encoding/binary"
"net"
)
var (
cgnatRange = mustCIDR("100.64.0.0/10") // RFC 6598
deprecatedSiteLocal = mustCIDR("fec0::/10") // RFC 3879 / 4291
documentationPrefix = mustCIDR("2001:db8::/32") // RFC 3849
nat64WellKnown = mustCIDR("64:ff9b::/96") // RFC 6052
nat64LocalUse = mustCIDR("64:ff9b:1::/48") // RFC 8215
sixToFour = mustCIDR("2002::/16") // RFC 3056
teredo = mustCIDR("2001::/32") // RFC 4380
ipv4Compatible = mustCIDR("::/96") // RFC 4291 §2.5.5.1
ipv4Mapped = mustCIDR("::ffff:0:0/96") // RFC 4291 §2.5.5.2
)
func mustCIDR(s string) *net.IPNet {
_, n, err := net.ParseCIDR(s)
if err != nil {
panic(err)
}
return n
}
// IsInternalIP reports whether ip should be blocked as a connection target.
// Covers the stdlib Is* checks plus CGNAT, plus IPv6 forms outside the
// stdlib's scope (deprecated site-local, documentation prefix, and the
// IPv6 transition mechanisms whose embedded IPv4 is itself internal).
func IsInternalIP(ip net.IP) bool {
if ip.IsLoopback() ||
ip.IsPrivate() ||
ip.IsLinkLocalUnicast() ||
ip.IsLinkLocalMulticast() ||
ip.IsUnspecified() ||
ip.IsMulticast() ||
cgnatRange.Contains(ip) ||
deprecatedSiteLocal.Contains(ip) ||
documentationPrefix.Contains(ip) {
return true
}
if embedded, ok := embeddedIPv4(ip); ok {
return IsInternalIP(embedded)
}
return false
}
// embeddedIPv4 returns the IPv4 destination encoded in ip, if ip is an
// IPv6 form documented to carry an embedded IPv4 destination.
func embeddedIPv4(ip net.IP) (net.IP, bool) {
// Skip IPv4 / IPv4-mapped IPv6 — covered by the stdlib Is* checks via To4.
if ip.To4() != nil {
return nil, false
}
ip16 := ip.To16()
if ip16 == nil || len(ip16) != net.IPv6len {
return nil, false
}
switch {
case nat64WellKnown.Contains(ip16), nat64LocalUse.Contains(ip16),
ipv4Compatible.Contains(ip16):
// Last 32 bits are the embedded IPv4.
return net.IPv4(ip16[12], ip16[13], ip16[14], ip16[15]).To4(), true
case sixToFour.Contains(ip16):
// Bits 16..47 are the embedded IPv4.
return net.IPv4(ip16[2], ip16[3], ip16[4], ip16[5]).To4(), true
case teredo.Contains(ip16):
// Bits 96..127 are the embedded IPv4 XOR'd with 0xFFFFFFFF.
x := binary.BigEndian.Uint32(ip16[12:16]) ^ 0xFFFFFFFF
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, x)
return net.IPv4(b[0], b[1], b[2], b[3]).To4(), true
case ip16[10] == 0x5e && ip16[11] == 0xfe:
// ISATAP (RFC 5214) — interface identifier ends with :5efe:<ipv4>.
// Match structurally on bytes 10-11; the /64 prefix is not fixed.
// Must run after the fixed-prefix cases above (Teredo can legitimately
// have 5efe in bytes 10-11; its embedding takes precedence).
return net.IPv4(ip16[12], ip16[13], ip16[14], ip16[15]).To4(), true
}
return nil, false
}
This covers every bypass in the two tables above. The direct-prefix additions (deprecatedSiteLocal, documentationPrefix) are two lines in the first if-block; the embedded-IPv4 decoder is the substantive new function.
Alternative — adopt a comprehensive library: Replace the hand-rolled deny-list with `code.dny.dev/ssrf`, which generates its IPv4 and IPv6 prefix lists from the IANA Special Purpose Registries via a bi-monthly auto-sync. This protects against future RFCs adding new transition forms without requiring further mailpit maintenance.