ingress: check reserved and IPv4-embedding ranges for URL pull hosts

Also reject 198.18.0.0/15 and 240.0.0.0/4. For NAT64 (64:ff9b::/96)
and 6to4 (2002::/16) addresses, check the embedded IPv4 address instead
of the IPv6 one, so a public source reached through NAT64 still works
while an internal one is rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pradeep SharmaandClaude Opus 5.5 committed 2026-11-16 16:05:55 -08:00
1 parent 5a992e5a22
commit dbfafc1fdb
5 files changed
+39 -7

No files matched your search

+2 -1
View File
@@ -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
+2 -1
View File
@@ -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"`
}
-1
View File
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package service
import (
+23 -4
View File
@@ -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
}
+12
View File
@@ -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)