Skip to content

armgit / ente

Public Imported from GitHub
0

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

Require collection scope for comment updates

Neeraj Gupta57b193096b4e
diff --git a/server/pkg/controller/public/comments.go b/server/pkg/controller/public/comments.go
index afdc10d655..0f2d371f17 100644
--- a/server/pkg/controller/public/comments.go
+++ b/server/pkg/controller/public/comments.go
@@ -110,10 +110,11 @@ func (c *CommentsController) UpdateComment(ctx *gin.Context, collectionID int64,
return err
}
updateReq := socialcontroller.UpdateCommentRequest{
- Actor: actor,
- CommentID: commentID,
- Cipher: req.Cipher,
- Nonce: req.Nonce,
+ Actor: actor,
+ CommentID: commentID,
+ CollectionID: collectionID,
+ Cipher: req.Cipher,
+ Nonce: req.Nonce,
}
return c.CommentCtrl.UpdatePayload(ctx, updateReq)
}
diff --git a/server/pkg/controller/social/comments_controller.go b/server/pkg/controller/social/comments_controller.go
index 7947191e74..97ea8e590b 100644
--- a/server/pkg/controller/social/comments_controller.go
+++ b/server/pkg/controller/social/comments_controller.go
@@ -39,6 +39,7 @@ type CommentDiffRequest struct {
type UpdateCommentRequest struct {
Actor Actor
CommentID string
+ CollectionID int64
Cipher string
Nonce string
RequireAccess bool
@@ -161,7 +162,20 @@ func (c *CommentsController) UpdatePayload(ctx *gin.Context, req UpdateCommentRe
} else if !hasUserID || comment.UserID != userID {
return stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
- return c.Repo.UpdateCipher(ctx, req.CommentID, req.Cipher, req.Nonce)
+ if req.RequireAccess {
+ if !hasUserID || userID <= 0 {
+ return ente.ErrAuthenticationRequired
+ }
+ if _, err := c.AccessCtrl.GetCollection(ctx, &access.GetCollectionParams{
+ CollectionID: comment.CollectionID,
+ ActorUserID: userID,
+ }); err != nil {
+ return stacktrace.Propagate(err, "")
+ }
+ } else if comment.CollectionID != req.CollectionID {
+ return stacktrace.Propagate(ente.ErrPermissionDenied, "")
+ }
+ return c.Repo.UpdateCipher(ctx, req.CommentID, comment.CollectionID, req.Cipher, req.Nonce)
}
func (c *CommentsController) Delete(ctx *gin.Context, req DeleteCommentRequest) error {
diff --git a/server/pkg/repo/social/comments.go b/server/pkg/repo/social/comments.go
index 34e6007cda..a1fa628c60 100644
--- a/server/pkg/repo/social/comments.go
+++ b/server/pkg/repo/social/comments.go
@@ -32,15 +32,16 @@ func (repo *CommentsRepository) Insert(ctx context.Context, comment socialentity
return stacktrace.Propagate(err, "")
}
-func (repo *CommentsRepository) UpdateCipher(ctx context.Context, id string, cipher string, nonce string) error {
+func (repo *CommentsRepository) UpdateCipher(ctx context.Context, id string, collectionID int64, cipher string, nonce string) error {
result, err := repo.DB.ExecContext(ctx, `
UPDATE comments
SET cipher = $1,
nonce = $2,
updated_at = now_utc_micro_seconds()
WHERE id = $3
+ AND collection_id = $4
AND is_deleted = FALSE
- `, cipher, nonce, id)
+ `, cipher, nonce, id, collectionID)
if err != nil {
return stacktrace.Propagate(err, "")
}