{"id":"GHSA-fm76-w8jw-xf8m","aliases":[],"status":"published","title":"@saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source","description":"### Summary\n\nWhen creating a new plugin using the `git` source, the user-controlled value `req.body.name` is used to build the plugin directory where the location will be cloned. The API used to execute the `git clone` command with the user-controlled data is `child_process.execSync`. Since the user-controlled data is not validated, a user with admin permission can add escaping characters and execute arbitrary commands, leading to a command injection vulnerability.\n\n### Details\n\nRelevant code from source (`req.body`) to sink (`child_process.execSync`).\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400\n\n```js\nrouter.post(\n  \"/\",\n  isAdmin,\n  error_catcher(async (req, res) =\u003e {\n    const plugin = new Plugin(req.body); // [1] \n      [...]\n      try {\n        await load_plugins.loadAndSaveNewPlugin( // [3] \n          plugin,\n          schema === db.connectObj.default_schema || plugin.source === \"github\"\n        );\n        [...]\n    }\n  })\n);\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44\n```js\nclass Plugin {\n  [...]\n  constructor(o: PluginCfg | PluginPack | Plugin) {\n    [...]\n    this.name = o.name; // [2] \n    [...]\n}\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65\n```js\nconst loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) =\u003e {\n  [...]\n  const loader = new PluginInstaller(plugin); // [4] \n  const res = await loader.install(force); // [7] \n  [...]\n};\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61\n```js\nclass PluginInstaller {\n  constructor(plugin, opts = {}) {\n    [...]\n    const tokens =\n      plugin.source === \"npm\"\n        ? plugin.location.split(\"/\")\n        : plugin.name.split(\"/\"); // [5] \n    [...]\n    this.tempDir = join(this.tempRootFolder, \"temp_install\", ...tokens); // [6] \n    [...]\n  }\n\n  \n  async install(force) {\n    [...]\n    if (await this.prepPluginsFolder(force, pckJSON)) { // [8] \n    [...]\n  }\n\n  async prepPluginsFolder(force, pckJSON) {\n    [...]\n    switch (this.plugin.source) {\n      [...]\n      case \"git\":\n        if (force || !(await pathExists(this.pluginDir))) { \n          await gitPullOrClone(this.plugin, this.tempDir); // [9] \n\t  [...]\n  }\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112\n```js\nconst gitPullOrClone = async (plugin, pluginDir) =\u003e {\n  [...]\n  if (fs.existsSync(pluginDir)) {\n    execSync(`git ${setKey} -C ${pluginDir} pull`);\n  } else {\n    execSync(`git ${setKey} clone ${plugin.location} ${pluginDir}`); // [10] \n  }\n  [...]\n};\n```\n\n### PoC\n\n- check that the file will be created by the command `echo \"hello\"\u003e/tmp/HACKED` does not exists:\n```\ncat /tmp/HACKED\ncat: /tmp/HACKED: No such file or directory\n```\n- login with an admin account\n- visit `http://localhost:3000/plugins/new`\n- enter the following fields:\n\t- Name: `;echo \"hello\"\u003e/tmp/HACKED`\n\t- Source: `git`\n\t- other fields blank\n- click `Create`\n- you will get an error saying `ENOENT: no such file or directory,  ....` but the command `touch /tmp/HACKED` will be executed\n- to verify:\n```\ncat /tmp/HACKED\nhello\n```\n\n### Impact\n\nRemote code execution\n\n### Recommended Mitigation\n\nSanitize the `pluginDir` value before passing to `execSync`. Alternatively, use `child_process. execFileSync` API (docs: https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options)","severity":{"version":"4.0","score":7.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P","level":"high","from":"ghsa"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"cwes":["CWE-78"],"published":"2024-10-03T22:21:24Z","modified":"2024-10-04T16:51:27Z","fixes":[{"ecosystem":"npm","package":"@saltcorn/plugins-loader","fixed_in":["1.0.0-beta.14"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"npm","package":"@saltcorn/plugins-loader","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"last_affected":"1.0.0-beta.13"},{"fixed":"1.0.0-beta.14"}]}]},{"source":"osv","ecosystem":"npm","package":"@saltcorn/plugins-loader","ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"1.0.0-beta.14"}]}]}],"references":[{"url":"https://github.com/saltcorn/saltcorn/security/advisories/GHSA-fm76-w8jw-xf8m","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/commit/024f19a7e079913f62f4a2335ab04116ddb68192","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65","tags":["web"]},{"url":"https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400","tags":["web"]},{"url":"https://github.com/advisories/GHSA-fm76-w8jw-xf8m"},{"url":"https://github.com/saltcorn/saltcorn","tags":["package"]}],"sources":{"ghsa":[{"id":"GHSA-fm76-w8jw-xf8m","title":"@saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source","description":"### Summary\n\nWhen creating a new plugin using the `git` source, the user-controlled value `req.body.name` is used to build the plugin directory where the location will be cloned. The API used to execute the `git clone` command with the user-controlled data is `child_process.execSync`. Since the user-controlled data is not validated, a user with admin permission can add escaping characters and execute arbitrary commands, leading to a command injection vulnerability.\n\n### Details\n\nRelevant code from source (`req.body`) to sink (`child_process.execSync`).\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400\n\n```js\nrouter.post(\n  \"/\",\n  isAdmin,\n  error_catcher(async (req, res) =\u003e {\n    const plugin = new Plugin(req.body); // [1] \n      [...]\n      try {\n        await load_plugins.loadAndSaveNewPlugin( // [3] \n          plugin,\n          schema === db.connectObj.default_schema || plugin.source === \"github\"\n        );\n        [...]\n    }\n  })\n);\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44\n```js\nclass Plugin {\n  [...]\n  constructor(o: PluginCfg | PluginPack | Plugin) {\n    [...]\n    this.name = o.name; // [2] \n    [...]\n}\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65\n```js\nconst loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) =\u003e {\n  [...]\n  const loader = new PluginInstaller(plugin); // [4] \n  const res = await loader.install(force); // [7] \n  [...]\n};\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61\n```js\nclass PluginInstaller {\n  constructor(plugin, opts = {}) {\n    [...]\n    const tokens =\n      plugin.source === \"npm\"\n        ? plugin.location.split(\"/\")\n        : plugin.name.split(\"/\"); // [5] \n    [...]\n    this.tempDir = join(this.tempRootFolder, \"temp_install\", ...tokens); // [6] \n    [...]\n  }\n\n  \n  async install(force) {\n    [...]\n    if (await this.prepPluginsFolder(force, pckJSON)) { // [8] \n    [...]\n  }\n\n  async prepPluginsFolder(force, pckJSON) {\n    [...]\n    switch (this.plugin.source) {\n      [...]\n      case \"git\":\n        if (force || !(await pathExists(this.pluginDir))) { \n          await gitPullOrClone(this.plugin, this.tempDir); // [9] \n\t  [...]\n  }\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112\n```js\nconst gitPullOrClone = async (plugin, pluginDir) =\u003e {\n  [...]\n  if (fs.existsSync(pluginDir)) {\n    execSync(`git ${setKey} -C ${pluginDir} pull`);\n  } else {\n    execSync(`git ${setKey} clone ${plugin.location} ${pluginDir}`); // [10] \n  }\n  [...]\n};\n```\n\n### PoC\n\n- check that the file will be created by the command `echo \"hello\"\u003e/tmp/HACKED` does not exists:\n```\ncat /tmp/HACKED\ncat: /tmp/HACKED: No such file or directory\n```\n- login with an admin account\n- visit `http://localhost:3000/plugins/new`\n- enter the following fields:\n\t- Name: `;echo \"hello\"\u003e/tmp/HACKED`\n\t- Source: `git`\n\t- other fields blank\n- click `Create`\n- you will get an error saying `ENOENT: no such file or directory,  ....` but the command `touch /tmp/HACKED` will be executed\n- to verify:\n```\ncat /tmp/HACKED\nhello\n```\n\n### Impact\n\nRemote code execution\n\n### Recommended Mitigation\n\nSanitize the `pluginDir` value before passing to `execSync`. Alternatively, use `child_process. execFileSync` API (docs: https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options)\n","status":"published","published":"2024-10-03T22:21:24Z","modified":"2024-10-04T16:51:27Z","cvss":[{"version":"4.0","score":7.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P","level":"high"},{"version":"3.1","score":7.2,"vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H","level":"high"}],"cwes":["CWE-78"],"updated_at":"2026-11-02T14:38:08.742903Z"}],"osv":[{"id":"GHSA-fm76-w8jw-xf8m","title":"@saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source","description":"### Summary\n\nWhen creating a new plugin using the `git` source, the user-controlled value `req.body.name` is used to build the plugin directory where the location will be cloned. The API used to execute the `git clone` command with the user-controlled data is `child_process.execSync`. Since the user-controlled data is not validated, a user with admin permission can add escaping characters and execute arbitrary commands, leading to a command injection vulnerability.\n\n### Details\n\nRelevant code from source (`req.body`) to sink (`child_process.execSync`).\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400\n\n```js\nrouter.post(\n  \"/\",\n  isAdmin,\n  error_catcher(async (req, res) =\u003e {\n    const plugin = new Plugin(req.body); // [1] \n      [...]\n      try {\n        await load_plugins.loadAndSaveNewPlugin( // [3] \n          plugin,\n          schema === db.connectObj.default_schema || plugin.source === \"github\"\n        );\n        [...]\n    }\n  })\n);\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44\n```js\nclass Plugin {\n  [...]\n  constructor(o: PluginCfg | PluginPack | Plugin) {\n    [...]\n    this.name = o.name; // [2] \n    [...]\n}\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65\n```js\nconst loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) =\u003e {\n  [...]\n  const loader = new PluginInstaller(plugin); // [4] \n  const res = await loader.install(force); // [7] \n  [...]\n};\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61\n```js\nclass PluginInstaller {\n  constructor(plugin, opts = {}) {\n    [...]\n    const tokens =\n      plugin.source === \"npm\"\n        ? plugin.location.split(\"/\")\n        : plugin.name.split(\"/\"); // [5] \n    [...]\n    this.tempDir = join(this.tempRootFolder, \"temp_install\", ...tokens); // [6] \n    [...]\n  }\n\n  \n  async install(force) {\n    [...]\n    if (await this.prepPluginsFolder(force, pckJSON)) { // [8] \n    [...]\n  }\n\n  async prepPluginsFolder(force, pckJSON) {\n    [...]\n    switch (this.plugin.source) {\n      [...]\n      case \"git\":\n        if (force || !(await pathExists(this.pluginDir))) { \n          await gitPullOrClone(this.plugin, this.tempDir); // [9] \n\t  [...]\n  }\n```\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112\n```js\nconst gitPullOrClone = async (plugin, pluginDir) =\u003e {\n  [...]\n  if (fs.existsSync(pluginDir)) {\n    execSync(`git ${setKey} -C ${pluginDir} pull`);\n  } else {\n    execSync(`git ${setKey} clone ${plugin.location} ${pluginDir}`); // [10] \n  }\n  [...]\n};\n```\n\n### PoC\n\n- check that the file will be created by the command `echo \"hello\"\u003e/tmp/HACKED` does not exists:\n```\ncat /tmp/HACKED\ncat: /tmp/HACKED: No such file or directory\n```\n- login with an admin account\n- visit `http://localhost:3000/plugins/new`\n- enter the following fields:\n\t- Name: `;echo \"hello\"\u003e/tmp/HACKED`\n\t- Source: `git`\n\t- other fields blank\n- click `Create`\n- you will get an error saying `ENOENT: no such file or directory,  ....` but the command `touch /tmp/HACKED` will be executed\n- to verify:\n```\ncat /tmp/HACKED\nhello\n```\n\n### Impact\n\nRemote code execution\n\n### Recommended Mitigation\n\nSanitize the `pluginDir` value before passing to `execSync`. Alternatively, use `child_process. execFileSync` API (docs: https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options)\n","status":"published","published":"2024-10-03T22:21:24Z","modified":"2024-10-03T22:21:24Z","cvss":[{"version":"3.1","score":7.2,"vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H","level":"high"},{"version":"4.0","score":7.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P","level":"high"}],"cwes":["CWE-78"],"updated_at":"2026-11-02T15:46:46.760785Z"}]}}
