MM_22682_Centralize_ID_Validation (#14237)

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Shibasis Patel
2020-05-07 22:57:35 +05:30
коммит произвёл GitHub
родитель ef5ac519d9
Коммит 882b0324b5
36 изменённых файлов: 93 добавлений и 93 удалений

Просмотреть файл

@@ -428,7 +428,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
for _, id := range userIds {
if len(id) != 26 {
if !model.IsValidId(id) {
c.SetInvalidParam("user_id")
return
}
@@ -507,7 +507,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
found := false
for _, id := range userIds {
if len(id) != 26 {
if !model.IsValidId(id) {
c.SetInvalidParam("user_id")
return
}
@@ -774,7 +774,7 @@ func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Re
}
for _, cid := range channelIds {
if len(cid) != 26 {
if !model.IsValidId(cid) {
c.SetInvalidParam("channel_id")
return
}
@@ -1359,7 +1359,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
userId, ok := props["user_id"].(string)
if !ok || len(userId) != 26 {
if !ok || !model.IsValidId(userId) {
c.SetInvalidParam("user_id")
return
}
@@ -1370,7 +1370,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
postRootId, ok := props["post_root_id"].(string)
if ok && len(postRootId) != 0 && len(postRootId) != 26 {
if ok && len(postRootId) != 0 && !model.IsValidId(postRootId) {
c.SetInvalidParam("post_root_id")
return
}
@@ -1539,7 +1539,7 @@ func updateChannelScheme(c *Context, w http.ResponseWriter, r *http.Request) {
}
schemeID := model.SchemeIDFromJson(r.Body)
if schemeID == nil || len(*schemeID) != 26 {
if schemeID == nil || !model.IsValidId(*schemeID) {
c.SetInvalidParam("scheme_id")
return
}
@@ -1606,7 +1606,7 @@ func channelMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.
groupIDs := []string{}
for _, gid := range strings.Split(c.Params.GroupIDs, ",") {
if len(gid) != 26 {
if !model.IsValidId(gid) {
c.SetInvalidParam("group_ids")
return
}

Просмотреть файл

@@ -296,7 +296,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(commandArgs.Command) <= 1 || strings.Index(commandArgs.Command, "/") != 0 || len(commandArgs.ChannelId) != 26 {
if len(commandArgs.Command) <= 1 || strings.Index(commandArgs.Command, "/") != 0 || !model.IsValidId(commandArgs.ChannelId) {
c.Err = model.NewAppError("executeCommand", "api.command.execute_command.start.app_error", nil, "", http.StatusBadRequest)
return
}

Просмотреть файл

@@ -23,7 +23,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(reaction.UserId) != 26 || len(reaction.PostId) != 26 || len(reaction.EmojiName) == 0 || len(reaction.EmojiName) > model.EMOJI_NAME_MAX_LENGTH {
if !model.IsValidId(reaction.UserId) || !model.IsValidId(reaction.PostId) || len(reaction.EmojiName) == 0 || len(reaction.EmojiName) > model.EMOJI_NAME_MAX_LENGTH {
c.Err = model.NewAppError("saveReaction", "api.reaction.save_reaction.invalid.app_error", nil, "", http.StatusBadRequest)
return
}

Просмотреть файл

@@ -570,7 +570,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(member.UserId) != 26 {
if !model.IsValidId(member.UserId) {
c.SetInvalidParam("user_id")
return
}
@@ -737,7 +737,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(member.UserId) != 26 {
if !model.IsValidId(member.UserId) {
c.SetInvalidParam("user_id")
return
}
@@ -1447,7 +1447,7 @@ func updateTeamScheme(c *Context, w http.ResponseWriter, r *http.Request) {
}
schemeID := model.SchemeIDFromJson(r.Body)
if schemeID == nil || (len(*schemeID) != 26 && *schemeID != "") {
if schemeID == nil || (!model.IsValidId(*schemeID) && *schemeID != "") {
c.SetInvalidParam("scheme_id")
return
}
@@ -1513,7 +1513,7 @@ func teamMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.Req
groupIDs := []string{}
for _, gid := range strings.Split(c.Params.GroupIDs, ",") {
if len(gid) != 26 {
if !model.IsValidId(gid) {
c.SetInvalidParam("group_ids")
return
}