From 38ce7b5dd25db0ec058090ffbb4ab0b707a9bfad Mon Sep 17 00:00:00 2001 From: miracle Date: Mon, 5 Oct 2026 14:32:59 +0800 Subject: [PATCH] feat(plugins): per-plugin graphics engine grant for unsafe-eval CSP --- .../plugins/PluginContributionsPanel.vue | 15 ++++ .../PluginGraphicsEngineSection.spec.ts | 72 +++++++++++++++++++ .../plugins/PluginGraphicsEngineSection.vue | 52 ++++++++++++++ .../plugins/PluginWorkbenchHost.vue | 21 ++++-- .../PluginContributionsPanelBatch.spec.ts | 6 ++ apps/desktop/src/i18n/locales/az.ts | 6 ++ apps/desktop/src/i18n/locales/en.ts | 6 ++ apps/desktop/src/i18n/locales/es.ts | 6 ++ apps/desktop/src/i18n/locales/id.ts | 6 ++ apps/desktop/src/i18n/locales/it.ts | 6 ++ apps/desktop/src/i18n/locales/ja.ts | 6 ++ apps/desktop/src/i18n/locales/ko.ts | 6 ++ apps/desktop/src/i18n/locales/pt-BR.ts | 6 ++ apps/desktop/src/i18n/locales/ru.ts | 6 ++ apps/desktop/src/i18n/locales/tr.ts | 6 ++ apps/desktop/src/i18n/locales/zh-CN.ts | 6 ++ apps/desktop/src/i18n/locales/zh-TW.ts | 6 ++ .../lib/plugins/pluginGraphicsEngine.spec.ts | 31 ++++++++ .../src/lib/plugins/pluginGraphicsEngine.ts | 35 +++++++++ .../src/lib/plugins/pluginHostBridge.spec.ts | 16 +++++ .../src/lib/plugins/pluginHostBridge.ts | 10 ++- .../src/lib/plugins/pluginUiHtmlCache.ts | 6 +- apps/desktop/src/stores/settingsStore.ts | 6 ++ 23 files changed, 333 insertions(+), 9 deletions(-) create mode 100644 apps/desktop/src/components/plugins/PluginGraphicsEngineSection.spec.ts create mode 100644 apps/desktop/src/components/plugins/PluginGraphicsEngineSection.vue create mode 100644 apps/desktop/src/lib/plugins/pluginGraphicsEngine.spec.ts create mode 100644 apps/desktop/src/lib/plugins/pluginGraphicsEngine.ts diff --git a/apps/desktop/src/components/plugins/PluginContributionsPanel.vue b/apps/desktop/src/components/plugins/PluginContributionsPanel.vue index c7f34e1ea8..9a5f7df240 100644 --- a/apps/desktop/src/components/plugins/PluginContributionsPanel.vue +++ b/apps/desktop/src/components/plugins/PluginContributionsPanel.vue @@ -15,6 +15,7 @@ import { useToast } from "@/composables/useToast"; import PluginShortcutSettings from "./PluginShortcutSettings.vue"; import PluginIcon from "@/components/plugins/PluginIcon.vue"; import PluginAiAccessSection from "@/components/plugins/PluginAiAccessSection.vue"; +import PluginGraphicsEngineSection from "@/components/plugins/PluginGraphicsEngineSection.vue"; import * as api from "@/lib/backend/api"; import { clearPluginIconCache } from "@/lib/plugins/pluginIconResolver"; import { loadPinnedPluginIds, savePinnedPluginIds, sortPluginsPinnedFirst } from "@/lib/plugins/pluginPinning"; @@ -43,6 +44,7 @@ import { formatBytes } from "@/lib/database/serverMetrics"; import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation"; import { useConnectionStore } from "@/stores/connectionStore"; import { useQueryStore } from "@/stores/queryStore"; +import { useSettingsStore } from "@/stores/settingsStore"; import type { InstalledPlugin, PluginInstallResult, PluginRepository, PluginRepositoryCatalogResult, PluginTrustedKey } from "@/types/database"; import { useI18n } from "vue-i18n"; import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage"; @@ -84,6 +86,15 @@ const { t, locale: appLocale } = useI18n(); const { toast } = useToast(); const connectionStore = useConnectionStore(); const queryStore = useQueryStore(); +const settingsStore = useSettingsStore(); + +// A reinstall must start without consent: drop any graphics-engine (unsafe-eval) grant +// when the plugin is uninstalled, mirroring the backend's forget_plugin_permissions. +function forgetGraphicsEngineGrant(pluginId: string) { + const granted = settingsStore.editorSettings.pluginGraphicsEngineIds; + if (!granted.includes(pluginId)) return; + settingsStore.updateEditorSettings({ pluginGraphicsEngineIds: granted.filter((id) => id !== pluginId) }); +} const activeSection = ref<"marketplace" | "installed" | "settings">("marketplace"); const installedPlugins = ref([]); const trustedKeys = ref([]); @@ -653,6 +664,7 @@ async function runBatchUninstall() { (definition) => definition.plugin.manifest.name, async (definition) => { await api.uninstallPlugin(definition.plugin.manifest.id); + forgetGraphicsEngineGrant(definition.plugin.manifest.id); }, (definition) => definition.plugin.manifest.id, ); @@ -1034,6 +1046,7 @@ async function uninstallSelectedPlugin() { operating.value = true; try { applyInstalledPlugins(await api.uninstallPlugin(definition.plugin.manifest.id)); + forgetGraphicsEngineGrant(definition.plugin.manifest.id); retireBatchFailure(definition.plugin.manifest.id); notifyComponentUpdatesChanged(); window.dispatchEvent(new CustomEvent("dbx:plugins-changed")); @@ -1569,6 +1582,8 @@ onBeforeUnmount(() => { + +