π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename and minor fixes
Neeraj Guptadbb1ad66d359
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex f0b8c2c371..5533a17563 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -354,6 +354,12 @@ func main() {userCache,userCacheCtrl,)+ fileLinkCtrl := &publicCtrl.FileLinkController{+ FileController: fileController,+ FileLinkRepo: fileLinkRepo,+ FileRepo: fileRepo,+ JwtSecret: jwtSecretBytes,+ }passkeyCtrl := &controller.PasskeyController{Repo: passkeysRepo,@@ -361,7 +367,7 @@ func main() {}authMiddleware := middleware.AuthMiddleware{UserAuthRepo: userAuthRepo, Cache: authCache, UserController: userController}- collectionTokenMiddleware := middleware.CollectionTokenMiddleware{+ collectionLinkMiddleware := middleware.CollectionLinkMiddleware{CollectionLinkRepo: collectionLinkRepo,PublicCollectionCtrl: collectionLinkCtrl,CollectionRepo: collectionRepo,@@ -369,6 +375,13 @@ func main() {BillingCtrl: billingController,DiscordController: discordController,}+ fileLinkMiddleware := &middleware.FileLinkMiddleware{+ FileLinkRepo: fileLinkRepo,+ FileLinkCtrl: fileLinkCtrl,+ Cache: accessTokenCache,+ BillingCtrl: billingController,+ DiscordController: discordController,+ }if environment != "local" {gin.SetMode(gin.ReleaseMode)@@ -407,7 +420,9 @@ func main() {familiesJwtAuthAPI.Use(rateLimiter.GlobalRateLimiter(), authMiddleware.TokenAuthMiddleware(jwt.FAMILIES.Ptr()), rateLimiter.APIRateLimitForUserMiddleware(urlSanitizer))publicCollectionAPI := server.Group("/public-collection")- publicCollectionAPI.Use(rateLimiter.GlobalRateLimiter(), collectionTokenMiddleware.Authenticate(urlSanitizer))+ publicCollectionAPI.Use(rateLimiter.GlobalRateLimiter(), collectionLinkMiddleware.Authenticate(urlSanitizer))+ fileLinkApi := server.GET("/file-link")+ fileLinkApi.Use(rateLimiter.GlobalRateLimiter(), fileLinkMiddleware.Authenticate(urlSanitizer))healthCheckHandler := &api.HealthCheckHandler{DB: db,@@ -430,12 +445,6 @@ func main() {ObjectRepo: objectRepo,FileRepo: fileRepo,}- fileLinkCtrl := &publicCtrl.FileLinkController{- FileController: fileController,- FileLinkRepo: fileLinkRepo,- FileRepo: fileRepo,- JwtSecret: jwtSecretBytes,- }fileHandler := &api.FileHandler{Controller: fileController,diff --git a/server/pkg/middleware/collection_token.go b/server/pkg/middleware/collection_link.gosimilarity index 93%rename from server/pkg/middleware/collection_token.gorename to server/pkg/middleware/collection_link.goindex 1760718e65..5b11a5ec07 100644--- a/server/pkg/middleware/collection_token.go+++ b/server/pkg/middleware/collection_link.go@@ -26,8 +26,8 @@ import (var passwordWhiteListedURLs = []string{"/public-collection/info", "/public-collection/report-abuse", "/public-collection/verify-password"}var whitelistedCollectionShareIDs = []int64{111}-// CollectionTokenMiddleware intercepts and authenticates incoming requests-type CollectionTokenMiddleware struct {+// CollectionLinkMiddleware intercepts and authenticates incoming requests+type CollectionLinkMiddleware struct {CollectionLinkRepo *public.CollectionLinkRepoPublicCollectionCtrl *public2.CollectionLinkControllerCollectionRepo *repo.CollectionRepository@@ -39,7 +39,7 @@ type CollectionTokenMiddleware struct {// Authenticate returns a middle ware that extracts the `X-Auth-Access-Token`// within the header of a request and uses it to validate the access token and set the// ente.PublicAccessContext with auth.PublicAccessKey as key-func (m *CollectionTokenMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) string) gin.HandlerFunc {+func (m *CollectionLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) string) gin.HandlerFunc {return func(c *gin.Context) {accessToken := auth.GetAccessToken(c)if accessToken == "" {@@ -114,7 +114,7 @@ func (m *CollectionTokenMiddleware) Authenticate(urlSanitizer func(_ *gin.Contexc.Next()}}-func (m *CollectionTokenMiddleware) validateOwnersSubscription(cID int64) error {+func (m *CollectionLinkMiddleware) validateOwnersSubscription(cID int64) error {userID, err := m.CollectionRepo.GetOwnerID(cID)if err != nil {return stacktrace.Propagate(err, "")@@ -122,7 +122,7 @@ func (m *CollectionTokenMiddleware) validateOwnersSubscription(cID int64) errorreturn m.BillingCtrl.HasActiveSelfOrFamilySubscription(userID, false)}-func (m *CollectionTokenMiddleware) isDeviceLimitReached(ctx context.Context,+func (m *CollectionLinkMiddleware) isDeviceLimitReached(ctx context.Context,collectionSummary ente.PublicCollectionSummary, ip string, ua string) (bool, error) {// skip deviceLimit check & record keeping for requests via CF workerif network.IsCFWorkerIP(ip) {@@ -164,7 +164,7 @@ func (m *CollectionTokenMiddleware) isDeviceLimitReached(ctx context.Context,}// validatePassword will verify if the user is provided correct password for the public album-func (m *CollectionTokenMiddleware) validatePassword(c *gin.Context, reqPath string,+func (m *CollectionLinkMiddleware) validatePassword(c *gin.Context, reqPath string,collectionSummary ente.PublicCollectionSummary) error {if array.StringInList(reqPath, passwordWhiteListedURLs) {return nildiff --git a/server/pkg/middleware/file_link_token.go b/server/pkg/middleware/file_link.gosimilarity index 87%rename from server/pkg/middleware/file_link_token.gorename to server/pkg/middleware/file_link.goindex 539ca1179e..d861e9f0f4 100644--- a/server/pkg/middleware/file_link_token.go+++ b/server/pkg/middleware/file_link.go@@ -5,13 +5,12 @@ import ("fmt"publicCtrl "github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/repo/public"+ "github.com/ente-io/museum/pkg/utils/array""net/http""github.com/ente-io/museum/ente""github.com/ente-io/museum/pkg/controller""github.com/ente-io/museum/pkg/controller/discord"- "github.com/ente-io/museum/pkg/repo"- "github.com/ente-io/museum/pkg/utils/array""github.com/ente-io/museum/pkg/utils/auth""github.com/ente-io/museum/pkg/utils/network""github.com/ente-io/museum/pkg/utils/time"@@ -21,13 +20,12 @@ import ("github.com/sirupsen/logrus")-var filePasswordWhiteListedURLs = []string{"/public-collection/info", "/public-collection/report-abuse", "/public-collection/verify-password"}+var filePasswordWhiteListedURLs = []string{"/file-link/info", "/file-link/verify-password"}// FileLinkMiddleware intercepts and authenticates incoming requeststype FileLinkMiddleware struct {FileLinkRepo *public.FileLinkRepositoryFileLinkCtrl *publicCtrl.FileLinkController- CollectionRepo *repo.CollectionRepositoryCache *cache.CacheBillingCtrl *controller.BillingControllerDiscordController *discord.DiscordController@@ -53,6 +51,7 @@ func (m *FileLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) striif !cacheHit {fileLinkRow, err = m.FileLinkRepo.GetFileUrlRowByToken(c, accessToken)if err != nil {+ logrus.WithError(err).Info("failed to get file link row by token")c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})return}@@ -62,15 +61,15 @@ func (m *FileLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) stri}// validate if user still has active paid subscriptionif err = m.BillingCtrl.HasActiveSelfOrFamilySubscription(fileLinkRow.OwnerID, true); err != nil {- logrus.WithError(err).Warn("failed to verify active paid subscription")+ logrus.WithError(err).Info("failed to verify active paid subscription")c.AbortWithStatusJSON(http.StatusGone, gin.H{"error": "no active subscription"})return}// validate device limit- reached, err := m.isDeviceLimitReached(c, fileLinkRow, clientIP, userAgent)- if err != nil {- logrus.WithError(err).Error("failed to check device limit")+ reached, limitErr := m.isDeviceLimitReached(c, fileLinkRow, clientIP, userAgent)+ if limitErr != nil {+ logrus.WithError(limitErr).Error("failed to check device limit")c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "something went wrong"})return}@@ -111,13 +110,6 @@ func (m *FileLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) stric.Next()}}-func (m *FileLinkMiddleware) validateOwnersSubscription(cID int64) error {- userID, err := m.CollectionRepo.GetOwnerID(cID)- if err != nil {- return stacktrace.Propagate(err, "")- }- return m.BillingCtrl.HasActiveSelfOrFamilySubscription(userID, true)-}func (m *FileLinkMiddleware) isDeviceLimitReached(ctx context.Context,collectionSummary *ente.FileLinkRow, ip string, ua string) (bool, error) {@@ -161,11 +153,11 @@ func (m *FileLinkMiddleware) isDeviceLimitReached(ctx context.Context,// validatePassword will verify if the user is provided correct password for the public albumfunc (m *FileLinkMiddleware) validatePassword(c *gin.Context, reqPath string,fileLinkRow *ente.FileLinkRow) error {- if array.StringInList(reqPath, passwordWhiteListedURLs) {- return nil- }accessTokenJWT := auth.GetAccessTokenJWT(c)if accessTokenJWT == "" {+ if array.StringInList(reqPath, filePasswordWhiteListedURLs) {+ return nil+ }return ente.ErrAuthenticationRequired}return m.FileLinkCtrl.ValidateJWTToken(c, accessTokenJWT, *fileLinkRow.PassHash)diff --git a/server/pkg/middleware/rate_limit.go b/server/pkg/middleware/rate_limit.goindex 14d3c92a00..bf4c403cfe 100644--- a/server/pkg/middleware/rate_limit.go+++ b/server/pkg/middleware/rate_limit.go@@ -140,6 +140,7 @@ func (r *RateLimitMiddleware) getLimiter(reqPath string, reqMethod string) *limireqPath == "/users/verify-email" ||reqPath == "/user/change-email" ||reqPath == "/public-collection/verify-password" ||+ reqPath == "/file-link/verify-password" ||reqPath == "/family/accept-invite" ||reqPath == "/users/srp/attributes" ||(reqPath == "/cast/device-info" && reqMethod == "POST") ||