MM-58255 Ensure remote users do not get valid email addresses (#27421)

* remote users don't get valid email addresses; remote users cannot have access tokens

* block notification emails for remote users

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Doug Lauder
2024-06-25 09:26:08 -04:00
коммит произвёл GitHub
родитель 12ad9f3fe2
Коммит 6773d13dee
7 изменённых файлов: 41 добавлений и 15 удалений

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

@@ -2415,6 +2415,12 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
audit.AddEventParameterAuditable(auditRec, "user", user)
if user.IsRemote() {
// remote/synthetic users cannot have access tokens
c.SetPermissionError(model.PermissionCreateUserAccessToken)
return
}
if c.AppContext.Session().IsOAuth {
c.SetPermissionError(model.PermissionCreateUserAccessToken)
c.Err.DetailedError += ", attempted access by oauth app"

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

@@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app"
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
@@ -4634,6 +4635,26 @@ func TestCreateUserAccessToken(t *testing.T) {
assertToken(t, th, rtoken, th.BasicUser.Id)
})
t.Run("create user access token for remote user as a system admin", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
// make a remote user
remoteUser, appErr := th.App.CreateUser(request.TestContext(t), &model.User{
Username: "remoteuser",
RemoteId: model.NewString(model.NewId()),
Password: model.NewId(),
Email: "remoteuser@example.com",
})
require.Nil(t, appErr)
_, resp, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), remoteUser.Id, "test token")
require.Error(t, err)
CheckForbiddenStatus(t, resp) // remote users are not allowed to have access tokens
})
t.Run("create access token as oauth session", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()

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

@@ -1102,8 +1102,8 @@ func max(a, b int64) int64 {
}
func (a *App) userAllowsEmail(c request.CTX, user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool {
// if user is a bot account, then we do not send email
if user.IsBot {
// if user is a bot account or remote, then we do not send email
if user.IsBot || user.IsRemote() {
return false
}