π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Harden bulk collection sharing
Neeraj Guptaa83b3e04c955
diff --git a/server/pkg/controller/collections/share.go b/server/pkg/controller/collections/share.goindex c4238882e4..3549fd56b0 100644--- a/server/pkg/controller/collections/share.go+++ b/server/pkg/controller/collections/share.go@@ -69,7 +69,7 @@ func (c *CollectionController) BulkShare(return nil, err}fromUserID := auth.GetUserID(ctx.Request.Header)- if err := c.validateBulkShareRecipient(fromUserID, req.RecipientUserID); err != nil {+ if err := validateBulkShareRecipient(fromUserID, req.RecipientUserID); err != nil {return nil, err}@@ -98,15 +98,14 @@ func (c *CollectionController) BulkShare(return results, nil}-func (c *CollectionController) validateBulkShareRecipient(actorUserID, recipientUserID int64) error {+func validateBulkShareRecipient(actorUserID, recipientUserID int64) error {+ if recipientUserID <= 0 {+ return stacktrace.Propagate(ente.ErrBadRequest, "invalid recipient user ID")+ }if actorUserID == recipientUserID {return stacktrace.Propagate(ente.ErrBadRequest, "Can not share collections with self")}- _, err := c.UserRepo.Get(recipientUserID)- if errors.Is(err, sql.ErrNoRows) {- return stacktrace.Propagate(ente.ErrNotFound, "")- }- return stacktrace.Propagate(err, "")+ return nil}func (c *CollectionController) shareCollectionWithUserID(@@ -305,7 +304,7 @@ func (c *CollectionController) BulkUnShare(return nil, err}fromUserID := auth.GetUserID(ctx.Request.Header)- if err := c.validateBulkShareRecipient(fromUserID, req.RecipientUserID); err != nil {+ if err := validateBulkShareRecipient(fromUserID, req.RecipientUserID); err != nil {return nil, err}diff --git a/server/pkg/controller/collections/share_test.go b/server/pkg/controller/collections/share_test.goindex bc086b35be..0159d6093d 100644--- a/server/pkg/controller/collections/share_test.go+++ b/server/pkg/controller/collections/share_test.go@@ -462,11 +462,7 @@ func TestBulkShareAndUnshareReturnPerCollectionStatuses(t *testing.T) {)controller := &CollectionController{CollectionRepo: collectionRepo,- UserRepo: &repo.UserRepository{- DB: db,- SecretEncryptionKey: testutil.SecretEncryptionKey(),- },- CastRepo: &castRepo.Repository{DB: db},+ CastRepo: &castRepo.Repository{DB: db},}ctx, _ := gin.CreateTestContext(httptest.NewRecorder())ctx.Request = httptest.NewRequest("POST", "/collections/share/bulk", nil)diff --git a/server/pkg/middleware/rate_limit.go b/server/pkg/middleware/rate_limit.goindex fe02badd23..91e117fc70 100644--- a/server/pkg/middleware/rate_limit.go+++ b/server/pkg/middleware/rate_limit.go@@ -262,6 +262,9 @@ func (r *RateLimitMiddleware) getLimiter(reqPath string, reqMethod string) *limiif isPublicCollectionUploadURLPath(reqPath) {return r.limit250ReqPerMin}+ if reqPath == "/collections/share/bulk" || reqPath == "/collections/unshare/bulk" {+ return r.limit60ReqPerMin+ }if reqPath == "/users/public-key" {return r.limit200ReqPerMin}