π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Validate app type during create or add files
Neeraj Guptae2df743d4850
diff --git a/server/pkg/api/file.go b/server/pkg/api/file.goindex 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 photosenteApp := auth.GetApp(c)file.OwnerID = userIDfile.IsDeleted = falsediff --git a/server/pkg/controller/collections/file_action.go b/server/pkg/controller/collections/file_action.goindex 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 collectionfunc (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.goindex 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.Fif 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 checkif 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 filefunc (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, "")}