Skip to content

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

Additional dashboard read check (#82787)

Nathan Voxland674c8b8dc6ed
diff --git a/src/metabase/query_processor/middleware/permissions.clj b/src/metabase/query_processor/middleware/permissions.clj
index dacead30ff7..ba428790121 100644
--- a/src/metabase/query_processor/middleware/permissions.clj
+++ b/src/metabase/query_processor/middleware/permissions.clj
@@ -102,10 +102,12 @@
;; collection perms for the dashboard and not ad-hoc query perms
*param-values-query*
(do
- ;; The value-source Card itself is read-checked by the caller, but its query may nest other Cards; the
- ;; user must be able to read every one of those too, just like when running the Card normally.
- ;; Otherwise a readable wrapper Card launders the values of a Card the user cannot read. The
- ;; result_metadata check covers tables a Card's saved columns name but its query footprint does not.
+ ;; `source-card-ids` holds the Card the values query is built on as well as every Card its query nests,
+ ;; and the user must be able to read all of them, just like when running the Card normally. Otherwise a
+ ;; readable wrapper Card launders the values of a Card the user cannot read. Don't narrow this to the
+ ;; nested Cards: filter values from field-ref-only dashcard mappings have no caller-side read check on
+ ;; the mapped Card, so this is the only check. The result_metadata check covers tables a Card's saved
+ ;; columns name but its query footprint does not.
(doseq [card-id source-card-ids]
(query-perms/check-card-read-perms database-id card-id)
(query-perms/check-card-result-metadata-data-perms database-id card-id))
diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.clj
index 4d007a0442c..4d2efe42a7d 100644
--- a/test/metabase/dashboards_rest/api_test.clj
+++ b/test/metabase/dashboards_rest/api_test.clj
@@ -5813,6 +5813,37 @@
:tabs []})
(is (every? #(= 1 (count %)) (t2/select-fn-vec :parameter_mappings :model/DashboardCard :dashboard_id dash-id)))))))
+(deftest param-values-no-field-ids-unreadable-card-test
+ (testing "a field-ref-only param mapped to a card the user cannot read is a 403"
+ (let [mp (mt/metadata-provider)
+ target [:dimension [:field "SOURCE" {:base-type :type/Text}]]
+ no-perms #(format "You do not have permissions to view Card %d." %)
+ all-users (perms-group/all-users)]
+ (mt/with-non-admin-groups-no-root-collection-perms
+ (mt/with-temp [:model/Collection private-coll {:name "Private native card collection"}
+ :model/Card {native-id :id} (assoc (qp.test-util/card-with-source-metadata-for-query
+ (lib/native-query mp "select * from people"))
+ :collection_id (:id private-coll))
+ :model/Collection dash-coll {:name "Readable dashboard collection"}
+ :model/Dashboard {dashboard-id :id}
+ {:collection_id (:id dash-coll)
+ :parameters [{:name "User Source" :slug "user_source" :id "_US_" :type :string/=}]}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id native-id
+ :parameter_mappings [{:card_id native-id
+ :parameter_id "_US_"
+ :target target}]}]
+ (perms/grant-collection-read-permissions! all-users dash-coll)
+ (let [values-url (str "dashboard/" dashboard-id "/params/_US_/values")]
+ (testing "read on the dashboard does not grant read on the mapped card"
+ (is (= (no-perms native-id)
+ (mt/user-http-request :rasta :get 403 values-url))))
+ (testing "the values come back once the user can read the mapped card"
+ (perms/grant-collection-read-permissions! all-users private-coll)
+ (is (= {:values [["Affiliate"] ["Facebook"] ["Google"] ["Organic"] ["Twitter"]]
+ :has_more_values false}
+ (mt/user-http-request :rasta :get 200 values-url))))))))))
+
(deftest param-search-no-field-ids-test
(testing "GET .../params/:param-key/search/:query for field-ref-only (nested-native) params currently returns the same unfiltered set as /values"
(let [mp (mt/metadata-provider)]