Skip to content

Commit 0475e67

Browse files
authored
Only applying angled brackets to sip: uris. (#1247)
1 parent 5552d64 commit 0475e67

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

livekit/sip.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,21 +700,29 @@ func (p *TransferSIPParticipantRequest) Validate() error {
700700
}
701701

702702
// Validate TransferTo URI format and ensure RFC compliance
703-
var uriToValidate string
703+
var innerURI string
704704
if strings.HasPrefix(p.TransferTo, "<") && strings.HasSuffix(p.TransferTo, ">") {
705705
// Extract inner URI for validation
706-
uriToValidate = p.TransferTo[1 : len(p.TransferTo)-1]
706+
innerURI = p.TransferTo[1 : len(p.TransferTo)-1]
707707
} else {
708-
uriToValidate = p.TransferTo
708+
innerURI = p.TransferTo
709709
}
710710

711-
if !strings.HasPrefix(uriToValidate, "sip:") && !strings.HasPrefix(uriToValidate, "tel:") {
711+
if !strings.HasPrefix(innerURI, "sip:") && !strings.HasPrefix(innerURI, "tel:") {
712+
// In theory the Refer-To header can receive the full name-addr.
713+
// This can make this check inaccurate, but we want to limit to just SIP and TEL URIs.
712714
return errors.New("transfer_to must be a valid SIP or TEL URI (sip: or tel:)")
713715
}
714716

715-
// Ensure RFC compliance by wrapping in angle brackets if not already wrapped
716-
if !strings.HasPrefix(p.TransferTo, "<") || !strings.HasSuffix(p.TransferTo, ">") {
717-
p.TransferTo = fmt.Sprintf("<%s>", p.TransferTo)
717+
if strings.HasPrefix(innerURI, "sip:") {
718+
// addr-spec = sip:...
719+
// name-addr = [ display-name ] <addr-spec>
720+
// Both name-addr and addr-spec are allowed in RFC3515 (section-2.1).
721+
// However, name-addr is more premissive and widely-supported, so we convert.
722+
p.TransferTo = fmt.Sprintf("<%s>", innerURI)
723+
} else {
724+
// tel: URIs are not explicitly allowed in spec, but are generally supported.
725+
p.TransferTo = innerURI
718726
}
719727

720728
if err := validateHeaderKeys(p.Headers); err != nil {

livekit/sip_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func TestTransferSIPParticipantRequestValidate(t *testing.T) {
387387
TransferTo: "tel:+15105550100",
388388
},
389389
expectError: false,
390-
expectedURI: "<tel:+15105550100>",
390+
expectedURI: "tel:+15105550100",
391391
},
392392
{
393393
name: "valid sip URI with brackets",
@@ -407,7 +407,7 @@ func TestTransferSIPParticipantRequestValidate(t *testing.T) {
407407
TransferTo: "<tel:+15105550100>",
408408
},
409409
expectError: false,
410-
expectedURI: "<tel:+15105550100>",
410+
expectedURI: "tel:+15105550100",
411411
},
412412
{
413413
name: "invalid URI - http",
@@ -520,7 +520,7 @@ func TestTransferSIPParticipantRequestValidate(t *testing.T) {
520520
TransferTo: "tel:+1234567890;ext=123",
521521
},
522522
expectError: false,
523-
expectedURI: "<tel:+1234567890;ext=123>",
523+
expectedURI: "tel:+1234567890;ext=123",
524524
},
525525
{
526526
name: "tel URI with parameters",
@@ -530,7 +530,7 @@ func TestTransferSIPParticipantRequestValidate(t *testing.T) {
530530
TransferTo: "tel:+1234567890;phone-context=example.com",
531531
},
532532
expectError: false,
533-
expectedURI: "<tel:+1234567890;phone-context=example.com>",
533+
expectedURI: "tel:+1234567890;phone-context=example.com",
534534
},
535535
{
536536
name: "sip URI with headers",

0 commit comments

Comments
 (0)