PLT-7785: Slash commands can be issued to a channel in a team without it (#7567)

* Ensured that specified channel is a part of specified team

* Simplified approach to just infer team id from specified channel id to eliminate the attack vector entirely
Этот коммит содержится в:
Jonathan
2017-10-04 11:12:13 -04:00
коммит произвёл Christopher Speller
родитель f94b807f39
Коммит fa80cb10a8
3 изменённых файлов: 42 добавлений и 7 удалений

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

@@ -212,12 +212,9 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if commandArgs.TeamId == "" {
commandArgs.TeamId = channel.TeamId
} else if c.Session.GetTeamByTeamId(commandArgs.TeamId) == nil {
c.SetPermissionError(model.PERMISSION_USE_SLASH_COMMANDS)
return
}
// team id is implicitly taken from channel so that slash commands
// created on some other team can't be run against this one
commandArgs.TeamId = channel.TeamId
commandArgs.UserId = c.Session.UserId
commandArgs.T = c.T

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

@@ -490,3 +490,38 @@ func TestExecuteCommand(t *testing.T) {
_, resp = th.SystemAdminClient.ExecuteCommand(channel.Id, "/getcommand")
CheckNoError(t, resp)
}
func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
Client := th.Client
channel := th.BasicChannel
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
*utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost"
// create a slash command on some other team where we have permission to do so
team2 := th.CreateTeam()
postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: team2.Id,
URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V4 + "/teams/command_test",
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
}
if _, err := th.App.CreateCommand(postCmd); err != nil {
t.Fatal("failed to create post command")
}
// the execute command endpoint will always search for the command by trigger and team id, inferring team id from the
// channel id, so there is no way to use that slash command on a channel that belongs to some other team
_, resp := Client.ExecuteCommand(channel.Id, "/postcommand")
CheckNotFoundStatus(t, resp)
}

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

@@ -2808,7 +2808,10 @@ func (c *Client4) ListCommands(teamId string, customOnly bool) ([]*Command, *Res
// ExecuteCommand executes a given command.
func (c *Client4) ExecuteCommand(channelId, command string) (*CommandResponse, *Response) {
commandArgs := &CommandArgs{ChannelId: channelId, Command: command}
commandArgs := &CommandArgs{
ChannelId: channelId,
Command: command,
}
if r, err := c.DoApiPost(c.GetCommandsRoute()+"/execute", commandArgs.ToJson()); err != nil {
return nil, BuildErrorResponse(r, err)
} else {