Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tidy-hounds-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"github.com/livekit/protocol": patch
"@livekit/protocol": patch
---

sip: fix panic in EvaluateDispatchRule on an empty From user part
3 changes: 2 additions & 1 deletion sip/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,8 @@ func EvaluateDispatchRule(projectID string, trunk *livekit.SIPInboundTrunkInfo,
// TODO: Maybe keep regional code, but mask all but 4 last digits?
n := 4
if len(from) <= 4 {
n = 1
// User part comes from the INVITE and may be empty.
n = min(1, len(from))
}
from = from[len(from)-n:]
fromName = "Phone " + from
Expand Down
24 changes: 24 additions & 0 deletions sip/sip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,30 @@ func TestEvaluateDispatchRule(t *testing.T) {
}
require.True(t, proto.Equal(exp, res), "%v\nvs\n%v", exp, res)
})
t.Run("HidePhoneNumber", func(t *testing.T) {
// Masking slices the From user part, which may be empty.
d := &livekit.SIPDispatchRuleInfo{
SipDispatchRuleId: "rule",
Rule: newDirectDispatch("room", ""),
HidePhoneNumber: true,
}
for _, c := range []struct{ from, exp string }{
{"", ""},
{"1", "1"},
{"1234", "4"},
{"12345", "2345"},
{caller, "4567"},
} {
r := &rpc.EvaluateSIPDispatchRulesRequest{
SipCallId: "call-id",
CallingNumber: c.from,
CalledNumber: callee,
}
res, err := EvaluateDispatchRule(projectID, tr, d, r)
require.NoError(t, err, "from %q", c.from)
require.Equal(t, "Phone "+c.exp, res.ParticipantName, "from %q", c.from)
}
})
t.Run("Individual", func(t *testing.T) {
t.Run("minimal", func(t *testing.T) {
testDR := livekit.SIPDispatchRuleInfo{
Expand Down
Loading