🐛 Fix problem with Penpot plugins being blocked (#13147)

This commit is contained in:
Alonso Torres 2026-11-19 11:21:54 +01:00 committed by GitHub
parent 981fa06961
commit 951ebbba6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 13 deletions

View File

@ -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")))

View File

@ -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}))

View File

@ -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"))))))

View File

@ -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"

View File

@ -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"