File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " github.com/livekit/protocol " : patch
3+ ---
4+
5+ Relax SIP header validation.
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package livekit
33import (
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+
105108func 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}
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments