fix(review): filter unknown capabilities; grant bundle plugins all modules (C1)

- 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.
This commit is contained in:
jackkav
2026-07-09 16:59:23 +02:00
parent e0d0c783c8
commit 2fbda0ef4c
3 changed files with 15 additions and 7 deletions

View File

@@ -426,10 +426,14 @@ const pluginToMainAPI: Record<PluginToMainAPIPaths, (...args: any[]) => 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);
}

View File

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

View File

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