Skip to content

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

execute_question: improve error codes (#77156)

Chris Truter0149067bd70a
diff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.clj
index c195fe0800a..9c319bb738e 100644
--- a/src/metabase/agent_api/api.clj
+++ b/src/metabase/agent_api/api.clj
@@ -1170,7 +1170,7 @@
[{:keys [id]} :- [:map [:id ms/PositiveInt]]
_query-params
_body]
- (let [card (api/check-404 (t2/select-one :model/Card id))]
+ (let [card (api/read-check :model/Card id)]
(reject-parameterized-card! card)
(qp.card/process-query-for-card
card :api
diff --git a/test/metabase/agent_api/api_test.clj b/test/metabase/agent_api/api_test.clj
index 8021af3c6e1..12f7f1c42a8 100644
--- a/test/metabase/agent_api/api_test.clj
+++ b/test/metabase/agent_api/api_test.clj
@@ -728,7 +728,15 @@
:parameters [{:id "p1" :name "Category" :slug "category" :type :category}]}]
(is (re-find #"takes parameters"
(str (mt/user-http-request :crowberto :post 400
- (format "agent/v1/question/%d/query" card-id))))))))
+ (format "agent/v1/question/%d/query" card-id)))))))
+ (testing "Read-check runs before the parameterized rejection, so an unreadable parameterized card is 403 — it does not leak that the card exists or is parameterized"
+ (mt/with-non-admin-groups-no-root-collection-perms
+ (mt/with-temp [:model/Collection {coll-id :id} {:name "No-Read Coll"}
+ :model/Card {card-id :id} {:collection_id coll-id
+ :dataset_query (orders-limit-query 5)
+ :parameters [{:id "p1" :name "Category" :slug "category" :type :category}]}]
+ (mt/user-http-request :rasta :post 403
+ (format "agent/v1/question/%d/query" card-id))))))
(deftest create-question-explicit-null-collection-test
(testing "An explicit null collection_id saves to the root collection, not the personal default"