Validate the right username
3ad12b6added username validation, but only validated the username provided as part of the join event. When joining with an external token, the username needs to be loaded from the token instead. This broke in two ways: - in the default UI, the username would be passed in as "" with token auth, which failed validation even if the token was valid - you could pass in a valid username in the join event, and then pass in an invalid one in the token, and that would be accepted and used, presumably allowing for the same shenanigans3ad12b6sought to prevent Move username validation to the end, where we know what the right username is.
This commit is contained in:
1 parent
377ab0efcf
commit
d129fd54ac
1 file changed
+6
-5
+6
-5
@@ -1029,11 +1029,6 @@ func validUsername(username string) bool {
|
||||
|
||||
// called locked
|
||||
func (g *Group) getPermission(creds ClientCredentials) (string, []string, error) {
|
||||
if creds.Username != nil && !validUsername(*creds.Username) {
|
||||
return "", nil, &NotAuthorisedError{
|
||||
errors.New("invalid username"),
|
||||
}
|
||||
}
|
||||
desc := g.description
|
||||
var username string
|
||||
var perms []string
|
||||
@@ -1070,6 +1065,12 @@ func (g *Group) getPermission(creds ClientCredentials) (string, []string, error)
|
||||
return "", nil, errors.New("neither username nor token provided")
|
||||
}
|
||||
|
||||
if !validUsername(username) {
|
||||
return "", nil, &NotAuthorisedError{
|
||||
errors.New("invalid username"),
|
||||
}
|
||||
}
|
||||
|
||||
return username, perms, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user