MCPcopy Create free account
hub / github.com/Kong/insomnia / buildUserPluginModuleFromManifest

Function buildUserPluginModuleFromManifest

packages/insomnia/src/plugins/index.ts:80–108  ·  view source on GitHub ↗
(pluginName: string, manifest: PluginExportManifest)

Source from the content-addressed store, hash-verified

78}
79
80function 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.
111const DANGEROUS_PLUGIN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);

Callers 1

traversePluginPathFunction · 0.85

Calls 4

notRoutedFunction · 0.85
hookStubsFunction · 0.85
toActionFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected