Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/sip-encrypted-header-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"github.com/livekit/protocol": patch
---

Allow SIP header values with the `lkenc:` prefix up to 8192 characters, so that encrypted header values pass validation
16 changes: 14 additions & 2 deletions livekit/sip_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ func ValidateHeaderName(name string, restrictNames bool) error {
return nil
}

// EncryptedHeaderValuePrefix marks a header value that was encrypted.
const EncryptedHeaderValuePrefix = "lkenc:"

const (
maxHeaderValueLen = 1024
maxEncryptedHeaderValueLen = 8192
)

// ValidateHeaderValue validates a SIP header value per RFC 3261 Section 25.1
func ValidateHeaderValue(name, value string) error {
return ValidateHeaderValueResult(name, value).Error()
Expand All @@ -257,8 +265,12 @@ func ValidateHeaderValueResult(name, value string) ValidationResult {
return ValidationResult{}
}

if len(value) > 1024 {
return ValidationFailure(fmt.Errorf("header %s: value too long (max 1024 characters)", name))
maxLen := maxHeaderValueLen
if strings.HasPrefix(value, EncryptedHeaderValuePrefix) {
maxLen = maxEncryptedHeaderValueLen
}
if len(value) > maxLen {
return ValidationFailure(fmt.Errorf("header %s: value too long (max %d characters)", name, maxLen))
}

// Basic character validation - printable ASCII. We're stricter than the spec here - no UTF-8 for now
Expand Down
2 changes: 2 additions & 0 deletions livekit/sip_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var ValidHeaderValues = []string{
"Header with unicode 世界", // Unicode
"Header with unicode émojis 🎉", // Unicode with emojis
strings.Repeat("a", 1024), // max length
EncryptedHeaderValuePrefix + strings.Repeat("a", 8192-len(EncryptedHeaderValuePrefix)), // encrypted max length
}

// Note: These restrictions are NOT in RFC 3261 but are applied for security/performance
Expand All @@ -111,6 +112,7 @@ var InvalidHeaderValues = []string{
"Header with\x1Funit separator", // control character
"Header with\x7Fdelete", // delete character
strings.Repeat("a", 1025), // too long
EncryptedHeaderValuePrefix + strings.Repeat("a", 8193-len(EncryptedHeaderValuePrefix)), // encrypted too long
}

// testCaseName truncates a test case name to maxLen and adds dots with total size
Expand Down
Loading