Skip to content

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

GDGT-3184 Reject ':' in custom viz plugin identifiers (#81886)

Kamil Mielnikff7b417ce6e5
diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj
index 513e9ca5cd9..9886e32d93d 100644
--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj
@@ -94,11 +94,14 @@
(nil? (:bundle_hash plugin)))
(defn- plugin-warnings
- "Version warnings for a plugin. Dev-only plugins get no warnings."
+ "Warnings for a plugin. Dev-only plugins get no version warnings."
[plugin]
- (if (dev-only-plugin? plugin)
- []
- (manifest/warnings plugin)))
+ (cond-> (if (dev-only-plugin? plugin)
+ []
+ (manifest/warnings plugin))
+ ;; a legacy pre-validation identifier; /list skips such plugins entirely
+ (manifest/identifier-error (:identifier plugin))
+ (conj {:type "invalid-identifier" :identifier (:identifier plugin)})))
(defn- plugin->response
"Convert a plugin record to API response format."
@@ -174,6 +177,8 @@
"metabase-plugin.json is missing a \"name\" field."
"Could not fetch metabase-plugin.json from the dev server.")
{:status-code 400})))
+ _ (when-let [error (manifest/identifier-error identifier)]
+ (throw (ex-info error {:status-code 400})))
_ (api/check-400
(not (custom-viz-plugin.db/plugin-identifier-exists? identifier))
(format "A custom visualization with identifier \"%s\" already exists." identifier))
@@ -209,6 +214,10 @@
plugins (custom-viz-plugin.db/active-enabled-non-blob-plugins)]
(->> plugins
(remove #(and (not dev-mode?) (dev-only-plugin? %)))
+ ;; An identifier containing ":" would collide with another plugin's `custom-viz:<id>:`
+ ;; settings prefix on the frontend. Colons are rejected at registration now; skip any
+ ;; legacy row that predates that check instead of serving it.
+ (remove #(manifest/identifier-error (:identifier %)))
(mapv (comp plugin->runtime-response api/read-check)))))
(api.macros/defendpoint :delete "/:id" :- :nil
@@ -247,6 +256,10 @@
_query-params
{:keys [file]} :- BundleUploadParts]
(let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))
+ _ (api/check-400 (nil? (manifest/identifier-error (:identifier existing)))
+ (format (str "This plugin's identifier (\"%s\") contains \":\", which is no longer allowed. "
+ "Delete the plugin and upload the bundle under a name without \":\".")
+ (:identifier existing)))
tempfile (check-upload! file)]
(try
(let [bundle-bytes (Files/readAllBytes (.toPath tempfile))
diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj
index 72aa318214a..3d129490ccd 100644
--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj
+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj
@@ -129,6 +129,9 @@
(when (str/blank? (:name parsed))
(throw (ex-info (str (manifest/manifest-path) " is missing a \"name\" field")
{:status-code 400})))
+ (when-let [error (manifest/identifier-error (:name parsed))]
+ (throw (ex-info (str (manifest/manifest-path) " is invalid: " error)
+ {:status-code 400})))
{:bytes bundle-bytes
:hash (bytes-hash bundle-bytes)
:manifest parsed
diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/manifest.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/manifest.clj
index 7493a0e1704..39a9a83fc52 100644
--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/manifest.clj
+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/manifest.clj
@@ -45,6 +45,13 @@
[manifest]
(some-> (mr/explain ManifestFieldTypes manifest) me/humanize))
+(defn identifier-error
+ "Why `identifier` can't name a plugin, or nil. `:` separates the parts of `custom-viz:<identifier>:<setting id>`
+ viz-settings keys, so an identifier containing it could read another plugin's settings."
+ [identifier]
+ (when (and (string? identifier) (str/includes? identifier ":"))
+ (format "Plugin identifier \"%s\" must not contain \":\"" identifier)))
+
;;; ------------------------------------------------ Version ------------------------------------------------
(defn compatible?
diff --git a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/api_test.clj b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/api_test.clj
index 34ed8eb40f6..14bf0e9e350 100644
--- a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/api_test.clj
@@ -115,6 +115,14 @@
(is (contains? identifiers "active-viz"))
(is (not (contains? identifiers "disabled-viz")))
(is (not (contains? identifiers "error-viz"))))))
+ (testing "/list skips a legacy plugin whose identifier contains \":\""
+ (mt/with-temp [:model/CustomVizPlugin _ {:identifier "colon:viz"
+ :display_name "Colon Viz"
+ :status :active
+ :enabled true
+ :bundle_hash "colon-hash"}]
+ (let [identifiers (set (map :identifier (mt/user-http-request :rasta :get 200 "ee/custom-viz-plugin/list")))]
+ (is (not (contains? identifiers "colon:viz"))))))
(testing "/list does not expose the raw bundle blob"
(mt/with-temp [:model/CustomVizPlugin _ {:identifier "bundle-viz"
:display_name "Bundle Viz"
@@ -134,6 +142,31 @@
entry (first (filter #(= "cachebust-viz" (:identifier %)) result))]
(is (re-find #"\?v=deadbeefcafe$" (:bundle_url entry))))))))
+(deftest admin-listing-flags-invalid-identifier-test
+ (mt/with-premium-features #{:custom-viz}
+ (testing "GET / flags a legacy plugin whose identifier contains \":\" with an invalid-identifier warning"
+ (mt/with-temp [:model/CustomVizPlugin _ {:identifier "colon:viz"
+ :display_name "Colon Viz"
+ :status :active
+ :enabled true
+ :bundle_hash "colon-hash"}
+ :model/CustomVizPlugin _ {:identifier "colon:dev-viz"
+ :display_name "Colon Dev Viz"
+ :status :active
+ :enabled true
+ :dev_bundle_url "http://localhost:5174"}]
+ (let [plugins (mt/user-http-request :crowberto :get 200 "ee/custom-viz-plugin/")
+ warn-types (fn [identifier]
+ (->> plugins
+ (filter #(= identifier (:identifier %)))
+ first
+ :warnings
+ (map :type)
+ set))]
+ (is (contains? (warn-types "colon:viz") "invalid-identifier"))
+ (is (contains? (warn-types "colon:dev-viz") "invalid-identifier")
+ "dev-only plugins are exempt from version warnings but not from this one"))))))
+
;;; ------------------------------------------------ Bundle bytes not exposed ------------------------------------------------
(deftest bundle-bytes-not-exposed-test
@@ -389,7 +422,12 @@
(let [resp (mt/user-http-request :crowberto :post 400 "ee/custom-viz-plugin/dev"
{:dev_bundle_url "http://localhost:5174"})]
(is (str/includes? resp "name")
- "error should mention the missing name field"))))))))
+ "error should mention the missing name field"))))
+ (testing "dev plugin registration rejects an identifier containing `:`"
+ (mt/with-dynamic-fn-redefs [cache/fetch-dev-manifest (constantly {:name "a:b"})]
+ (let [resp (mt/user-http-request :crowberto :post 400 "ee/custom-viz-plugin/dev"
+ {:dev_bundle_url "http://localhost:5174"})]
+ (is (str/includes? resp "must not contain \":\"")))))))))
;;; ------------------------------------------------ Bundle Replace ------------------------------------------------
@@ -428,6 +466,19 @@
:method :put)]
(is (re-find #"does not match" (or (:message resp) (str resp)))))))))
+(deftest replace-bundle-legacy-colon-identifier-test
+ (mt/with-premium-features #{:custom-viz}
+ (testing "PUT /:id/bundle refuses a legacy colon-identifier plugin with a delete-and-recreate hint"
+ (mt/with-temp [:model/CustomVizPlugin {id :id} {:identifier "colon:replace-viz"
+ :display_name "Colon Replace Viz"
+ :status :active
+ :bundle_hash "abc"}]
+ (let [zip (cvp.tu/valid-bundle-bytes "colon:replace-viz")
+ resp (multipart-upload! :crowberto 400
+ (str "ee/custom-viz-plugin/" id "/bundle") zip
+ :method :put)]
+ (is (re-find #"contains \":\", which is no longer allowed" (or (:message resp) (str resp)))))))))
+
;;; ------------------------------------------------ Update / Refresh ------------------------------------------------
(deftest refresh-upload-plugin-test
diff --git a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/cache_test.clj b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/cache_test.clj
index 948bf9bc3c1..c17d0495ee4 100644
--- a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/cache_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/cache_test.clj
@@ -71,6 +71,14 @@
(is (thrown-with-msg? Exception #"\"name\""
(cache/validate-bundle! bytes))))))
+(deftest validate-bundle-rejects-colon-in-name-test
+ (testing "a name containing `:` is rejected, it is the viz-settings key separator"
+ (let [bytes (cvp.tu/make-tgz-bytes
+ [["metabase-plugin.json" (json/encode {:name "a:b"})]
+ ["dist/index.js" "console.log('hi')"]])]
+ (is (thrown-with-msg? Exception #"must not contain \":\""
+ (cache/validate-bundle! bytes))))))
+
(deftest validate-bundle-rejects-invalid-json-manifest-test
(testing "non-JSON manifest is rejected"
(let [bytes (cvp.tu/make-tgz-bytes
diff --git a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/manifest_test.clj b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/manifest_test.clj
index cff4ec33ae1..96e2ec1218a 100644
--- a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/manifest_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/manifest_test.clj
@@ -203,3 +203,9 @@
(is (nil? (manifest/asset-content-type "data.csv")))
;; .html has MIME text/html — should be rejected
(is (nil? (manifest/asset-content-type "page.html")))))
+
+(deftest identifier-error-test
+ (testing "`:` is the viz-settings key separator"
+ (is (nil? (manifest/identifier-error "demo-viz")))
+ (is (= "Plugin identifier \"demo:viz\" must not contain \":\""
+ (manifest/identifier-error "demo:viz")))))
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.ts b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.ts
index 1ea8b5131bb..045d0b7e0fc 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.ts
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.ts
@@ -25,5 +25,10 @@ export function getCustomVizPluginWarningMessage(
// eslint-disable-next-line metabase/no-literal-metabase-strings -- admin-only custom-viz settings page
t`Requires Metabase ${metabase_version}, but this instance is on ${current_version}.`,
)
+ .with(
+ { type: "invalid-identifier" },
+ ({ identifier }) =>
+ t`The identifier "${identifier}" contains ":", which is no longer allowed, so this visualization isn't served to viewers. Delete it and upload the bundle under a name without ":".`,
+ )
.exhaustive();
}
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.unit.spec.ts
index 817836c7fc2..a706d423e84 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/warning-messages.unit.spec.ts
@@ -34,4 +34,15 @@ describe("getCustomVizPluginWarningMessage", () => {
}),
).toBe("Requires Metabase >=1.99, but this instance is on v1.64.0.");
});
+
+ it("describes a legacy colon identifier", () => {
+ expect(
+ getCustomVizPluginWarningMessage({
+ type: "invalid-identifier",
+ identifier: "acme:viz",
+ }),
+ ).toBe(
+ `The identifier "acme:viz" contains ":", which is no longer allowed, so this visualization isn't served to viewers. Delete it and upload the bundle under a name without ":".`,
+ );
+ });
});
diff --git a/frontend/src/metabase-types/api/custom-viz-plugin.ts b/frontend/src/metabase-types/api/custom-viz-plugin.ts
index 35fe03d477e..2ba6eff6d0b 100644
--- a/frontend/src/metabase-types/api/custom-viz-plugin.ts
+++ b/frontend/src/metabase-types/api/custom-viz-plugin.ts
@@ -51,6 +51,10 @@ export type CustomVizPluginWarning =
type: "metabase-version-mismatch";
metabase_version: string;
current_version: string;
+ }
+ | {
+ type: "invalid-identifier";
+ identifier: string;
};
/**