Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[master] security fixes (#69924)

dpsuttonf1de74d0d24f
diff --git a/src/metabase/actions_rest/api.clj b/src/metabase/actions_rest/api.clj
index 80e55ad1cd0..d6569552c01 100644
--- a/src/metabase/actions_rest/api.clj
+++ b/src/metabase/actions_rest/api.clj
@@ -210,7 +210,7 @@
_query-params
{:keys [parameters], :as _body} :- [:maybe [:map
[:parameters {:optional true} [:maybe [:map-of :keyword any?]]]]]]
- (let [{:keys [type] :as action} (api/check-404 (actions/select-action :id id :archived false))]
+ (let [{:keys [type] :as action} (api/read-check (actions/select-action :id id :archived false))]
(when (= type :http)
(throw (ex-info (tru "HTTP actions are not supported.")
{:type :http
diff --git a/src/metabase/channel/render/style.clj b/src/metabase/channel/render/style.clj
index 0f834895383..1d8d7dfe7a7 100644
--- a/src/metabase/channel/render/style.clj
+++ b/src/metabase/channel/render/style.clj
@@ -14,15 +14,26 @@
;; TODO - we should move other CSS definitions from `metabase.channel.render` namespaces into this one, so they're all
;; in one place.
+(defn- sanitize-css-value
+ "Remove characters that are unsafe in CSS values rendered inside a `<style>` block.
+ Allows alphanumerics plus punctuation that appears in legitimate CSS values
+ (e.g. `#FF0000`, `1.5em`, `100%`, `1px solid black`, `Lato, \"Helvetica Neue\"`, `780px !important`, `3/2`)."
+ [v]
+ (-> v
+ (str/replace #"[^\p{L}\p{N} #%.,!+\-/\"'()]" "")
+ ;; block those that can fetch remote url
+ (str/replace #"(?i)(url|expression|image|image-set)\s*\(" "blocked(")))
+
(defn style
"Compile one or more CSS style maps into a string.
(style {:font-weight 400, :color \"white\"}) -> \"font-weight: 400; color: white;\""
[& style-maps]
(str/join " " (for [[k v] (into {} style-maps)
- :let [v (if (keyword? v) (name v) (str v))]
+ :let [v (-> (if (keyword? v) (name v) (str v))
+ sanitize-css-value)]
:when (seq v)]
- (str (name k) ": " v ";"))))
+ (str (sanitize-css-value (name k)) ": " v ";"))))
(def ^:const color-gold
"Used as color for 'We were unable to display this Pulse' messages."
diff --git a/src/metabase/notification/payload/core.clj b/src/metabase/notification/payload/core.clj
index 8ce6728ed19..c2d52ea4114 100644
--- a/src/metabase/notification/payload/core.clj
+++ b/src/metabase/notification/payload/core.clj
@@ -1,5 +1,6 @@
(ns metabase.notification.payload.core
(:require
+ [clojure.walk :as w]
[metabase.appearance.core :as appearance]
[metabase.notification.models :as models.notification]
[metabase.notification.payload.execute :as notification.payload.execute]
@@ -146,7 +147,11 @@
[notification :- ::Notification]
(assoc (select-keys notification [:payload_type])
:creator (t2/select-one [:model/User :id :first_name :last_name :email] (:creator_id notification))
- :payload (payload notification)
+ :payload (w/prewalk (fn [x]
+ (if (and (map? x) (:lib/metadata x))
+ (dissoc x :lib/metadata)
+ x))
+ (payload notification))
:context (default-context)))
(defmulti skip-reason
diff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.clj
index b1655753d80..bff27eb314b 100644
--- a/src/metabase/public_sharing_rest/api.clj
+++ b/src/metabase/public_sharing_rest/api.clj
@@ -648,6 +648,7 @@
;; you're by definition allowed to run it without a perms check anyway
(request/as-admin
(let [action (api/check-404 (actions/select-action :public_uuid uuid :archived false))]
+ (actions/check-actions-enabled! action)
(analytics/track-event! :snowplow/action
{:event :action-executed
:source :public_form
diff --git a/test/metabase/actions_rest/api_test.clj b/test/metabase/actions_rest/api_test.clj
index 86bf65655cf..001f36e90bc 100644
--- a/test/metabase/actions_rest/api_test.clj
+++ b/test/metabase/actions_rest/api_test.clj
@@ -221,7 +221,7 @@
(let [response (mt/user-http-request :crowberto :post "action" action)
url (format "action/%s/execute" (:id response))
params {:parameters {:id 1 :source "Twitter"}}]
- (is (=? {:message "You don't have permissions to do that."}
+ (is (=? "You don't have permissions to do that."
(mt/user-http-request :rasta :post 403 url params)))
(is (= {:rows-affected 1} (mt/user-http-request :crowberto :post 200 url params)))))))))))))))
@@ -546,6 +546,29 @@
(format "action/%s/execute" action-id)
{:parameters {:id 1 :name "European"}})))))))))
+(deftest execute-action-permission-test
+ (mt/test-drivers (mt/normal-drivers-with-feature :actions)
+ (mt/with-actions-test-data-and-actions-enabled
+ (mt/with-actions [_ {:type :model :dataset_query (mt/mbql-query categories)
+ :collection_id (:id (collection/user->personal-collection (mt/user->id :crowberto)))}
+ {query-action-id :action-id} (assoc unshared-action-opts :type :query)
+ {implicit-action-id :action-id} (assoc unshared-action-opts :type :implicit :kind "row/update")]
+ (testing "User without read permissions cannot execute a query action"
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :post 403
+ (format "action/%d/execute" query-action-id)
+ {:parameters {:id 1 :name "European"}}))))
+ (testing "User without read permissions cannot execute an implicit action"
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :post 403
+ (format "action/%d/execute" implicit-action-id)
+ {:parameters {:id 1 :name "European"}}))))
+ (testing "Admin can still execute actions"
+ (is (=? {:rows-affected 1}
+ (mt/user-http-request :crowberto :post 200
+ (format "action/%d/execute" query-action-id)
+ {:parameters {:id 1 :name "European"}}))))))))
+
(deftest parameter-ignore-test
(mt/with-actions-test-data-tables #{"users"}
(mt/with-actions-test-data-and-actions-enabled
diff --git a/test/metabase/channel/render/style_test.clj b/test/metabase/channel/render/style_test.clj
index 125e903d289..7ab0fd82a31 100644
--- a/test/metabase/channel/render/style_test.clj
+++ b/test/metabase/channel/render/style_test.clj
@@ -11,6 +11,25 @@
(is (= "a: 0; c: 2;"
(style/style {:a 0, :b nil, :c 2, :d ""})))))
+(deftest ^:parallel style-sanitizes-css-values-test
+ (testing "values with characters that can escape CSS context are sanitized"
+ (are [res input] (= res (style/style input))
+ "k: abc;" {:k "a;b:c"} ; semicolons do not introduce new declarations
+ "k: a/style;" {:k "a}</style>"} ; braces/angles do break out of CSS into HTML
+ "k: 3c script3e;" {:k "\\3c script\\3e"} ; disallow escape sequences
+ "k: blocked(1);" {:k "url(1)"} ; no url() injections
+ "k: url/ hack/(1);" {:k "url/* hack/*(1)"})) ; no comment hacks
+ (testing "legitimate CSS values are unchanged"
+ (are [res input] (= res (style/style input))
+ "text-align: left;" {:text-align "left"}
+ "max-width: 100% !important;" {:max-width "100% !important"}
+ "border: .5em solid #DEAD00;" {:border ".5em solid #DEAD00"}
+ "font-family: One, \"Two Three\";" {:font-family "One, \"Two Three\""}
+ "aspect-ratio: 4/5 auto;" {:aspect-ratio "4/5 auto"}
+ "color: rgba(1,1,1,1);" {:color "rgba(1,1,1,1)"}
+ ;; <skip lint>
+ "content: 'шо ти';" {:content "'шо ти'"})))
+
(deftest register-fonts-test
(testing "Under normal circumstances, font registration should work as expected"
(is (= nil