(pluginName: string, manifest: PluginExportManifest)
| 78 | } |
| 79 | |
| 80 | function buildUserPluginModuleFromManifest(pluginName: string, manifest: PluginExportManifest): Plugin['module'] { |
| 81 | const notRouted = (surface: string) => () => { |
| 82 | throw new Error( |
| 83 | `Plugin "${pluginName}": sandboxed ${surface} are not supported yet. Disable "Run template tags in sandbox" to use them.`, |
| 84 | ); |
| 85 | }; |
| 86 | const toAction = (surface: string) => (a: ActionDescriptor) => ({ |
| 87 | label: a.label ?? '', |
| 88 | icon: a.icon, |
| 89 | action: notRouted(surface), |
| 90 | }); |
| 91 | // The count comes from untrusted sandbox output; clamp to a finite, non-negative, bounded integer |
| 92 | // before allocating so a hostile manifest can't drive a huge Array.from allocation (the sandbox |
| 93 | // clamps too — this is defense in depth). |
| 94 | const hookStubs = (count: number, surface: string) => |
| 95 | Array.from({ length: Number.isFinite(count) && count > 0 ? Math.min(Math.floor(count), 1000) : 0 }, () => |
| 96 | notRouted(surface), |
| 97 | ); |
| 98 | return { |
| 99 | templateTags: manifest.templateTags.map(t => ({ ...t, run: notRouted('template-tag run()') }) as PluginTemplateTag), |
| 100 | requestHooks: hookStubs(manifest.requestHooks, 'request hooks'), |
| 101 | responseHooks: hookStubs(manifest.responseHooks, 'response hooks'), |
| 102 | requestActions: manifest.requestActions.map(toAction('request actions')), |
| 103 | requestGroupActions: manifest.requestGroupActions.map(toAction('request group actions')), |
| 104 | workspaceActions: manifest.workspaceActions.map(toAction('workspace actions')), |
| 105 | documentActions: manifest.documentActions.map(toAction('document actions')), |
| 106 | themes: manifest.themes, |
| 107 | } as Plugin['module']; |
| 108 | } |
| 109 | |
| 110 | // A plugin name of "__proto__"/"constructor"/"prototype" must never be used as a pluginMap key, since that would write onto Object.prototype instead of a normal property. |
| 111 | const DANGEROUS_PLUGIN_KEYS = new Set(['__proto__', 'constructor', 'prototype']); |
no test coverage detected