Make sure room ids for dial-out are numeric.

This commit is contained in:
Joachim Bauch 2023-10-25 14:33:45 +02:00
parent fdb4d74dd6
commit e333ddfd53
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 40 additions and 0 deletions

View file

@ -36,6 +36,7 @@ import (
"net/http"
"net/url"
"reflect"
"regexp"
"strings"
"sync"
"sync/atomic"
@ -669,11 +670,21 @@ func returnDialoutError(status int, err *Error) (any, error) {
return response, nil
}
var checkNumeric = regexp.MustCompile(`^[0-9]+$`)
func isNumeric(s string) bool {
return checkNumeric.MatchString(s)
}
func (b *BackendServer) startDialout(roomid string, backend *Backend, request *BackendServerRoomRequest) (any, error) {
if err := request.Dialout.ValidateNumber(); err != nil {
return returnDialoutError(http.StatusBadRequest, err)
}
if !isNumeric(roomid) {
return returnDialoutError(http.StatusBadRequest, NewError("invalid_roomid", "The room id must be numeric."))
}
var session *ClientSession
for s := range b.hub.dialoutSessions {
if s.GetClient() != nil {

View file

@ -1760,3 +1760,32 @@ func TestBackendServer_StatsAllowedIps(t *testing.T) {
})
}
}
func Test_IsNumeric(t *testing.T) {
numeric := []string{
"0",
"1",
"12345",
}
nonNumeric := []string{
"",
" ",
" 0",
"0 ",
" 0 ",
"-1",
"1.2",
"1a",
"a1",
}
for _, s := range numeric {
if !isNumeric(s) {
t.Errorf("%s should be numeric", s)
}
}
for _, s := range nonNumeric {
if isNumeric(s) {
t.Errorf("%s should not be numeric", s)
}
}
}