From 951ebbba6ac70316c2fb41af7359a67301ef0fdb Mon Sep 17 00:00:00 2001 From: Alonso Torres Date: Thu, 19 Nov 2026 11:21:54 +0100 Subject: [PATCH] :bug: Fix problem with Penpot plugins being blocked (#13147) --- frontend/src/app/main/data/plugins.cljs | 2 +- frontend/src/app/plugins/register.cljs | 27 ++++++++---- .../frontend_tests/plugins/register_test.cljs | 44 ++++++++++++++++++- frontend/translations/en.po | 2 +- frontend/translations/es.po | 2 +- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/main/data/plugins.cljs b/frontend/src/app/main/data/plugins.cljs index 4d3f8b5ef5..7e489d1351 100644 --- a/frontend/src/app/main/data/plugins.cljs +++ b/frontend/src/app/main/data/plugins.cljs @@ -63,7 +63,7 @@ [plugin] (when (and (preg/global-requested? plugin) (not (preg/global-allowed? plugin))) - (log/warn :hint "Global plugins can only be loaded from localhost" + (log/warn :hint "Global plugins are not allowed from this host" :plugin-id (:plugin-id plugin) :host (:host plugin)) (st/emit! (ntf/warn (tr "workspace.plugins.error.global-not-allowed"))) diff --git a/frontend/src/app/plugins/register.cljs b/frontend/src/app/plugins/register.cljs index 5c7c4b4fe6..d1ab6ea5ac 100644 --- a/frontend/src/app/plugins/register.cljs +++ b/frontend/src/app/plugins/register.cljs @@ -34,14 +34,25 @@ (def global-permissions #{"allow:global" "manage:projects" "manage:teams" "manage:delete"}) -(def ^:private local-hosts +;; Loopback hosts that may serve global plugins over any scheme +(def ^:private trusted-hosts #{"localhost" "127.0.0.1" "[::1]" "::1"}) -(defn- local-url? - "True when the url host is a loopback name, ignoring case and a - trailing dot." +;; Domains whose https subdomains may serve global plugins +(def ^:private trusted-domains + #{"penpot.dev" "penpot.app"}) + +(defn- trusted-url? + "True when the url host is one of `trusted-hosts`, or the url uses + https and its host is a subdomain of one of `trusted-domains`. Hosts + are compared ignoring case and a trailing dot." [url] - (contains? local-hosts (some-> url u/uri :host str/lower (str/rtrim ".")))) + (let [uri (some-> url u/uri) + host (some-> uri :host str/lower (str/rtrim "."))] + (or (contains? trusted-hosts host) + (and (= "https" (some-> uri :scheme str/lower)) + (some? host) + (boolean (some #(str/ends-with? host (str "." %)) trusted-domains)))))) (defn global-requested? "True when the plugin asks for global scope or a management permission." @@ -52,10 +63,10 @@ (defn global-allowed? "True when the plugin may run with global scope and use the management API. The feature is still in progress, so only the bundled MCP plugin - and plugins served from localhost get it." + and plugins served from a trusted url get it." [{:keys [plugin-id host]}] (or (= plugin-id mcp-plugin-id) - (local-url? host))) + (trusted-url? host))) ;; Promise that resolves when plugins runtime is initialized. ;; Lives here to avoid circular dependency: workspace.mcp -> app.plugins -> app.plugins.api -> workspace @@ -155,7 +166,7 @@ (and (global-requested? manifest) (not (global-allowed? manifest))) - (throw (ex-info "Global plugins can only be loaded from localhost" + (throw (ex-info "Global plugins are not allowed from this host" {:type ::global-not-allowed :host origin})) diff --git a/frontend/test/frontend_tests/plugins/register_test.cljs b/frontend/test/frontend_tests/plugins/register_test.cljs index afa0cfe304..b59b3141cc 100644 --- a/frontend/test/frontend_tests/plugins/register_test.cljs +++ b/frontend/test/frontend_tests/plugins/register_test.cljs @@ -363,11 +363,45 @@ (t/is (preg/global-allowed? {:plugin-id preg/mcp-plugin-id :host "https://design.penpot.app/plugins/mcp/"})) (doseq [host ["http://localhost:4400/" "http://127.0.0.1:4400/" "http://[::1]:4400/" - "http://LOCALHOST:4400/" "http://LocalHost/" "http://localhost.:4400/"]] + "http://LOCALHOST:4400/" "http://LocalHost/" "http://localhost.:4400/" + "https://localhost:4400/" "https://127.0.0.1/"]] (t/is (preg/global-allowed? {:plugin-id "local" :host host}) host)) (t/is (not (preg/global-allowed? {:plugin-id "remote" :host "https://plugins.example.com/"}))) (t/is (not (preg/global-allowed? {:plugin-id "remote" :host "https://localhost.example.com/"})))) +(t/deftest global-plugins-are-allowed-for-penpot-domains + (doseq [host ["https://api-test-suite.plugins.penpot.dev/" + "https://design.penpot.dev/plugins/x/" + "https://plugins.penpot.app/" + "https://Plugins.PENPOT.app./"]] + (t/is (preg/global-allowed? {:plugin-id "penpot" :host host}) host)) + (doseq [host ["http://api-test-suite.plugins.penpot.dev/" + "https://penpot.dev/" + "https://penpot.app/" + "https://evilpenpot.app/" + "https://penpot.app.example.com/" + "https://plugins.penpot.dev.example.com/"]] + (t/is (not (preg/global-allowed? {:plugin-id "remote" :host host})) host))) + +(t/deftest parse-manifest-keeps-localhost-management-permissions + (let [manifest (preg/parse-manifest + "http://localhost:4400/manifest.json" + #js {:name "Local management plugin" + :code "plugin.js" + :permissions #js ["content:read" "manage:projects" "manage:teams" "manage:delete"]})] + (t/is (= #{"content:read" "manage:projects" "manage:teams" "manage:delete"} + (:permissions manifest))))) + +(t/deftest parse-manifest-keeps-penpot-domain-global-scope + (let [manifest (preg/parse-manifest + "https://api-test-suite.plugins.penpot.dev/manifest.json" + #js {:name "Penpot global plugin" + :code "plugin.js" + :scope "global" + :permissions #js ["content:read" "manage:projects"]})] + (t/is (= "global" (:scope manifest))) + (t/is (contains? (:permissions manifest) "manage:projects")))) + (t/deftest parse-manifest-rejects-remote-global-scope (t/is (= ::preg/global-not-allowed (global-not-allowed-error @@ -413,5 +447,11 @@ (t/is (preg/has-permission? "reg-global-remote" "content:read")) (t/is (not (preg/has-permission? "reg-global-remote" "allow:global"))) (t/is (not (preg/has-permission? "reg-global-remote" "manage:projects"))) + (preg/install-plugin! {:plugin-id "reg-global-penpot" + :host "https://api-test-suite.plugins.penpot.dev/" + :scope "global" + :permissions permissions}) (t/is (preg/has-permission? "reg-global-local" "allow:global")) - (t/is (preg/has-permission? "reg-global-local" "manage:projects")))))) + (t/is (preg/has-permission? "reg-global-local" "manage:projects")) + (t/is (preg/has-permission? "reg-global-penpot" "allow:global")) + (t/is (preg/has-permission? "reg-global-penpot" "manage:projects")))))) diff --git a/frontend/translations/en.po b/frontend/translations/en.po index b90c25212a..d50bda0f83 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -8552,7 +8552,7 @@ msgstr "No plugins installed yet" #: src/app/main/data/plugins.cljs, src/app/main/ui/dashboard.cljs, src/app/main/ui/workspace/plugins.cljs msgid "workspace.plugins.error.global-not-allowed" -msgstr "Plugins that work outside a file can only be installed from localhost for now." +msgstr "Plugins that work outside a file can only be installed from trusted sources for now." #: src/app/main/ui/workspace/plugins.cljs:237 msgid "workspace.plugins.error.manifest" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index c6c13b91af..b611f2c42c 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -8629,7 +8629,7 @@ msgstr "No se encuentran extensiones" #: src/app/main/data/plugins.cljs, src/app/main/ui/dashboard.cljs, src/app/main/ui/workspace/plugins.cljs msgid "workspace.plugins.error.global-not-allowed" -msgstr "Por ahora, las extensiones que funcionan fuera de un archivo solo se pueden instalar desde localhost." +msgstr "Por ahora, las extensiones que funcionan fuera de un archivo solo se pueden instalar desde fuentes de confianza." #: src/app/main/ui/workspace/plugins.cljs:237 msgid "workspace.plugins.error.manifest"