High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Fix multiple list permission RBAC issues across related handlers.
Kailash Nadhd946c84a6144
diff --git a/cmd/bounce.go b/cmd/bounce.goindex a407109f..4deefa1e 100644--- a/cmd/bounce.go+++ b/cmd/bounce.go@@ -7,6 +7,7 @@ import ("strconv""time"+ "github.com/knadh/listmonk/internal/auth""github.com/knadh/listmonk/models""github.com/labstack/echo/v4")@@ -57,8 +58,14 @@ func (a *App) GetBounces(c echo.Context) error {// GetSubscriberBounces retrieves a subscriber's bounce records.func (a *App) GetSubscriberBounces(c echo.Context) error {- // Query and fetch bounces from the DB.subID := getID(c)++ // Check if the user has access to at least one of the lists on the subscriber.+ if err := a.hasSubPerm(auth.GetUser(c), []int{subID}); err != nil {+ return err+ }++ // Query and fetch bounces from the DB.out, _, err := a.core.QueryBounces(0, subID, "", "", "", 0, 1000)if err != nil {return errdiff --git a/cmd/campaigns.go b/cmd/campaigns.goindex 07d20ce3..0a794520 100644--- a/cmd/campaigns.go+++ b/cmd/campaigns.go@@ -553,14 +553,19 @@ func (a *App) TestCampaign(c echo.Context) error {return err}- // Check if the user has permission to access the subscribers.+ // Exclude subscribers from lists that the user doesn't have access to.user := auth.GetUser(c)- subIDs := make([]int, len(subs))- for i, s := range subs {- subIDs[i] = s.ID+ validSubs := subs[:0]+ for _, s := range subs {+ if err := a.hasSubPerm(user, []int{s.ID}); err == nil {+ validSubs = append(validSubs, s)+ }}- if err := a.hasSubPerm(user, subIDs); err != nil {- return err+ subs = validSubs++ // No subscribers.+ if len(subs) == 0 {+ return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("campaigns.noKnownSubsToTest"))}// Get the campaign from the DB for previewing.@@ -613,6 +618,13 @@ func (a *App) GetCampaignViewAnalytics(c echo.Context) error {a.i18n.Ts("globals.messages.missingFields", "name", "`id`"))}+ // Ensure the user has access to campaigns via lists.+ for _, id := range ids {+ if err := a.checkCampaignPerm(auth.PermTypeGet, id, c); err != nil {+ return err+ }+ }+var (typ = c.Param("type")from = c.QueryParams().Get("from")diff --git a/cmd/subscribers.go b/cmd/subscribers.goindex be242f0f..a0b8a6f8 100644--- a/cmd/subscribers.go+++ b/cmd/subscribers.go@@ -292,6 +292,11 @@ func (a *App) UpdateSubscriber(c echo.Context) error {// Update the subscriber in the DB.id := getID(c)+ // Check if the user has access to at least one of the lists on the target subscriber.+ if err := a.hasSubPerm(user, []int{id}); err != nil {+ return err+ }+// Get the user's permitted lists to pass to the update query so that lists on the subscribers// to which they don't have permissions are preserved/left as-is when deleteLists=true.allPerm, permittedLists := user.GetPermittedLists(auth.PermTypeManage)@@ -315,6 +320,12 @@ func (a *App) PatchSubscriber(c echo.Context) error {user := auth.GetUser(c)id := getID(c)+ // Check if the user has access to at least one of the lists on the target subscriber+ // before fetching it. An empty PATCH body is otherwise a cross-scope PII read primitive.+ if err := a.hasSubPerm(user, []int{id}); err != nil {+ return err+ }+// Fetch the sub subscriber from the DB.sub, err := a.core.GetSubscriber(id, "", "")if err != nil {@@ -478,7 +489,7 @@ func (a *App) ManageSubscriberLists(c echo.Context) error {}// Filter lists against the current user's permitted lists.- listIDs := user.FilterListsByPerm(auth.PermTypeGet|auth.PermTypeManage, req.TargetListIDs)+ listIDs := user.FilterListsByPerm(auth.PermTypeManage, req.TargetListIDs)// User doesn't have the required list permissions.if len(listIDs) == 0 {@@ -656,7 +667,7 @@ func (a *App) ManageSubscriberListsByQuery(c echo.Context) error {// Filter lists against the current user's permitted lists.sourceListIDs := user.GetPermittedListIDs(req.ListIDs)- targetListIDs := user.FilterListsByPerm(auth.PermTypeGet|auth.PermTypeManage, req.TargetListIDs)+ targetListIDs := user.FilterListsByPerm(auth.PermTypeManage, req.TargetListIDs)// Run the action in the DB.var err error@@ -680,8 +691,14 @@ func (a *App) ManageSubscriberListsByQuery(c echo.Context) error {// DeleteSubscriberBounces deletes all the bounces on a subscriber.func (a *App) DeleteSubscriberBounces(c echo.Context) error {- // Delete the bounces from the DB.id := getID(c)++ // Check if the user has access to at least one of the lists on the subscriber.+ if err := a.hasSubPerm(auth.GetUser(c), []int{id}); err != nil {+ return err+ }++ // Delete the bounces from the DB.if err := a.core.DeleteSubscriberBounces(id, ""); err != nil {return err}