diff --git a/.changeset/proud-boats-clean.md b/.changeset/proud-boats-clean.md new file mode 100644 index 00000000..1c66487b --- /dev/null +++ b/.changeset/proud-boats-clean.md @@ -0,0 +1,5 @@ +--- +"github.com/livekit/protocol": patch +--- + +Relax SIP header validation. diff --git a/livekit/sip.go b/livekit/sip.go index f0ad4e1b..3da2888c 100644 --- a/livekit/sip.go +++ b/livekit/sip.go @@ -3,6 +3,7 @@ package livekit import ( "errors" "fmt" + "regexp" "slices" "strings" ) @@ -102,10 +103,11 @@ func (p *SIPOutboundTrunkInfo) AsTrunkInfo() *SIPTrunkInfo { } } +var reHeaders = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-]*$`) + func validateHeader(header string) error { - v := strings.ToLower(header) - if !strings.HasPrefix(v, "x-") { - return fmt.Errorf("only X-* headers are allowed: %s", header) + if !reHeaders.MatchString(header) { + return fmt.Errorf("invalid header name: %q", header) } return nil } diff --git a/livekit/sip_test.go b/livekit/sip_test.go index 6c51b586..5dde6c7d 100644 --- a/livekit/sip_test.go +++ b/livekit/sip_test.go @@ -91,6 +91,16 @@ func TestSIPValidate(t *testing.T) { "From": "from", }, }, + exp: true, + }, + { + name: "inbound invalid header", + req: &SIPInboundTrunkInfo{ + Numbers: []string{"+1111"}, + HeadersToAttributes: map[string]string{ + "From ": "from", + }, + }, exp: false, }, { @@ -165,6 +175,17 @@ func TestSIPValidate(t *testing.T) { "From": "from", }, }, + exp: true, + }, + { + name: "outbound invalid header", + req: &SIPOutboundTrunkInfo{ + Address: "sip.example.com", + Numbers: []string{"+2222"}, + HeadersToAttributes: map[string]string{ + "From ": "from", + }, + }, exp: false, }, }