π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Merge remote-tracking branch 'upstream/main' into codex/pr-10052
Neeraj Gupta44661548d0c2
diff --cc server/pkg/middleware/collection_link.goindex 6514c12eb6,8bbe38bfaf..afaeb5dff1--- a/server/pkg/middleware/collection_link.go+++ b/server/pkg/middleware/collection_link.go@@@ -89,19 -97,35 +97,37 @@@ func (m *CollectionLinkMiddleware) AuthpublicCollectionSummary.DeviceLimit = public2.FreeUserDeviceLimit}- // validate device limit- reached, err := m.isDeviceLimitReached(c, publicCollectionSummary, clientIP, userAgent)- if err != nil {- logrus.WithError(err).Error("failed to check device limit")- c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "something went wrong"})+ if publicCollectionSummary.ValidTill > 0 && // expiry time is defined, 0 indicates no expiry+ publicCollectionSummary.ValidTill < time.Microseconds() {+ c.AbortWithStatusJSON(http.StatusGone, gin.H{"error": "expired token"})return}- if reached {- c.AbortWithStatusJSON(- ente.ErrLinkDeviceLimitExceeded.HttpStatusCode,- &ente.ErrLinkDeviceLimitExceeded,- )- return-+ if publicCollectionSummary.PassHash != nil && *publicCollectionSummary.PassHash != "" {+ if err = m.validatePassword(c, reqPath, publicCollectionSummary); err != nil {+ logrus.WithError(err).Warn("password validation failed")+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": err})+ return+ }+ passwordValidated = true+ }++ if shouldCheckDeviceLimit {+ linkDeviceToken, reached, limitErr := m.checkDeviceLimit(c, accessToken, publicCollectionSummary, 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+ }+ if reached {- c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{"error": "reached device limit"})++ c.AbortWithStatusJSON(++ ente.ErrLinkDeviceLimitExceeded.HttpStatusCode,++ &ente.ErrLinkDeviceLimitExceeded,++ )+ return+ }+ if linkDeviceToken != "" {+ c.Set(auth.LinkDeviceTokenResponseKey, linkDeviceToken)+ }}} else {publicCollectionSummary = cachedValue.(ente.PublicCollectionSummary)diff --cc server/pkg/middleware/file_link.goindex cfd703f135,9508ce5fe4..26e277469f--- a/server/pkg/middleware/file_link.go+++ b/server/pkg/middleware/file_link.go@@@ -60,19 -67,33 +67,36 @@@ func (m *FileLinkMiddleware) Authenticac.AbortWithStatusJSON(http.StatusGone, gin.H{"error": "disabled token"})return}- // validate 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"})+ if fileLinkRow.ValidTill > 0 && // expiry time is defined, 0 indicates no expiry+ fileLinkRow.ValidTill < time.Microseconds() {+ c.AbortWithStatusJSON(http.StatusGone, gin.H{"error": "expired token"})return}- if reached {- c.AbortWithStatusJSON(- ente.ErrLinkDeviceLimitExceeded.HttpStatusCode,- &ente.ErrLinkDeviceLimitExceeded,- )- return+ if fileLinkRow.PassHash != nil && *fileLinkRow.PassHash != "" {+ if err = m.validatePassword(c, reqPath, fileLinkRow); err != nil {+ logrus.WithError(err).Warn("password validation failed")+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": err})+ return+ }+ passwordValidated = true+ }+ if shouldCheckDeviceLimit {+ linkDeviceToken, reached, limitErr := m.checkDeviceLimit(c, accessToken, 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+ }+ if reached {- c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{"error": "reached device limit"})++ c.AbortWithStatusJSON(++ ente.ErrLinkDeviceLimitExceeded.HttpStatusCode,++ &ente.ErrLinkDeviceLimitExceeded,++ )+ return+ }+ if linkDeviceToken != "" {+ c.Set(auth.LinkDeviceTokenResponseKey, linkDeviceToken)+ }}} else {fileLinkRow = cachedValue.(*ente.FileLinkRow)