π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Restrict Authenticator routes to Auth sessions
Neeraj Gupta94bafb3e7945
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 5ff35b710e..83db2a22b1 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -1059,12 +1059,14 @@ func main() {authenticatorController := &authenticatorCtrl.Controller{Repo: authRepo, UserRepo: userRepo}authenticatorHandler := &api.AuthenticatorHandler{Controller: authenticatorController}- privateAPI.POST("/authenticator/key", authenticatorHandler.CreateKey)- privateAPI.GET("/authenticator/key", authenticatorHandler.GetKey)- privateAPI.POST("/authenticator/entity", authenticatorHandler.CreateEntity)- privateAPI.PUT("/authenticator/entity", authenticatorHandler.UpdateEntity)- privateAPI.DELETE("/authenticator/entity", authenticatorHandler.DeleteEntity)- privateAPI.GET("/authenticator/entity/diff", authenticatorHandler.GetDiff)+ authenticatorAPI := privateAPI.Group("/authenticator")+ authenticatorAPI.Use(middleware.RequireAuthApp())+ authenticatorAPI.POST("/key", authenticatorHandler.CreateKey)+ authenticatorAPI.GET("/key", authenticatorHandler.GetKey)+ authenticatorAPI.POST("/entity", authenticatorHandler.CreateEntity)+ authenticatorAPI.PUT("/entity", authenticatorHandler.UpdateEntity)+ authenticatorAPI.DELETE("/entity", authenticatorHandler.DeleteEntity)+ authenticatorAPI.GET("/entity/diff", authenticatorHandler.GetDiff)dataCleanupController := &dataCleanupCtrl.DeleteUserCleanupController{Repo: dataCleanupRepository,diff --git a/server/pkg/middleware/auth.go b/server/pkg/middleware/auth.goindex 48aad34e9d..ac542e31ca 100644--- a/server/pkg/middleware/auth.go+++ b/server/pkg/middleware/auth.go@@ -123,6 +123,21 @@ func RejectAuthApp() gin.HandlerFunc {}}+func RequireAuthApp() gin.HandlerFunc {+ return func(c *gin.Context) {+ app, ok := auth.GetAuthenticatedApp(c)+ if !ok {+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "missing authenticated app"})+ return+ }+ if app != ente.Auth {+ c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "invalid app for endpoint"})+ return+ }+ c.Next()+ }+}+// NOTE: Should be added after TokenAuthMiddleware middlewarefunc (m *AuthMiddleware) AdminAuthMiddleware() gin.HandlerFunc {return func(c *gin.Context) {diff --git a/server/pkg/middleware/auth_test.go b/server/pkg/middleware/auth_test.goindex e4fc72af53..9aa0dedf5d 100644--- a/server/pkg/middleware/auth_test.go+++ b/server/pkg/middleware/auth_test.go@@ -23,7 +23,7 @@ type authRouteTestTokens struct {payment string}-func TestRejectAuthAppKeepsAuthRoutesAndBlocksStorageRoutes(t *testing.T) {+func TestAppScopedRoutes(t *testing.T) {router, tokens, _ := setupAuthRouteTest(t)tests := []struct {@@ -40,6 +40,27 @@ func TestRejectAuthAppKeepsAuthRoutesAndBlocksStorageRoutes(t *testing.T) {clientPkg: "io.ente.auth",wantStatus: http.StatusNoContent,},+ {+ name: "photos token cannot access auth route",+ path: "/authenticator/entity/diff?sinceTime=0&limit=1",+ token: tokens.photos,+ clientPkg: "io.ente.photos",+ wantStatus: http.StatusForbidden,+ },+ {+ name: "locker token cannot access auth route",+ path: "/authenticator/entity/diff?sinceTime=0&limit=1",+ token: tokens.locker,+ clientPkg: "io.ente.locker",+ wantStatus: http.StatusForbidden,+ },+ {+ name: "photos token with auth header remains invalid",+ path: "/authenticator/entity/diff?sinceTime=0&limit=1",+ token: tokens.photos,+ clientPkg: "io.ente.auth",+ wantStatus: http.StatusUnauthorized,+ },{name: "auth token cannot access storage route",path: "/collections/v2",@@ -220,7 +241,9 @@ func setupAuthRouteTest(t *testing.T) (*gin.Engine, authRouteTestTokens, *userco}privateAPI := router.Group("/")privateAPI.Use(authMiddleware.TokenAuthMiddleware(nil))- privateAPI.GET("/authenticator/entity/diff", func(c *gin.Context) {+ authenticatorAPI := privateAPI.Group("/authenticator")+ authenticatorAPI.Use(RequireAuthApp())+ authenticatorAPI.GET("/entity/diff", func(c *gin.Context) {c.Status(http.StatusNoContent)})familyAPI := router.Group("/")