sip: reject invalid allowed_addresses on inbound trunk create and update (#5200)

* sip: reject invalid allowed_addresses on inbound trunk create and update

* Bump protocol.

* Bump protocol again.
This commit is contained in:
Alex Fish authored and GitHub committed 2026-11-13 11:53:24 -08:00
1 parent 0f229742cd
commit cceef27427
4 files changed
+103 -7

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ require (
github.com/jxskiss/base62 v1.1.0
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731
github.com/livekit/mediatransportutil v0.0.0-20261105133908-2cf1b1487796
github.com/livekit/protocol v1.53.3-0.20261112053547-ab952f4c4ae9
github.com/livekit/protocol v1.54.1-0.20261113191342-ebef16fe6043
github.com/livekit/psrpc v0.8.2
github.com/mackerelio/go-osstat v0.2.8
github.com/magefile/mage v1.17.2
+2 -2
View File
@@ -164,8 +164,8 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20261105133908-2cf1b1487796 h1:Ywn57x0LFvbUbHFV1gESlPA/4u8FHIpuEJIwQH3CQZA=
github.com/livekit/mediatransportutil v0.0.0-20261105133908-2cf1b1487796/go.mod h1:/T+BvdqiQN7mYJJk5EFFqbdbe7yBAvR8Ilx5kMVzT4M=
github.com/livekit/protocol v1.53.3-0.20261112053547-ab952f4c4ae9 h1:+IL5kQtS8Ayl1jh3U94Pp6Gr85Wp3yZ5+1TCZKbcKyI=
github.com/livekit/protocol v1.53.3-0.20261112053547-ab952f4c4ae9/go.mod h1:S0AnW03n6zgnWZOq+T4L1PtT9POxTBgrgEH1jyR6fl4=
github.com/livekit/protocol v1.54.1-0.20261113191342-ebef16fe6043 h1:js8lQguWyO2HK42mQM7mZJDzSw4H9dySeMjoQAwb5Rw=
github.com/livekit/protocol v1.54.1-0.20261113191342-ebef16fe6043/go.mod h1:S0AnW03n6zgnWZOq+T4L1PtT9POxTBgrgEH1jyR6fl4=
github.com/livekit/psrpc v0.8.2 h1:7tbkhBJoYlK5Csfkdv1XYbZjyAQeaEZgupvIXNCv7Dc=
github.com/livekit/psrpc v0.8.2/go.mod h1:6KnU8vULoizX0Er9NNfeKJDV8ug87j3fuo19M0bhj6Q=
github.com/livekit/webrtc-pion/v4 v4.2.25-warp.3 h1:n6Rctm2NI+YuAZlAuI0yDw+ZmazAIcol6sjeeTqU32I=
+6 -4
View File
@@ -129,7 +129,7 @@ func (s *SIPService) CreateSIPInboundTrunk(ctx context.Context, req *livekit.Cre
if s.store == nil {
return nil, ErrSIPNotConnected
}
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
if err := req.ValidateResultAddresses().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
}
@@ -197,7 +197,7 @@ func (s *SIPService) UpdateSIPInboundTrunk(ctx context.Context, req *livekit.Upd
if s.store == nil {
return nil, ErrSIPNotConnected
}
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
if err := req.ValidateResultAddresses().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
}
@@ -221,10 +221,12 @@ func (s *SIPService) UpdateSIPInboundTrunk(ctx context.Context, req *livekit.Upd
default:
return nil, errors.New("missing or unsupported action")
case livekit.UpdateSIPInboundTrunkRequestAction:
// Only the allowed_addresses entries the update sets or adds must be valid,
// so trunks that already have invalid entries can still be edited.
var result livekit.ValidationResult
info, result = a.ApplyResult(info)
info, result = a.ApplyResultAddresses(info)
if err := result.LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
return nil, err
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
}
}
if err := validateInboundNumbersNoURI(info.Numbers, prevNumbers); err != nil {
+94
View File
@@ -186,6 +186,100 @@ func TestSIPInboundTrunkRejectsURINumbers(t *testing.T) {
})
}
func TestSIPInboundTrunkAllowedAddressValidation(t *testing.T) {
ctx, s, rs := newTestSIPService(t)
create := func(number string, addrs ...string) (*livekit.SIPInboundTrunkInfo, error) {
return s.CreateSIPInboundTrunk(ctx, &livekit.CreateSIPInboundTrunkRequest{
Trunk: &livekit.SIPInboundTrunkInfo{Name: "trunk", Numbers: []string{number}, AllowedAddresses: addrs},
})
}
update := func(id string, u *livekit.SIPInboundTrunkUpdate) (*livekit.SIPInboundTrunkInfo, error) {
return s.UpdateSIPInboundTrunk(ctx, &livekit.UpdateSIPInboundTrunkRequest{
SipTrunkId: id,
Action: &livekit.UpdateSIPInboundTrunkRequest_Update{Update: u},
})
}
addAddress := func(addr string) *livekit.SIPInboundTrunkUpdate {
return &livekit.SIPInboundTrunkUpdate{AllowedAddresses: &livekit.ListUpdate{Add: []string{addr}}}
}
requireInvalidAddress := func(t *testing.T, err error) {
t.Helper()
requireInvalidArgument(t, err)
require.ErrorContains(t, err, "invalid allowed address")
}
t.Run("create", func(t *testing.T) {
for _, addr := range []string{"sip.twilio.com", "*", "192.0.2.10:5060", "[2001:db8::1]"} {
_, err := create("+15550004001", "192.0.2.10", addr)
requireInvalidAddress(t, err)
}
tr, err := create("+15550004002", "192.0.2.10", "192.0.2.0/24", "2001:db8::/32")
require.NoError(t, err)
require.Equal(t, []string{"192.0.2.10", "192.0.2.0/24", "2001:db8::/32"}, tr.AllowedAddresses)
})
t.Run("update", func(t *testing.T) {
tr, err := create("+15550004003", "192.0.2.10")
require.NoError(t, err)
_, err = update(tr.SipTrunkId, addAddress("sip.twilio.com"))
requireInvalidAddress(t, err)
_, err = update(tr.SipTrunkId, &livekit.SIPInboundTrunkUpdate{
AllowedAddresses: &livekit.ListUpdate{Set: []string{"192.0.2.10", "sip.twilio.com"}},
})
requireInvalidAddress(t, err)
_, err = s.UpdateSIPInboundTrunk(ctx, &livekit.UpdateSIPInboundTrunkRequest{
SipTrunkId: tr.SipTrunkId,
Action: &livekit.UpdateSIPInboundTrunkRequest_Replace{Replace: &livekit.SIPInboundTrunkInfo{
Name: "replace",
Numbers: tr.Numbers,
AllowedAddresses: []string{"sip.twilio.com"},
}},
})
requireInvalidAddress(t, err)
info, err := update(tr.SipTrunkId, addAddress("2001:db8::1"))
require.NoError(t, err)
require.Equal(t, []string{"192.0.2.10", "2001:db8::1"}, info.AllowedAddresses)
})
t.Run("stored trunk with an invalid entry", func(t *testing.T) {
id := guid.New(utils.SIPTrunkPrefix)
require.NoError(t, rs.StoreSIPInboundTrunk(ctx, &livekit.SIPInboundTrunkInfo{
SipTrunkId: id,
Name: "legacy",
Numbers: []string{"+15550004004"},
AllowedAddresses: []string{"192.0.2.10", "sip.twilio.com"},
}))
// Updates that don't add invalid entries keep the existing one.
info, err := update(id, &livekit.SIPInboundTrunkUpdate{Name: proto.String("renamed")})
require.NoError(t, err)
require.Equal(t, "renamed", info.Name)
require.Equal(t, []string{"192.0.2.10", "sip.twilio.com"}, info.AllowedAddresses)
info, err = update(id, addAddress("192.0.2.11"))
require.NoError(t, err)
require.Equal(t, []string{"192.0.2.10", "sip.twilio.com", "192.0.2.11"}, info.AllowedAddresses)
_, err = update(id, addAddress("sip.telnyx.com"))
requireInvalidAddress(t, err)
info, err = update(id, &livekit.SIPInboundTrunkUpdate{
AllowedAddresses: &livekit.ListUpdate{Remove: []string{"sip.twilio.com"}},
})
require.NoError(t, err)
require.Equal(t, []string{"192.0.2.10", "192.0.2.11"}, info.AllowedAddresses)
stored, err := rs.LoadSIPInboundTrunk(ctx, id)
require.NoError(t, err)
require.Equal(t, []string{"192.0.2.10", "192.0.2.11"}, stored.AllowedAddresses)
})
}
func TestCreateSIPParticipantSourceCallUnsupported(t *testing.T) {
req := &livekit.CreateSIPParticipantRequest{SipSourceCallId: "SCL_1"}