{"answers":{"affected":"2 open source packages ship an affected version, including @saltcorn/plugins-loader.","exploited":"There is no known exploitation of GHSA-fm76-w8jw-xf8m in the wild and no public exploit code.","fix":"Upgrade @saltcorn/plugins-loader to 1.0.0-beta.14 or later.","what":"GHSA-fm76-w8jw-xf8m is a command injection vulnerability in @saltcorn/plugins-loader, published on 3 Oct 2024. An attacker needs administrator access to exploit it, with no action from the victim."},"fix_prompt":"Check this codebase for GHSA-fm76-w8jw-xf8m and fix it if it is affected.\n\nWhat it is: GHSA-fm76-w8jw-xf8m is a command injection vulnerability in @saltcorn/plugins-loader, published on 3 Oct 2024. An attacker needs administrator access to exploit it, with no action from the victim.\nExploitation: There is no known exploitation of GHSA-fm76-w8jw-xf8m in the wild and no public exploit code.\n\nAffected packages and fixed versions:\n- @saltcorn/plugins-loader (npm): affected all versions; fixed in 1.0.0-beta.14\n- @saltcorn/plugins-loader (npm): affected all versions; fixed in 1.0.0-beta.14\n\nTask:\n1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.\n2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.\n3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.\n4. Run the tests and summarise what changed and why.\n5. If nothing in the project is affected, say so and change nothing.\n\nReference: https://insights.sbomify.com/GHSA-fm76-w8jw-xf8m/ (Markdown: https://insights.sbomify.com/GHSA-fm76-w8jw-xf8m/index.md)","id":"GHSA-fm76-w8jw-xf8m","markdown":"https://insights.sbomify.com/GHSA-fm76-w8jw-xf8m/index.md","name":"GHSA-fm76-w8jw-xf8m","record":{"aliases":[],"analysis":{"component_type":"library","fix_type":"upgrade","impacts":["code_execution"],"network_reachable":"yes","non_default_config":false,"product_category":"Saltcorn plugin loader","requires_auth":"high_privilege","summary":"An admin can execute arbitrary commands via command injection in the plugin name during git-based plugin installation.","user_interaction":"not_required","vuln_class":"command_injection"},"analysis_generated_by":"qwen3.8-flash-next","assigner":null,"cpe":[],"cvss":{"score":null,"severity":null,"source":null,"vector":null,"version":null},"cwes":[],"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)","ecosystems":["npm"],"exploits":{"exploitdb":null,"first_seen":null,"github_poc":null,"max_poc_stars":null,"metasploit":null,"nuclei":null,"refs":[],"tier":null},"has_fix":true,"headline":"When creating a new plugin using the `git` source, the user-controlled value `req.body.name` is used to build the plugin directo","id":"GHSA-fm76-w8jw-xf8m","indexable":true,"kev":null,"kind":"advisory","links":{"ecosystem":"npm","product":null,"products":[],"type":"command_injection","year":"2024"},"n_packages":2,"n_references":null,"packages":[{"ecosystem":"npm","fixed":["1.0.0-beta.14"],"introduced":["0"],"last_affected":[],"package":"@saltcorn/plugins-loader","purl":null,"source":"GHSA-fm76-w8jw-xf8m"},{"ecosystem":"npm","fixed":["1.0.0-beta.14"],"introduced":["0"],"last_affected":[],"package":"@saltcorn/plugins-loader","purl":"pkg:npm/%40saltcorn/plugins-loader","source":"GHSA-fm76-w8jw-xf8m"}],"products":null,"published":"2024-10-03","related":[],"sources":[{"class":"attribution","licence":"CC BY 4.0","name":"GitHub Advisory Database","prefix":"GHSA"}],"ssvc":{"automatable":null,"exploitation":null,"technical_impact":null},"state":null,"updated":null,"vendors":null},"summary":"An admin can execute arbitrary commands via command injection in the plugin name during git-based plugin installation.","url":"https://insights.sbomify.com/GHSA-fm76-w8jw-xf8m/"}