Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: handle unknown sheet for ACL check (#3355)
Tianzhou (天舟)af673b9921a2
diff --git a/server/acl.go b/server/acl.goindex faa0462c51..2884dafe7a 100644--- a/server/acl.go+++ b/server/acl.go@@ -37,12 +37,10 @@ func enforceWorkspaceDeveloperProjectRouteACL(plan api.PlanType, path string, meif path == "/project" {userIDStr := quaryParams.Get("user")if userIDStr == "" {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not allowed to fetch all project list"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to fetch all project list")}if strconv.Itoa(principalID) != userIDStr {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not allowed to fetch projects from other user"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to fetch projects from other user")}}// For /project/xxx subroutes, since all projects are public, we don't enforce ACL.@@ -65,13 +63,11 @@ func enforceWorkspaceDeveloperProjectRouteACL(plan api.PlanType, path string, me}if role == "" {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("is not a member of the project"))+ return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project")}if !api.ProjectPermission(permission, plan, role) {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf(permissionErrMsg))+ return echo.NewHTTPError(http.StatusUnauthorized, permissionErrMsg)}}@@ -88,14 +84,16 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, methif err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)}+ if sheet == nil {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Sheet ID not found: %d", sheetID))+ }// Creator can always manage her own sheet.if sheet.CreatorID == principalID {return nil}switch sheet.Visibility {case api.PrivateSheet:- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not allowed to access private sheet created by other user"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to access private sheet created by other user")case api.PublicSheet:return nilcase api.ProjectSheet:@@ -105,13 +103,11 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if role == "" {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("is not a member of the project containing the sheet"))+ return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project containing the sheet")}if !api.ProjectPermission(api.ProjectPermissionOrganizeSheet, plan, role) {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not have permission to organize the project sheet"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not have permission to organize the project sheet")}}} else if matches := sheetRouteRegex.FindStringSubmatch(path); matches != nil {@@ -120,20 +116,21 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, methif err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)}+ if sheet == nil {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Sheet ID not found: %d", sheetID))+ }// Creator can always manage her own sheet.if sheet.CreatorID == principalID {return nil}switch sheet.Visibility {case api.PrivateSheet:- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not allowed to access private sheet created by other user"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to access private sheet created by other user")case api.PublicSheet:if method == "GET" {return nil}- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not allowed to change public sheet created by other user"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to change public sheet created by other user")case api.ProjectSheet:role, err := roleFinder(sheet.ProjectID, principalID)if err != nil {@@ -141,8 +138,7 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if role == "" {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("is not a member of the project containing the sheet"))+ return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project containing the sheet")}if method == "GET" {@@ -150,8 +146,7 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if !api.ProjectPermission(api.ProjectPermissionAdminSheet, plan, role) {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(- errors.Errorf("not have permission to change the project sheet"))+ return echo.NewHTTPError(http.StatusUnauthorized, "not have permission to change the project sheet")}}}diff --git a/server/acl_project_test.go b/server/acl_project_test.goindex 38b571a003..3954208989 100644--- a/server/acl_project_test.go+++ b/server/acl_project_test.go@@ -277,9 +277,9 @@ func TestEnforceWorkspaceDeveloperProjectRouteACL(t *testing.T) {err := enforceWorkspaceDeveloperProjectRouteACL(tc.plan, tc.path, tc.method, tc.queryParams, tc.principalID, roleFinder)if err != nil {if tc.errMsg == "" {- t.Errorf("expect no error, got %s", err.Internal.Error())- } else if tc.errMsg != err.Internal.Error() {- t.Errorf("expect error %s, got %s", tc.errMsg, err.Internal.Error())+ t.Errorf("expect no error, got %s", err.Message)+ } else if tc.errMsg != err.Message {+ t.Errorf("expect error %s, got %s", tc.errMsg, err.Message)}} else if tc.errMsg != "" {t.Errorf("expect error %s, got no error", tc.errMsg)diff --git a/server/acl_sheet_test.go b/server/acl_sheet_test.goindex 91f68d8bec..ec220af10d 100644--- a/server/acl_sheet_test.go+++ b/server/acl_sheet_test.go@@ -41,6 +41,22 @@ func TestEnforceWorkspaceDeveloperSheetRouteACL(t *testing.T) {principalID: 200,errMsg: "",},+ {+ desc: "Access unknown sheet",+ plan: api.ENTERPRISE,+ path: "/sheet/9999",+ method: "GET",+ principalID: 202,+ errMsg: "Sheet ID not found: 9999",+ },+ {+ desc: "Organize unknown sheet",+ plan: api.ENTERPRISE,+ path: "/sheet/9999/organize",+ method: "PATCH",+ principalID: 202,+ errMsg: "Sheet ID not found: 9999",+ },}privateSheetTests := []test{@@ -301,9 +317,9 @@ func TestEnforceWorkspaceDeveloperSheetRouteACL(t *testing.T) {err := enforceWorkspaceDeveloperSheetRouteACL(tc.plan, tc.path, tc.method, tc.principalID, roleFinder, sheetFinder)if err != nil {if tc.errMsg == "" {- t.Errorf("expect no error, got %s", err.Internal.Error())- } else if tc.errMsg != err.Internal.Error() {- t.Errorf("expect error %s, got %s", tc.errMsg, err.Internal.Error())+ t.Errorf("expect no error, got %s", err.Message)+ } else if tc.errMsg != err.Message {+ t.Errorf("expect error %s, got %s", tc.errMsg, err.Message)}} else if tc.errMsg != "" {t.Errorf("expect error %s, got no error", tc.errMsg)