nyxora 1.4.7 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.pluginManager = exports.PluginManager = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const vm_1 = __importDefault(require("vm"));
9
10
  class PluginManager {
10
11
  skills = new Map();
11
12
  async loadPlugins() {
@@ -18,20 +19,43 @@ class PluginManager {
18
19
  for (const file of files) {
19
20
  if (file.endsWith('.js') || file.endsWith('.ts')) {
20
21
  try {
21
- // Dynamic import requires relative path from this file or absolute path
22
- // For TS compiled to JS, absolute path is safer
23
22
  const absolutePath = path_1.default.resolve(pluginsDir, file);
24
- // Note: In development with ts-node, requiring .ts works.
25
- // In production, we need compiled .js files.
26
- const module = require(absolutePath);
27
- if (module.toolDefinition && module.execute) {
28
- const toolName = module.toolDefinition.function.name;
29
- this.skills.set(toolName, module);
30
- console.log(`[PluginManager] Loaded external skill: ${toolName}`);
23
+ const code = fs_1.default.readFileSync(absolutePath, 'utf8');
24
+ // Construct a restricted require function for the sandbox
25
+ const restrictedRequire = (moduleName) => {
26
+ const blockedModules = ['fs', 'child_process', 'os', 'net', 'tls', 'cluster', 'worker_threads'];
27
+ if (blockedModules.includes(moduleName)) {
28
+ throw new Error(`Sandboxing error: Access to the '${moduleName}' module is blocked for security reasons.`);
29
+ }
30
+ // Allow fetch and other safe modules by delegating to actual require
31
+ return require(moduleName);
32
+ };
33
+ // Create the sandbox environment
34
+ const sandbox = {
35
+ require: restrictedRequire,
36
+ console: console,
37
+ module: { exports: {} },
38
+ exports: {},
39
+ process: { env: {} }, // Hide actual environment variables
40
+ Buffer: Buffer,
41
+ setTimeout: setTimeout,
42
+ clearTimeout: clearTimeout,
43
+ setInterval: setInterval,
44
+ clearInterval: clearInterval,
45
+ };
46
+ const context = vm_1.default.createContext(sandbox);
47
+ const script = new vm_1.default.Script(code, { filename: file });
48
+ // Execute the plugin code inside the VM
49
+ script.runInContext(context);
50
+ const moduleExports = sandbox.module.exports;
51
+ if (moduleExports.toolDefinition && moduleExports.execute) {
52
+ const toolName = moduleExports.toolDefinition.function.name;
53
+ this.skills.set(toolName, moduleExports);
54
+ console.log(`[PluginManager] Loaded sandboxed external skill: ${toolName}`);
31
55
  }
32
56
  }
33
57
  catch (error) {
34
- console.error(`[PluginManager] Failed to load plugin ${file}:`, error);
58
+ console.error(`[PluginManager] Failed to load sandboxed plugin ${file}:`, error.message);
35
59
  }
36
60
  }
37
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nyxora",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "",
5
5
  "main": "dist/gateway/cli.js",
6
6
  "files": [