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
Disallow private list UUIDs on public sub endpoints. Closes #2296.
Kailash Nadha9869612dc86
diff --git a/cmd/public.go b/cmd/public.goindex c634a487..7e4c85b5 100644--- a/cmd/public.go+++ b/cmd/public.go@@ -703,6 +703,18 @@ func processSubForm(c echo.Context) (bool, error) {listUUIDs := pq.StringArray(req.FormListUUIDs)+ // Fetch the list types and ensure that they are not private.+ listTypes, err := app.core.GetListTypes(nil, req.FormListUUIDs)+ if err != nil {+ return false, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("%s", err.(*echo.HTTPError).Message))+ }++ for _, t := range listTypes {+ if t == models.ListTypePrivate {+ return false, echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidUUID"))+ }+ }+// Insert the subscriber into the DB._, hasOptin, err := app.core.InsertSubscriber(models.Subscriber{Name: req.Name,diff --git a/internal/core/lists.go b/internal/core/lists.goindex 98c03a3f..9848a0ba 100644--- a/internal/core/lists.go+++ b/internal/core/lists.go@@ -9,6 +9,12 @@ import ("github.com/lib/pq")+type listType struct {+ ID int `json:"id"`+ UUID string `json:"uuid"`+ Type string `json:"type"`+}+// GetLists gets all lists optionally filtered by type.func (c *Core) GetLists(typ string, getAll bool, permittedIDs []int) ([]models.List, error) {out := []models.List{}@@ -112,6 +118,33 @@ func (c *Core) GetListsByOptin(ids []int, optinType string) ([]models.List, erroreturn out, nil}+// GetListTypes returns lists by their IDs or UUIDs.+// If ids is given, then the map returned has the list IDs as keys,+// otherwise, they have UUIDs as the keys.+// Note: This is a really weird and awkward API. Ideally, Go Generics+// should've somehow supported generic struct methods.+func (c *Core) GetListTypes(ids []int, uuids []string) (map[interface{}]string, error) {+ res := []listType{}++ out := map[interface{}]string{}+ if err := c.q.GetListTypes.Select(&res, pq.Array(ids), pq.StringArray(uuids)); err != nil {+ c.log.Printf("error fetching list types: %v", err)+ return nil, echo.NewHTTPError(http.StatusInternalServerError,+ c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.list}", "error", pqErrMsg(err)))+ }++ isIDs := ids != nil+ for _, r := range res {+ if isIDs {+ out[r.ID] = r.Type+ } else {+ out[r.UUID] = r.Type+ }+ }++ return out, nil+}+// CreateList creates a new list.func (c *Core) CreateList(l models.List) (models.List, error) {uu, err := uuid.NewV4()diff --git a/models/queries.go b/models/queries.goindex 5aa6f576..c6b1b99f 100644--- a/models/queries.go+++ b/models/queries.go@@ -53,6 +53,7 @@ type Queries struct {QueryLists string `query:"query-lists"`GetLists *sqlx.Stmt `query:"get-lists"`GetListsByOptin *sqlx.Stmt `query:"get-lists-by-optin"`+ GetListTypes *sqlx.Stmt `query:"get-list-types"`UpdateList *sqlx.Stmt `query:"update-list"`UpdateListsDate *sqlx.Stmt `query:"update-lists-date"`DeleteLists *sqlx.Stmt `query:"delete-lists"`diff --git a/queries.sql b/queries.sqlindex 7772fce7..c0d09dcb 100644--- a/queries.sql+++ b/queries.sql@@ -466,6 +466,13 @@ SELECT * FROM lists WHERE (CASE WHEN $1 != '' THEN optin=$1::list_optin ELSE TRUWHEN $3::UUID[] IS NOT NULL THEN uuid = ANY($3::UUID[])END) ORDER BY name;+-- name: get-list-types+-- Retrieves the private|public type of lists by ID or uuid. Used for filtering.+SELECT id, uuid, type FROM lists WHERE+ (CASE WHEN $1::INT[] IS NOT NULL THEN id = ANY($1::INT[])+ WHEN $2::UUID[] IS NOT NULL THEN uuid = ANY($2::UUID[])+ END);+-- name: create-listINSERT INTO lists (uuid, name, type, optin, tags, description) VALUES($1, $2, $3, $4, $5, $6) RETURNING id;