Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: proper DNS64 support

Matthew Kilgore42c52f7f7566
diff --git a/backend/internal/core/services/all.go b/backend/internal/core/services/all.go
index 2b2a9e0c..b971ce82 100644
--- a/backend/internal/core/services/all.go
+++ b/backend/internal/core/services/all.go
@@ -78,8 +78,9 @@ func WithMailer(m *mailer.Mailer) func(*options) {
// This ensures SSRF protections are enabled when WithNotifierConfig is not provided.
func defaultNotifierConf() *config.NotifierConf {
return &config.NotifierConf{
- BlockBogonNets: true, // default:true per conf tag
- BlockCloudMetadata: true, // default:true per conf tag
+ BlockBogonNets: true, // default:true per conf tag
+ BlockCloudMetadata: true, // default:true per conf tag
+ Dns64Nets: []string{"64:ff9b::/96", "64:ff9b:1::/48"}, // default per conf tag
}
}
diff --git a/backend/internal/core/services/main_test.go b/backend/internal/core/services/main_test.go
index ed761176..cc15811b 100644
--- a/backend/internal/core/services/main_test.go
+++ b/backend/internal/core/services/main_test.go
@@ -58,6 +58,10 @@ func MainNoExit(m *testing.M) int {
log.Fatalf("failed opening connection to sqlite: %v", err)
}
+ go func() {
+ _ = tbus.Run(context.Background())
+ }()
+
err = client.Schema.Create(context.Background())
if err != nil {
log.Fatalf("failed creating schema resources: %v", err)
diff --git a/backend/internal/sys/config/conf_notifier.go b/backend/internal/sys/config/conf_notifier.go
index 95d49872..b303a656 100644
--- a/backend/internal/sys/config/conf_notifier.go
+++ b/backend/internal/sys/config/conf_notifier.go
@@ -15,4 +15,10 @@ type NotifierConf struct {
BlockBogonNets bool `yaml:"block_bogon_nets" conf:"default:true"`
// BlockCloudMetadata will prevent generic notifiers from sending to known cloud metadata IPs.
BlockCloudMetadata bool `yaml:"block_cloud_metadata" conf:"default:true"`
+ // Dns64Nets lists the IPv6 prefixes used for DNS64/NAT64 translation (RFC 6052).
+ // IPv6 addresses inside these prefixes carry an embedded IPv4 address, which is
+ // extracted and checked against the allow/block rules above so DNS64 synthesis
+ // cannot be used to bypass them. Defaults to the RFC 6052 well-known prefix and
+ // the RFC 8215 local-use prefix; override if your network uses a custom prefix.
+ Dns64Nets []string `yaml:"dns64_nets" conf:"default:64:ff9b::/96;64:ff9b:1::/48,env:NOTIFIER_DNS64_NETS,flag:notifier-dns64-nets"`
}
diff --git a/backend/internal/sys/validate/notifier_url.go b/backend/internal/sys/validate/notifier_url.go
index 9f28f6b9..60d44502 100644
--- a/backend/internal/sys/validate/notifier_url.go
+++ b/backend/internal/sys/validate/notifier_url.go
@@ -51,6 +51,21 @@ func ValidateNotifierURL(notifierURL string, cfg *config.NotifierConf) error {
return fmt.Errorf("hostname did not resolve to any IP addresses")
}
+ // Expand DNS64-synthesized IPv6 addresses (RFC 6052) into their embedded
+ // IPv4 addresses so the allow/block rules below are applied to the IPv4
+ // destination the NAT64 gateway will actually reach. The original IPv6
+ // address stays in the list so IPv6 rules still apply to it.
+ checkIPs := make([]net.IP, 0, len(ips))
+ for _, ip := range ips {
+ checkIPs = append(checkIPs, ip)
+ embedded, inDNS64Range := dns64EmbeddedIPv4s(ip, cfg.Dns64Nets)
+ if inDNS64Range && len(embedded) == 0 {
+ return fmt.Errorf("IP %s is in a DNS64 range but no valid embedded IPv4 address could be extracted", ip.String())
+ }
+ checkIPs = append(checkIPs, embedded...)
+ }
+ ips = checkIPs
+
// If AllowNets is configured, only allow IPs in those networks
if len(cfg.AllowNets) > 0 {
for _, ip := range ips {
@@ -155,6 +170,102 @@ func extractGenericURL(notifierURL string) (string, error) {
return "", fmt.Errorf("not a generic notifier URL")
}
+// rfc6052PrefixLens are the prefix lengths at which RFC 6052 permits embedding
+// an IPv4 address into an IPv6 address.
+var rfc6052PrefixLens = []int{32, 40, 48, 56, 64, 96}
+
+// embeddedIPv4 extracts the IPv4 address embedded in ip using the RFC 6052
+// layout for the given prefix length. It returns nil if the address is not
+// well-formed at that layout: the "u" octet (bits 64-71) and the suffix bits
+// after the embedded address must both be zero.
+func embeddedIPv4(ip net.IP, prefixLen int) net.IP {
+ b := ip.To16()
+ if b == nil {
+ return nil
+ }
+
+ var v4 [4]byte
+ var suffix []byte
+ switch prefixLen {
+ case 32:
+ copy(v4[:], b[4:8])
+ suffix = b[9:]
+ case 40:
+ copy(v4[:3], b[5:8])
+ v4[3] = b[9]
+ suffix = b[10:]
+ case 48:
+ copy(v4[:2], b[6:8])
+ copy(v4[2:], b[9:11])
+ suffix = b[11:]
+ case 56:
+ v4[0] = b[7]
+ copy(v4[1:], b[9:12])
+ suffix = b[12:]
+ case 64:
+ copy(v4[:], b[9:13])
+ suffix = b[13:]
+ case 96:
+ copy(v4[:], b[12:16])
+ default:
+ return nil
+ }
+
+ if prefixLen < 96 && b[8] != 0 {
+ return nil
+ }
+ for _, sb := range suffix {
+ if sb != 0 {
+ return nil
+ }
+ }
+
+ return net.IPv4(v4[0], v4[1], v4[2], v4[3])
+}
+
+// dns64EmbeddedIPv4s returns the IPv4 addresses embedded in ip when it falls
+// inside one of the configured DNS64/NAT64 prefixes, along with whether the
+// address is inside any such prefix at all. A configured prefix may be shorter
+// than the prefix the NAT64 gateway actually translates with (e.g. the RFC 8215
+// 64:ff9b:1::/48 space holds deployment prefixes of /48 through /96), so every
+// RFC 6052 layout at or beyond the configured length is tried and all
+// well-formed extractions are returned for checking.
+func dns64EmbeddedIPv4s(ip net.IP, dns64Nets []string) ([]net.IP, bool) {
+ if ip.To4() != nil {
+ return nil, false
+ }
+
+ inRange := false
+ var candidates []net.IP
+ for _, dns64Net := range dns64Nets {
+ _, ipNet, err := net.ParseCIDR(dns64Net)
+ if err != nil {
+ log.Warn().
+ Err(err).
+ Str("cidr", dns64Net).
+ Str("config", "Dns64Nets").
+ Msg("invalid CIDR in notifier Dns64Nets configuration, skipping")
+ continue
+ }
+ if !ipNet.Contains(ip) {
+ continue
+ }
+ inRange = true
+
+ prefixLen, _ := ipNet.Mask.Size()
+ for _, layoutLen := range rfc6052PrefixLens {
+ if layoutLen < prefixLen {
+ continue
+ }
+ if v4 := embeddedIPv4(ip, layoutLen); v4 != nil {
+ candidates = append(candidates, v4)
+ }
+ }
+ }
+
+ return candidates, inRange
+}
+
// isLocalhost checks if an IP is a localhost address
func isLocalhost(ip net.IP) bool {
return ip.IsLoopback()
diff --git a/backend/internal/sys/validate/notifier_url_test.go b/backend/internal/sys/validate/notifier_url_test.go
index e3e09358..a05e8b4c 100644
--- a/backend/internal/sys/validate/notifier_url_test.go
+++ b/backend/internal/sys/validate/notifier_url_test.go
@@ -1,6 +1,7 @@
package validate
import (
+ "net"
"testing"
"github.com/sysadminsmedia/homebox/backend/internal/sys/config"
@@ -13,6 +14,9 @@ const (
urlGenericIPv4Local = "generic://http://192.168.1.100/webhook"
)
+// dns64DefaultNets mirrors the conf tag default for Dns64Nets.
+var dns64DefaultNets = []string{"64:ff9b::/96", "64:ff9b:1::/48"}
+
func TestValidateNotifierURL(t *testing.T) {
tests := []struct {
name string
@@ -294,6 +298,123 @@ func TestValidateNotifierURL(t *testing.T) {
},
expectError: false,
},
+ // DNS64 test cases
+ {
+ name: "dns64_embedded_cloud_metadata_blocked",
+ url: "generic://http://[64:ff9b::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ BlockCloudMetadata: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_embedded_cloud_metadata_blocked_by_bogon",
+ url: "generic://http://[64:ff9b::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ BlockBogonNets: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_embedded_private_ip_blocked",
+ url: "generic://http://[64:ff9b::c0a8:101]/webhook",
+ config: config.NotifierConf{
+ BlockLocalNets: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_embedded_localhost_blocked",
+ url: "generic://http://[64:ff9b::7f00:1]/webhook",
+ config: config.NotifierConf{
+ BlockLocalhost: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_embedded_public_ip_passes",
+ url: "generic://http://[64:ff9b::808:808]/webhook",
+ config: config.NotifierConf{
+ BlockLocalhost: true,
+ BlockLocalNets: true,
+ BlockBogonNets: true,
+ BlockCloudMetadata: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: false,
+ },
+ {
+ name: "dns64_local_use_prefix_embedded_metadata_blocked",
+ url: "generic://http://[64:ff9b:1::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ BlockCloudMetadata: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_local_use_deployment_specific_prefix_blocked",
+ url: "generic://http://[64:ff9b:1:abcd::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ BlockCloudMetadata: true,
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_custom_prefix_embedded_metadata_blocked",
+ url: "generic://http://[2001:db8:64::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ BlockCloudMetadata: true,
+ Dns64Nets: []string{"2001:db8:64::/96"},
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_embedded_ip_checked_against_block_nets",
+ url: "generic://http://[64:ff9b::c0a8:101]/webhook",
+ config: config.NotifierConf{
+ BlockNets: []string{cidrPrivate24},
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_allow_nets_requires_embedded_ip_allowed",
+ url: "generic://http://[64:ff9b::c0a8:101]/webhook",
+ config: config.NotifierConf{
+ AllowNets: []string{"64:ff9b::/96"},
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_allow_nets_passes_when_prefix_and_embedded_ip_allowed",
+ url: "generic://http://[64:ff9b::c0a8:101]/webhook",
+ config: config.NotifierConf{
+ AllowNets: []string{"64:ff9b::/96", cidrPrivate24},
+ Dns64Nets: dns64DefaultNets,
+ },
+ expectError: false,
+ },
+ {
+ name: "dns64_range_without_extractable_ipv4_fails_closed",
+ url: "generic://http://[64:ff9b::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{
+ Dns64Nets: []string{"64:ff9b::a9fe:a9fe/128"},
+ },
+ expectError: true,
+ },
+ {
+ name: "dns64_checks_disabled_when_no_nets_configured",
+ url: "generic://http://[64:ff9b::a9fe:a9fe]/webhook",
+ config: config.NotifierConf{BlockCloudMetadata: true},
+ expectError: false,
+ },
}
for _, tt := range tests {
@@ -388,6 +509,42 @@ func TestExtractGenericURL(t *testing.T) {
}
}
+func TestEmbeddedIPv4(t *testing.T) {
+ // Layout examples are taken from RFC 6052 section 2.4, all embedding 192.0.2.33.
+ tests := []struct {
+ name string
+ ip string
+ prefixLen int
+ expected string // empty means extraction must fail
+ }{
+ {"rfc6052_example_32", "2001:db8:c000:221::", 32, "192.0.2.33"},
+ {"rfc6052_example_40", "2001:db8:1c0:2:21::", 40, "192.0.2.33"},
+ {"rfc6052_example_48", "2001:db8:122:c000:2:2100::", 48, "192.0.2.33"},
+ {"rfc6052_example_56", "2001:db8:122:3c0:0:221::", 56, "192.0.2.33"},
+ {"rfc6052_example_64", "2001:db8:122:344:c0:2:2100::", 64, "192.0.2.33"},
+ {"rfc6052_example_96", "2001:db8:122:344::c000:221", 96, "192.0.2.33"},
+ {"well_known_prefix_96", "64:ff9b::a9fe:a9fe", 96, "169.254.169.254"},
+ {"nonzero_u_octet_rejected", "2001:db8:122:344:ffc0:2:2100::", 64, ""},
+ {"nonzero_suffix_rejected", "2001:db8:122:344:c0:2:2100:1", 64, ""},
+ {"unsupported_prefix_length", "64:ff9b::a9fe:a9fe", 128, ""},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := embeddedIPv4(net.ParseIP(tt.ip), tt.prefixLen)
+ if tt.expected == "" {
+ if result != nil {
+ t.Errorf("expected no extraction but got %v", result)
+ }
+ return
+ }
+ if result == nil || result.String() != tt.expected {
+ t.Errorf("expected %v but got %v", tt.expected, result)
+ }
+ })
+ }
+}
+
func TestValidateNotifierURL_InvalidCIDR_AllowNets(t *testing.T) {
// Test with invalid CIDR in AllowNets - should skip invalid and check valid ones
tests := []struct {
diff --git a/docs/src/content/docs/en/quick-start/configure/index.mdx b/docs/src/content/docs/en/quick-start/configure/index.mdx
index 071745c0..640a124a 100644
--- a/docs/src/content/docs/en/quick-start/configure/index.mdx
+++ b/docs/src/content/docs/en/quick-start/configure/index.mdx
@@ -87,12 +87,13 @@ import {Tabs, TabItem} from "@astrojs/starlight/components";
| HBOX_THUMBNAIL_HEIGHT | 500 | height for generated thumbnails in pixels |
| HBOX_BARCODE_TOKEN_BARCODESPIDER | | API token for BarcodeSpider.com service used for barcode product lookups. If not set, BarcodeSpider lookups will not be performed. |
| HBOX_BARCODE_OPEN_FOOD_FACTS_CONTACT | | Optional contact value included in the User-Agent for Open Food Facts, Open Beauty Facts, and Open Products Facts barcode lookups. This is sent to third-party APIs, so avoid secrets or personal PII and prefer a role/contact alias. |
-| HBOX_NOTIFIER_ALLOW_NETS | | comma-separated list of CIDR networks to allow for generic notifiers (e.g., `192.168.1.0/24,10.0.0.0/8`). If set, only these networks will be allowed and all block rules are bypassed. |
-| HBOX_NOTIFIER_BLOCK_NETS | | comma-separated list of CIDR networks to block for generic notifiers (e.g., `192.168.1.0/24,10.0.0.0/8`). Provides fine-grained blocking without enabling blanket rules. |
+| HBOX_NOTIFIER_ALLOW_NETS | | semicolon-separated list of CIDR networks to allow for generic notifiers (e.g., `192.168.1.0/24;10.0.0.0/8`). If set, only these networks will be allowed and all block rules are bypassed. |
+| HBOX_NOTIFIER_BLOCK_NETS | | semicolon-separated list of CIDR networks to block for generic notifiers (e.g., `192.168.1.0/24;10.0.0.0/8`). Provides fine-grained blocking without enabling blanket rules. |
| HBOX_NOTIFIER_BLOCK_LOCALHOST | false | block generic notifiers from sending to localhost/loopback addresses (127.0.0.1, ::1) |
| HBOX_NOTIFIER_BLOCK_LOCAL_NETS | false | block generic notifiers from sending to RFC1918 private networks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) |
| HBOX_NOTIFIER_BLOCK_BOGON_NETS | true | block generic notifiers from sending to bogon/reserved networks (link-local, multicast, broadcast, etc.) |
| HBOX_NOTIFIER_BLOCK_CLOUD_METADATA | true | block generic notifiers from sending to cloud metadata endpoints (169.254.169.254, fd00:ec2::254) |
+| HBOX_NOTIFIER_DNS64_NETS | 64:ff9b::/96;64:ff9b:1::/48 | semicolon-separated list of DNS64/NAT64 translation prefixes (RFC 6052). IPv6 addresses in these prefixes have their embedded IPv4 address extracted and checked against the allow/block rules, preventing DNS64-based SSRF bypasses. Override if your NAT64 deployment uses a custom prefix. |
| HBOX_OTEL_ENABLED | false | enable OpenTelemetry tracing. Standard OTEL_* env vars are also honored by the SDK in addition to these `HBOX_OTEL_*` options. |
| HBOX_OTEL_SERVICE_NAME | homebox | service name reported to the telemetry backend |
| HBOX_OTEL_SERVICE_VERSION | | service version reported to the telemetry backend (defaults to the build version when unset) |
@@ -166,6 +167,7 @@ OPTIONS
--notifier-block-cloud-metadata <bool> (default: true)
--notifier-block-local-nets <bool> (default: false)
--notifier-block-localhost <bool> (default: false)
+ --notifier-dns64-nets <string> (default: 64:ff9b::/96;64:ff9b:1::/48)
--oidc-allowed-groups <string>
--oidc-auto-redirect <bool> (default: false)
--oidc-button-text <string> (default: Sign in with OIDC)
diff --git a/docs/src/content/docs/en/user-guide/notifiers.mdx b/docs/src/content/docs/en/user-guide/notifiers.mdx
index 16bfb2b5..17e679cc 100644
--- a/docs/src/content/docs/en/user-guide/notifiers.mdx
+++ b/docs/src/content/docs/en/user-guide/notifiers.mdx
@@ -112,7 +112,7 @@ All security options apply only to generic webhook notifiers. Other notification
The most secure approach is to use an allow list. When configured, **only** the specified networks are allowed, and all block rules are bypassed.
```bash
-HBOX_NOTIFIER_ALLOW_NETS="192.168.1.0/24,10.0.50.0/24"
+HBOX_NOTIFIER_ALLOW_NETS="192.168.1.0/24;10.0.50.0/24"
```
**Use Case:** You have specific internal webhook endpoints at known IP ranges and want to only allow those.
@@ -181,7 +181,7 @@ HBOX_NOTIFIER_BLOCK_CLOUD_METADATA=true
Allows you to block specific network ranges using CIDR notation. This provides fine-grained control without needing to enable the blanket `BLOCK_LOCAL_NETS` or `BLOCK_BOGON_NETS` options.
```bash
-HBOX_NOTIFIER_BLOCK_NETS="192.168.1.0/24,172.16.0.0/12,10.10.0.0/16"
+HBOX_NOTIFIER_BLOCK_NETS="192.168.1.0/24;172.16.0.0/12;10.10.0.0/16"
```
**Default:** (empty, no networks blocked)
@@ -200,11 +200,31 @@ HBOX_NOTIFIER_BLOCK_NETS="192.168.1.100/32"
Block multiple networks:
```bash
-HBOX_NOTIFIER_BLOCK_NETS="192.168.0.0/16,172.16.0.0/12,10.10.0.0/16"
+HBOX_NOTIFIER_BLOCK_NETS="192.168.0.0/16;172.16.0.0/12;10.10.0.0/16"
```
**Note:** `HBOX_NOTIFIER_ALLOW_NETS` takes precedence over `HBOX_NOTIFIER_BLOCK_NETS`. If an IP is in the allow list, it will not be blocked even if it matches a network in the block list.
+#### DNS64 Prefixes
+
+On networks using DNS64/NAT64, hostnames resolve to IPv6 addresses with an IPv4 address embedded inside a translation prefix (RFC 6052). Without special handling, such an address would bypass all of the IPv4 rules above even though the NAT64 gateway ultimately delivers the request to the embedded IPv4 address — for example, `64:ff9b::a9fe:a9fe` is translated to `169.254.169.254`, the cloud metadata endpoint.
+
+Homebox extracts the embedded IPv4 address from any resolved IPv6 address that falls within a configured DNS64 prefix and validates it against all of the allow/block rules above, in addition to the original IPv6 address.
+
+```bash
+HBOX_NOTIFIER_DNS64_NETS="64:ff9b::/96;64:ff9b:1::/48"
+```
+
+**Default:** `64:ff9b::/96;64:ff9b:1::/48` (the RFC 6052 well-known prefix and the RFC 8215 local-use prefix)
+
+**Use Case:** If your network's NAT64 deployment uses a custom translation prefix instead of the well-known ones, set it here so the embedded IPv4 addresses are still validated:
+
+```bash
+HBOX_NOTIFIER_DNS64_NETS="2001:db8:64::/96"
+```
+
+**Note:** When using `HBOX_NOTIFIER_ALLOW_NETS` on a DNS64/NAT64 network, the allow list must contain both the DNS64 prefix itself and the IPv4 networks of your webhook endpoints, since every address (original and embedded) must be allowed.
+
### Recommended Security Configurations
#### Public Internet Deployment
@@ -223,7 +243,7 @@ HBOX_NOTIFIER_BLOCK_CLOUD_METADATA=true
For internal deployments where you want to allow specific webhook endpoints:
```bash
-HBOX_NOTIFIER_ALLOW_NETS="192.168.1.100/32,10.0.20.0/24"
+HBOX_NOTIFIER_ALLOW_NETS="192.168.1.100/32;10.0.20.0/24"
```
Note: When using the allow list, all block rules are bypassed. Only the specified networks will be permitted.
@@ -233,7 +253,7 @@ Note: When using the allow list, all block rules are bypassed. Only the specifie
For environments where you want to block specific networks without blocking all private networks:
```bash
-HBOX_NOTIFIER_BLOCK_NETS="192.168.1.0/24,10.10.0.0/16"
+HBOX_NOTIFIER_BLOCK_NETS="192.168.1.0/24;10.10.0.0/16"
HBOX_NOTIFIER_BLOCK_LOCALHOST=true
HBOX_NOTIFIER_BLOCK_BOGON_NETS=true
HBOX_NOTIFIER_BLOCK_CLOUD_METADATA=true