Skip to content

armgit / ente

Public Imported from GitHub
0

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

Redact owner-private metadata from shared lookups

Neeraj Guptadeecc649212d
diff --git a/server/pkg/controller/collections/cast.go b/server/pkg/controller/collections/cast.go
index 6aa7f6cfc6..dcc1cd683c 100644
--- a/server/pkg/controller/collections/cast.go
+++ b/server/pkg/controller/collections/cast.go
@@ -18,6 +18,7 @@ func (c *CollectionController) GetCastCollection(ctx *gin.Context) (*ente.Collec
if collection.IsDeleted {
return nil, stacktrace.Propagate(ente.ErrNotFound, "collection is deleted")
}
+ collection.MagicMetadata = nil
return &collection, nil
}
diff --git a/server/pkg/controller/collections/collection.go b/server/pkg/controller/collections/collection.go
index fbfd246c6d..c89be4fa8f 100644
--- a/server/pkg/controller/collections/collection.go
+++ b/server/pkg/controller/collections/collection.go
@@ -94,6 +94,7 @@ func (c *CollectionController) GetCollection(ctx *gin.Context, userID int64, cID
return ente.Collection{}, stacktrace.Propagate(err, "")
}
if resp.Role != nil && *resp.Role != ente.OWNER {
+ collection.MagicMetadata = nil
collection.PublicURLs = ente.FilterPublicURLsForRole(collection.PublicURLs, *resp.Role)
}
return collection, nil
@@ -118,6 +119,9 @@ func (c *CollectionController) GetFile(ctx *gin.Context, collectionID int64, fil
if !slices.Contains(cIDs, collectionID) {
return nil, stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
+ file.MagicMetadata = nil
+ file.Action = nil
+ file.ActionUserID = nil
}
if file.IsDeleted {
return nil, stacktrace.Propagate(&ente.ErrFileNotFoundInAlbum, "")
diff --git a/server/pkg/controller/collections/collection_test.go b/server/pkg/controller/collections/collection_test.go
index cce204e419..157a8e1c02 100644
--- a/server/pkg/controller/collections/collection_test.go
+++ b/server/pkg/controller/collections/collection_test.go
@@ -5,13 +5,24 @@ import (
"testing"
"github.com/ente/museum/ente"
+ "github.com/ente/museum/ente/cast"
"github.com/ente/museum/pkg/controller/access"
+ "github.com/ente/museum/pkg/utils/auth"
"github.com/gin-gonic/gin"
)
-func TestGetCollectionForViewer(t *testing.T) {
+func TestGetCollectionPointResponsesForViewer(t *testing.T) {
db, collectionRepo, ownerID, shareeID := setupCollectionShareTest(t)
collectionID := createShareTestCollection(t, collectionRepo, ownerID)
+ if _, err := db.Exec(
+ `UPDATE collections SET
+ magic_metadata = '{"version":1,"count":1,"data":"private-collection","header":"private-header"}'::jsonb,
+ pub_magic_metadata = '{"version":1,"count":1,"data":"public-collection","header":"public-header"}'::jsonb
+ WHERE collection_id = $1`,
+ collectionID,
+ ); err != nil {
+ t.Fatal(err)
+ }
addShareTestShare(t, collectionRepo, collectionID, ownerID, shareeID, ente.VIEWER)
if _, err := db.Exec(
`INSERT INTO public_collection_tokens (collection_id, access_token, valid_till, device_limit, min_role)
@@ -34,6 +45,9 @@ func TestGetCollectionForViewer(t *testing.T) {
if len(ownerCollection.PublicURLs) != 1 || ownerCollection.PublicURLs[0].URL != wantURL {
t.Fatalf("owner public URLs = %+v, want %q", ownerCollection.PublicURLs, wantURL)
}
+ if ownerCollection.MagicMetadata == nil || ownerCollection.MagicMetadata.Data != "private-collection" {
+ t.Fatalf("owner private magic metadata = %+v", ownerCollection.MagicMetadata)
+ }
collection, err := controller.GetCollection(ctx, shareeID, collectionID)
if err != nil {
@@ -42,6 +56,12 @@ func TestGetCollectionForViewer(t *testing.T) {
if collection.EncryptedKey != "share-key" {
t.Fatalf("encrypted key = %q, want recipient's key", collection.EncryptedKey)
}
+ if collection.MagicMetadata != nil {
+ t.Fatalf("viewer received owner-private magic metadata: %+v", collection.MagicMetadata)
+ }
+ if collection.PublicMagicMetadata == nil || collection.PublicMagicMetadata.Data != "public-collection" {
+ t.Fatalf("viewer public magic metadata = %+v", collection.PublicMagicMetadata)
+ }
if len(collection.PublicURLs) != 0 {
t.Fatalf("viewer received restricted public URLs: %+v", collection.PublicURLs)
}
@@ -51,4 +71,65 @@ func TestGetCollectionForViewer(t *testing.T) {
if len(collection.Sharees) != 1 || collection.Sharees[0].ID != shareeID {
t.Fatalf("unexpected sharees: %+v", collection.Sharees)
}
+
+ ctx.Set(auth.CastContext, cast.AuthContext{CollectionID: collectionID})
+ castCollection, err := controller.GetCastCollection(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if castCollection.MagicMetadata != nil || castCollection.PublicMagicMetadata == nil {
+ t.Fatalf("cast metadata = (%+v, %+v)", castCollection.MagicMetadata, castCollection.PublicMagicMetadata)
+ }
+}
+
+func TestGetFileForViewer(t *testing.T) {
+ db, collectionRepo, ownerID, shareeID := setupCollectionShareTest(t)
+ collectionID := createShareTestCollection(t, collectionRepo, ownerID)
+ addShareTestShare(t, collectionRepo, collectionID, ownerID, shareeID, ente.VIEWER)
+ fileID := addShareTestOwnerFile(t, db, collectionID, ownerID)
+ if _, err := db.Exec(
+ `UPDATE files SET
+ magic_metadata = '{"version":1,"count":1,"data":"private-file","header":"private-header"}'::jsonb,
+ pub_magic_metadata = '{"version":1,"count":1,"data":"public-file","header":"public-header"}'::jsonb
+ WHERE file_id = $1`,
+ fileID,
+ ); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := db.Exec(
+ `UPDATE collection_files SET action_user = $1, action = $2
+ WHERE collection_id = $3 AND file_id = $4`,
+ ownerID,
+ ente.ActionRemove,
+ collectionID,
+ fileID,
+ ); err != nil {
+ t.Fatal(err)
+ }
+
+ controller := &CollectionController{CollectionRepo: collectionRepo}
+ ownerFile, err := controller.GetFile(newBatchShareTestContext(ownerID), collectionID, fileID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if ownerFile.MagicMetadata == nil || ownerFile.MagicMetadata.Data != "private-file" {
+ t.Fatalf("owner private magic metadata = %+v", ownerFile.MagicMetadata)
+ }
+ if ownerFile.Action == nil || *ownerFile.Action != ente.ActionRemove || ownerFile.ActionUserID == nil || *ownerFile.ActionUserID != ownerID {
+ t.Fatalf("owner action fields = (%v, %v)", ownerFile.Action, ownerFile.ActionUserID)
+ }
+
+ viewerFile, err := controller.GetFile(newBatchShareTestContext(shareeID), collectionID, fileID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if viewerFile.MagicMetadata != nil || viewerFile.Action != nil || viewerFile.ActionUserID != nil {
+ t.Fatalf("viewer received owner-private file fields: %+v", viewerFile)
+ }
+ if viewerFile.PubicMagicMetadata == nil || viewerFile.PubicMagicMetadata.Data != "public-file" {
+ t.Fatalf("viewer public magic metadata = %+v", viewerFile.PubicMagicMetadata)
+ }
+ if viewerFile.EncryptedKey != "collection-file-key" || viewerFile.Metadata.EncryptedData != "encrypted-metadata" {
+ t.Fatalf("viewer shared file fields were not preserved: %+v", viewerFile)
+ }
}