From 3294058e169f170acd20971743d232c5f5b2a41b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 3 Jun 2024 11:15:00 +0200 Subject: [PATCH] :sparkles: Add stricter validation for audit events --- backend/src/app/rpc/commands/audit.clj | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/app/rpc/commands/audit.clj b/backend/src/app/rpc/commands/audit.clj index 5db758b464..6af5f5b62a 100644 --- a/backend/src/app/rpc/commands/audit.clj +++ b/backend/src/app/rpc/commands/audit.clj @@ -77,10 +77,19 @@ (when (seq events) (db/insert-many! pool :audit-log event-columns events)))) +(def valid-event-types + #{"action" "identify"}) + (def schema:event [:map {:title "Event"} - [:name [:string {:max 250}]] - [:type [:string {:max 250}]] + [:name + [:and {:gen/elements ["update-file", "get-profile"]} + [:string {:max 250}] + [:re #"[\d\w-]{1,50}"]]] + [:type + [:and {:gen/elements valid-event-types} + [:string {:max 250}] + [::sm/one-of {:format "string"} valid-event-types]]] [:props [:map-of :keyword :any]] [:context {:optional true}