-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax header validation for SIP. #925
Conversation
🦋 Changeset detectedLatest commit: 5f4c748 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR 💥 An error occurred when fetching the changed packages and changesets in this PR
|
111a120
to
c6d94e6
Compare
livekit/sip.go
Outdated
if strings.ContainsFunc(header, func(r rune) bool { | ||
if r >= 'a' && r <= 'z' { | ||
return false | ||
} else if r >= 'A' && r <= 'Z' { | ||
return false | ||
} else if r >= '0' && r <= '9' { | ||
return false | ||
} | ||
switch r { | ||
case '-': | ||
return false | ||
} | ||
return true | ||
}) { | ||
return fmt.Errorf("invalid header name: %q", header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace it by sth. like:
if !regexp.MustCompile(`^[a-zA-Z0-9\-]*$`).MatchString(header) {
return fmt.Errorf("invalid header name: %q", header)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. I suppose the number full of -
(e.g. -------
) is also incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, switched to regexp. Full header validation is out of scope - SIP itself will drop invalid headers during parsing. This is just a best-effort validation to prevent typos.
c6d94e6
to
5f4c748
Compare
Since #920 is merged, we now allow mapping any SIP headers to attributes. Thus, do not enforce
headers_to_attributes
map to only containX-*
headers. While at it - properly validate header names.