From 2fbda0ef4cf41394a2218a07220cdc326eba8406 Mon Sep 17 00:00:00 2001 From: jackkav Date: Thu, 9 Jul 2026 16:59:23 +0200 Subject: [PATCH] fix(review): filter unknown capabilities; grant bundle plugins all modules (C1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolveTemplateTagCapabilities now drops declared names that aren't real Capability values, matching its docstring (keeps the envelope clean for the P1 ceiling intersection). - Bundle (trusted first-party) plugins now receive ALL_SANDBOX_MODULES too, so the 'every module + capability' comment is accurate — they no longer silently run on the baseline module set. --- .../insomnia/src/main/templating-worker-database.ts | 10 +++++++--- .../insomnia/src/templating/sandbox/host-bridge.ts | 9 +++++---- .../insomnia/src/templating/sandbox/module-registry.ts | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/insomnia/src/main/templating-worker-database.ts b/packages/insomnia/src/main/templating-worker-database.ts index 830cada0ca..29ff181d23 100644 --- a/packages/insomnia/src/main/templating-worker-database.ts +++ b/packages/insomnia/src/main/templating-worker-database.ts @@ -426,10 +426,14 @@ const pluginToMainAPI: Record Promise< const settings = await services.settings.get(); if (settings.templateTagSandboxEnabled) { const { ALL_CAPABILITIES } = await import('../templating/sandbox/host-bridge'); + const { ALL_SANDBOX_MODULES } = await import('../templating/sandbox/module-registry'); // Bundle plugins are first-party and trusted: grant every module + capability. - return runPluginTagInSandbox(getPluginEntrySource({ directory: '', name: pluginName }), body, undefined, [ - ...ALL_CAPABILITIES, - ]); + return runPluginTagInSandbox( + getPluginEntrySource({ directory: '', name: pluginName }), + body, + [...ALL_SANDBOX_MODULES], + [...ALL_CAPABILITIES], + ); } return runPluginTag(targetTag.run, body); } diff --git a/packages/insomnia/src/templating/sandbox/host-bridge.ts b/packages/insomnia/src/templating/sandbox/host-bridge.ts index 51d8cf6864..46a30da901 100644 --- a/packages/insomnia/src/templating/sandbox/host-bridge.ts +++ b/packages/insomnia/src/templating/sandbox/host-bridge.ts @@ -114,14 +114,15 @@ export const ALL_CAPABILITIES: Capability[] = [ export const TEMPLATE_TAG_BASELINE_CAPABILITIES: Capability[] = ['render', 'models.read', 'util', 'crypto']; /** - * Resolve the capability set a template-tag plugin gets: the baseline floor plus whatever it - * declared in `insomnia.permissions.capabilities` (unknown names are ignored — they map to no - * bridge path). Profile-ceiling intersection is added in P1. + * Resolve the capability set a template-tag plugin gets: the baseline floor plus whatever known + * capabilities it declared in `insomnia.permissions.capabilities`. Unknown names are dropped (they + * map to no bridge path), so the resolved set only ever contains real `Capability` values — which + * keeps the envelope clean for the P1 profile-ceiling intersection. */ export const resolveTemplateTagCapabilities = (declaredCapabilities: string[] = []): string[] => { const resolved: string[] = [...TEMPLATE_TAG_BASELINE_CAPABILITIES]; for (const name of declaredCapabilities) { - if (!resolved.includes(name as Capability)) { + if (ALL_CAPABILITIES.includes(name as Capability) && !resolved.includes(name as Capability)) { resolved.push(name); } } diff --git a/packages/insomnia/src/templating/sandbox/module-registry.ts b/packages/insomnia/src/templating/sandbox/module-registry.ts index 890728f6e8..3b83fd42f5 100644 --- a/packages/insomnia/src/templating/sandbox/module-registry.ts +++ b/packages/insomnia/src/templating/sandbox/module-registry.ts @@ -123,6 +123,9 @@ export const SANDBOX_MODULES: SandboxModuleDefinition[] = [ */ export const TEMPLATE_TAG_BASELINE_MODULES: string[] = ['path', 'crypto']; +/** Every registered module name — the trusted grant for first-party bundle plugins. */ +export const ALL_SANDBOX_MODULES: string[] = SANDBOX_MODULES.map(m => m.name); + /** * Resolve the module set a template-tag plugin may `require()`: the baseline floor plus whatever the * plugin declared in `insomnia.permissions.modules`. Unknown declared names are harmless here —