[MM-58492][MM-58523] Fixed some access control bugs around archived channels by replacing the permission check with HasPermissionToReadChannel (#27409)

* [MM-58492][MM-58523] Fixed some access control bugs around archived channels by replacing the permission check with HasPermissionToReadChannel

* Fix lint, add ChannelId to uploads

* Fix MMCTL tests and remove unnecessary check for the error message that doesn't work anyways

* Include channel map for getting flagged posts

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Devin Binnie
2024-07-29 10:05:20 -04:00
коммит произвёл GitHub
родитель 6ddf796384
Коммит aa85a13c8f
17 изменённых файлов: 162 добавлений и 43 удалений

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

@@ -1105,6 +1105,7 @@ type AppIface interface {
SessionHasPermissionToCreateJob(session model.Session, job *model.Job) (bool, *model.Permission)
SessionHasPermissionToGroup(session model.Session, groupID string, permission *model.Permission) bool
SessionHasPermissionToManageJob(session model.Session, job *model.Job) (bool, *model.Permission)
SessionHasPermissionToReadChannel(c request.CTX, session model.Session, channel *model.Channel) bool
SessionHasPermissionToReadJob(session model.Session, jobType string) (bool, *model.Permission)
SessionHasPermissionToTeam(session model.Session, teamID string, permission *model.Permission) bool
SessionHasPermissionToUser(session model.Session, userID string) bool

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

@@ -371,6 +371,14 @@ func (a *App) SessionHasPermissionToManageBot(rctx request.CTX, session model.Se
return nil
}
func (a *App) SessionHasPermissionToReadChannel(c request.CTX, session model.Session, channel *model.Channel) bool {
if session.IsUnrestricted() {
return true
}
return a.HasPermissionToReadChannel(c, session.UserId, channel)
}
func (a *App) HasPermissionToReadChannel(c request.CTX, userID string, channel *model.Channel) bool {
if !*a.Config().TeamSettings.ExperimentalViewArchivedChannels && channel.DeleteAt != 0 {
return false

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

@@ -16443,6 +16443,23 @@ func (a *OpenTracingAppLayer) SessionHasPermissionToManageJob(session model.Sess
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) SessionHasPermissionToReadChannel(c request.CTX, session model.Session, channel *model.Channel) bool {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SessionHasPermissionToReadChannel")
a.ctx = newCtx
a.app.Srv().Store().SetContext(newCtx)
defer func() {
a.app.Srv().Store().SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.SessionHasPermissionToReadChannel(c, session, channel)
return resultVar0
}
func (a *OpenTracingAppLayer) SessionHasPermissionToReadJob(session model.Session, jobType string) (bool, *model.Permission) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SessionHasPermissionToReadJob")

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

@@ -2087,7 +2087,7 @@ func (a *App) GetPostIfAuthorized(c request.CTX, postID string, session *model.S
return nil, err
}
if !a.SessionHasPermissionToChannel(c, *session, channel.Id, model.PermissionReadChannelContent) {
if !a.SessionHasPermissionToReadChannel(c, *session, channel) {
if channel.Type == model.ChannelTypeOpen && !*a.Config().ComplianceSettings.Enable {
if !a.SessionHasPermissionToTeam(*session, channel.TeamId, model.PermissionReadPublicChannel) {
return nil, model.MakePermissionError(session, []*model.Permission{model.PermissionReadPublicChannel})

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

@@ -271,6 +271,7 @@ func (a *App) UploadData(c request.CTX, us *model.UploadSession, rd io.Reader) (
}
info.CreatorId = us.UserId
info.ChannelId = us.ChannelId
info.Path = us.Path
info.RemoteId = model.NewString(us.RemoteId)
if us.ReqFileId != "" {