Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Validate app type during create or add files

Neeraj Guptae2df743d4850
diff --git a/server/pkg/api/file.go b/server/pkg/api/file.go
index 241d111d8b..b7ed0f4a69 100644
--- a/server/pkg/api/file.go
+++ b/server/pkg/api/file.go
@@ -81,7 +81,6 @@ func (h *FileHandler) CreateMetaFile(c *gin.Context) {
}
file.UpdationTime = time.Microseconds()
- // get an ente.App from the ?app= query parameter with a default of photos
enteApp := auth.GetApp(c)
file.OwnerID = userID
file.IsDeleted = false
diff --git a/server/pkg/controller/collections/file_action.go b/server/pkg/controller/collections/file_action.go
index 90a3213ca8..5db90835dd 100644
--- a/server/pkg/controller/collections/file_action.go
+++ b/server/pkg/controller/collections/file_action.go
@@ -12,15 +12,19 @@ import (
// AddFiles adds files to a collection
func (c *CollectionController) AddFiles(ctx *gin.Context, userID int64, files []ente.CollectionFileItem, cID int64) error {
-
resp, err := c.AccessCtrl.GetCollection(ctx, &access.GetCollectionParams{
CollectionID: cID,
ActorUserID: userID,
IncludeDeleted: false,
})
+
if err != nil {
return stacktrace.Propagate(err, "failed to verify collection access")
}
+ app := auth.GetApp(ctx)
+ if resp.Collection.App != string(app) {
+ return stacktrace.Propagate(ente.ErrInvalidApp, fmt.Sprintf("app mismatch collection: %s request ctx app %s", resp.Collection.App, app))
+ }
if !resp.Role.CanAdd() {
return stacktrace.Propagate(ente.ErrPermissionDenied, fmt.Sprintf("user %d with role %s can not add files", userID, *resp.Role))
}
diff --git a/server/pkg/controller/file.go b/server/pkg/controller/file.go
index 48c69caf65..ea6416659d 100644
--- a/server/pkg/controller/file.go
+++ b/server/pkg/controller/file.go
@@ -80,7 +80,7 @@ const (
DeletedObjectQueueLock = "deleted_objects_queue_lock"
)
-func (c *FileController) validateFileCreateOrUpdateReq(userID int64, file ente.File) error {
+func (c *FileController) validateFileCreateOrUpdateReq(userID int64, file ente.File, app ente.App) error {
objectPathPrefix := strconv.FormatInt(userID, 10) + "/"
if !strings.HasPrefix(file.File.ObjectKey, objectPathPrefix) || !strings.HasPrefix(file.Thumbnail.ObjectKey, objectPathPrefix) {
return stacktrace.Propagate(ente.ErrBadRequest, "Incorrect object key reported")
@@ -106,6 +106,9 @@ func (c *FileController) validateFileCreateOrUpdateReq(userID int64, file ente.F
if err != nil {
return stacktrace.Propagate(err, "")
}
+ if ente.App(collection.App) != app {
+ return stacktrace.Propagate(ente.ErrInvalidApp, fmt.Sprintf("ctx app is different from collection app=%s collectionApp=%s", app, collection.App))
+ }
// Verify that user owns the collection.
// Warning: Do not remove this check
if collection.Owner.ID != userID {
@@ -139,7 +142,7 @@ func (c *FileController) Create(ctx *gin.Context, userID int64, file ente.File,
size, err := c.sizeOf(file.Thumbnail.ObjectKey)
thumbChan <- sizeResult{size, err}
}()
- err := c.validateFileCreateOrUpdateReq(userID, file)
+ err := c.validateFileCreateOrUpdateReq(userID, file, app)
if err != nil {
return file, stacktrace.Propagate(err, "")
}
@@ -235,7 +238,7 @@ func (c *FileController) maybeSendFirstUploadEmail(userID int64, userAgent strin
// Update verifies permissions and updates the specified file
func (c *FileController) Update(ctx context.Context, userID int64, file ente.File, app ente.App) (ente.UpdateFileResponse, error) {
var response ente.UpdateFileResponse
- err := c.validateFileCreateOrUpdateReq(userID, file)
+ err := c.validateFileCreateOrUpdateReq(userID, file, app)
if err != nil {
return response, stacktrace.Propagate(err, "")
}