diff --git a/config-sample.yaml b/config-sample.yaml index 0310c16ec..e4ab9dbee 100644 --- a/config-sample.yaml +++ b/config-sample.yaml @@ -403,7 +403,8 @@ keys: # # room, using the ingress as a relay for streams on the handler's local network. # enable_udp_url_pull: false # # Allow http, https and srt URL pull ingresses whose host is, or resolves to, a loopback, private, -# # link-local, CGNAT, unspecified or multicast address. Disabled by default. +# # link-local, CGNAT, reserved, unspecified or multicast address, including one embedded in a NAT64 +# # or 6to4 address. Disabled by default. # allow_private_url_pull: false # Region of the current node. Required if using regionaware node selector diff --git a/pkg/config/config.go b/pkg/config/config.go index 88e18ff99..65c3b3d12 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -545,7 +545,8 @@ type IngressConfig struct { // no direct access to. EnableUDPURLPull bool `yaml:"enable_udp_url_pull,omitempty"` // Allow http, https and srt URL pull ingresses whose host is, or resolves to, a loopback, - // private, link-local, CGNAT, unspecified or multicast address. Disabled by default. + // private, link-local, CGNAT, reserved, unspecified or multicast address, including one embedded + // in a NAT64 or 6to4 address. Disabled by default. AllowPrivateURLPull bool `yaml:"allow_private_url_pull,omitempty"` } diff --git a/pkg/service/export_test.go b/pkg/service/export_test.go index fb9f38028..2400a946a 100644 --- a/pkg/service/export_test.go +++ b/pkg/service/export_test.go @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - package service import ( diff --git a/pkg/service/ingress.go b/pkg/service/ingress.go index 62204087f..1bd695f82 100644 --- a/pkg/service/ingress.go +++ b/pkg/service/ingress.go @@ -439,7 +439,15 @@ func (s *IngressService) DeleteIngress(ctx context.Context, req *livekit.DeleteI var lookupNetIP = net.DefaultResolver.LookupNetIP -var cgnatPrefix = netip.MustParsePrefix("100.64.0.0/10") +var ( + blockedPrefixes = []netip.Prefix{ + netip.MustParsePrefix("100.64.0.0/10"), + netip.MustParsePrefix("198.18.0.0/15"), + netip.MustParsePrefix("240.0.0.0/4"), + } + nat64Prefix = netip.MustParsePrefix("64:ff9b::/96") + sixToFourPrefix = netip.MustParsePrefix("2002::/16") +) func checkURLPullHost(ctx context.Context, host string) error { host = strings.ToLower(strings.TrimSuffix(host, ".")) @@ -461,10 +469,21 @@ func checkURLPullHost(ctx context.Context, host string) error { func isPublicAddr(addr netip.Addr) bool { addr = addr.Unmap() + if a := addr.As16(); nat64Prefix.Contains(addr) { + addr = netip.AddrFrom4([4]byte(a[12:16])) + } else if sixToFourPrefix.Contains(addr) { + addr = netip.AddrFrom4([4]byte(a[2:6])) + } if addr.Is4() && addr.As4()[0] == 0 { return false } - return addr.IsGlobalUnicast() && - !addr.IsPrivate() && - !cgnatPrefix.Contains(addr) + if !addr.IsGlobalUnicast() || addr.IsPrivate() { + return false + } + for _, p := range blockedPrefixes { + if p.Contains(addr) { + return false + } + } + return true } diff --git a/pkg/service/ingress_test.go b/pkg/service/ingress_test.go index 7a7869d6e..8ad9fb592 100644 --- a/pkg/service/ingress_test.go +++ b/pkg/service/ingress_test.go @@ -189,6 +189,14 @@ func TestCreateURLPullIngressHost(t *testing.T) { "http://[::ffff:10.0.0.1]/live", "http://[::ffff:100.64.0.1]/live", "http://[::ffff:0.1.2.3]/live", + "http://198.18.0.1/live", + "http://198.19.255.254/live", + "http://240.0.0.1/live", + "http://[64:ff9b::a9fe:a9fe]/live", + "http://[64:ff9b::7f00:1]/live", + "http://[64:ff9b::a00:1]/live", + "http://[2002:a9fe:a9fe::1]/live", + "http://[2002:7f00:1::]/live", "http://internal.example/live", "http://mixed.example/live", "http://unresolvable.example/live", @@ -213,6 +221,10 @@ func TestCreateURLPullIngressHost(t *testing.T) { "http://[2606:2800:21f:cb07:6820:80da:af6b:8b2c]/live", "srt://public.example:9000", "http://100.128.0.1/live", + "http://198.20.0.1/live", + "http://223.255.255.254/live", + "http://[64:ff9b::5db8:d70e]/live", + "http://[2002:5db8:d70e::1]/live", } { svc, _ := newService(false) info, err := create(svc, url)