Skip to content

Commit 9eb0489

Browse files
authored
Relax header validation for SIP. (#925)
1 parent bc38834 commit 9eb0489

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

.changeset/proud-boats-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"github.com/livekit/protocol": patch
3+
---
4+
5+
Relax SIP header validation.

livekit/sip.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package livekit
33
import (
44
"errors"
55
"fmt"
6+
"regexp"
67
"slices"
78
"strings"
89
)
@@ -102,10 +103,11 @@ func (p *SIPOutboundTrunkInfo) AsTrunkInfo() *SIPTrunkInfo {
102103
}
103104
}
104105

106+
var reHeaders = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-]*$`)
107+
105108
func validateHeader(header string) error {
106-
v := strings.ToLower(header)
107-
if !strings.HasPrefix(v, "x-") {
108-
return fmt.Errorf("only X-* headers are allowed: %s", header)
109+
if !reHeaders.MatchString(header) {
110+
return fmt.Errorf("invalid header name: %q", header)
109111
}
110112
return nil
111113
}

livekit/sip_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ func TestSIPValidate(t *testing.T) {
9191
"From": "from",
9292
},
9393
},
94+
exp: true,
95+
},
96+
{
97+
name: "inbound invalid header",
98+
req: &SIPInboundTrunkInfo{
99+
Numbers: []string{"+1111"},
100+
HeadersToAttributes: map[string]string{
101+
"From ": "from",
102+
},
103+
},
94104
exp: false,
95105
},
96106
{
@@ -165,6 +175,17 @@ func TestSIPValidate(t *testing.T) {
165175
"From": "from",
166176
},
167177
},
178+
exp: true,
179+
},
180+
{
181+
name: "outbound invalid header",
182+
req: &SIPOutboundTrunkInfo{
183+
Address: "sip.example.com",
184+
Numbers: []string{"+2222"},
185+
HeadersToAttributes: map[string]string{
186+
"From ": "from",
187+
},
188+
},
168189
exp: false,
169190
},
170191
}

0 commit comments

Comments
 (0)