Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
chore(security): restrict admin from listing user emails and API keys
Jonas Kaninda718bd5a16658
diff --git a/internal/handlers/admin_handler.go b/internal/handlers/admin_handler.goindex 585cb65..58e487d 100644--- a/internal/handlers/admin_handler.go+++ b/internal/handlers/admin_handler.go@@ -271,54 +271,6 @@ func (h *AdminHandler) CancelUserDeletion(c *okapi.Context, req *AdminDeleteUserreturn ok(c, map[string]any{"message": "Account deletion cancelled"})}-// ListAllEmails returns all emails across all users (admin only).-func (h *AdminHandler) ListAllEmails(c *okapi.Context, req *ListRequest) error {- page, size, offset := normalizePageParams(req.Page, req.Size)-- emails, total, err := h.emailRepo.FindAll(size, offset)- if err != nil {- return c.AbortInternalServerError("failed to list emails")- }-- if h.emailSettings == nil || !h.emailSettings.EmailContentVisibility() {- redactEmails(emails)- }-- return paginated(c, emails, total, page, size)-}--// ListAllAPIKeys returns all API keys across all users (admin only).-func (h *AdminHandler) ListAllAPIKeys(c *okapi.Context, req *ListRequest) error {- page, size, offset := normalizePageParams(req.Page, req.Size)-- keys, total, err := h.keyRepo.FindAll(size, offset)- if err != nil {- return c.AbortInternalServerError("failed to list API keys")- }-- return paginated(c, keys, total, page, size)-}--// RevokeAPIKey allows admins to revoke any API key.-func (h *AdminHandler) RevokeAPIKey(c *okapi.Context, req *AdminRevokeKeyRequest) error {- _, err := h.keyRepo.FindByID(uint(req.ID))- if err != nil {- return c.AbortNotFound("API key not found")- }-- if err := h.keyRepo.Revoke(uint(req.ID)); err != nil {- return c.AbortInternalServerError("failed to revoke API key")- }-- if h.bus != nil {- adminID := uint(c.GetInt("user_id"))- h.bus.PublishSimple(models.EventCategoryUser, "apikey.revoked", &adminID, c.GetString("email"), c.RealIP(),- fmt.Sprintf("API key ID %d revoked", req.ID), map[string]any{"api_key_id": req.ID})- }-- return ok(c, okapi.M{"message": "API key revoked"})-}-// Metrics returns platform-wide metrics (admin only).func (h *AdminHandler) Metrics(c *okapi.Context) error {ctx := c.Request().Context()diff --git a/internal/routes/admin_routes.go b/internal/routes/admin_routes.goindex 0477416..d70bc93 100644--- a/internal/routes/admin_routes.go+++ b/internal/routes/admin_routes.go@@ -137,41 +137,6 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {},},- // ==================== All API Keys ====================- {- Method: http.MethodGet,- Path: "/api-keys",- Handler: okapi.H(r.h.admin.ListAllAPIKeys),- Group: adminGroup,- Summary: "List all API keys",- Request: &handlers.ListRequest{},- Response: &dto.PageableResponse[models.APIKey]{},- },- {- Method: http.MethodDelete,- Path: "/api-keys/{id:int}",- Handler: okapi.H(r.h.admin.RevokeAPIKey),- Group: adminGroup,- Summary: "Revoke any API key",- Response: &dto.Response[dto.MessageData]{},- Options: []okapi.RouteOption{- okapi.DocPathParam("id", "integer", "API key ID"),- okapi.DocErrorResponse(404, &dto.ErrorResponseBody{}),- },- },-- // ==================== All Emails ====================- {- Method: http.MethodGet,- Path: "/emails",- Handler: okapi.H(r.h.admin.ListAllEmails),- Group: adminGroup,- Summary: "List all emails",- Description: "List all emails across all users",- Request: &handlers.ListRequest{},- Response: &dto.PageableResponse[models.Email]{},- },-// ==================== Events ===================={Method: http.MethodGet,