when receiving file attachments for shared channels, ensure attachments are enabled and file size does not exceed maximum configured for receiving server. (#27018)

This commit is contained in:
Doug Lauder
2024-05-21 14:46:48 -05:00
committed by GitHub
parent d7b7d4e3b9
commit 2fd5725c9f

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sync"
"github.com/mattermost/mattermost/server/public/model"
@@ -172,6 +173,20 @@ func (scs *Service) onReceiveUploadCreate(msg model.RemoteClusterMsg, rc *model.
return fmt.Errorf("could not validate upload session for remote: %w", err)
}
// make sure file attachments are enabled
if scs.server.Config().FileSettings.EnableFileAttachments == nil || !*scs.server.Config().FileSettings.EnableFileAttachments {
return model.NewAppError("ReceiveUploadCreate",
"api.file.attachments.disabled.app_error",
nil, "", http.StatusNotImplemented)
}
// make sure the file size requested does not exceed local server config - MM server's regular
// upload code will ensure the actual bytes sent are within the upload session limit.
if scs.server.Config().FileSettings.MaxFileSize == nil || us.FileSize > *scs.server.Config().FileSettings.MaxFileSize {
return model.NewAppError("createUpload", "api.upload.create.upload_too_large.app_error",
map[string]any{"channelId": us.ChannelId}, "", http.StatusRequestEntityTooLarge)
}
us.RemoteId = rc.RemoteId // don't let remotes try to impersonate each other
// create upload session.