Vulnerabilities in pkg:npm/@saltcorn/plugins-loader

PACKAGE
Advisory Summary

GHSA-fm76-w8jw-xf8m is a HIGH (CVSS 7.2) remote code execution vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting @saltcorn/plugins loader libraries in the npm ecosystem. The issue involves @saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (rce) vulnerability when creating plugins using git source. Remediation is available by upgrading affected packages to version 1.0.0-beta.14.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@saltcorn/plugins-loader

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/@saltcorn/plugins-loader. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-fm76-w8jw-xf8m - HIGH @saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source

GHSA-fm76-w8jw-xf8m at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-fm76-w8jw-xf8m
Severity HIGH
CVSS v3.1 Base Score 7.2
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product @saltcorn/plugins loader
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-fm76-w8jw-xf8m

To remediate this vulnerability, upgrade all affected @saltcorn/plugins loader dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@saltcorn/plugins-loader fixed: 1.0.0-beta.14
npm install @saltcorn/plugins-loader@1.0.0-beta.14
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @saltcorn/plugins-loader

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-fm76-w8jw-xf8m, inspect your project dependencies using npm:

npm ls @saltcorn/plugins-loader

Analyze the terminal output to locate any version of @saltcorn/plugins loader in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.0-beta.14), your application is affected.

Note: The npm ls @saltcorn/plugins-loader command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In @saltcorn/plugins loader, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary When 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. ### Details Relevant code from source (`req.body`) to sink (`child_process.execSync`). - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400 ```js router.post( "/", isAdmin, error_catcher(async (req, res) => { const plugin = new Plugin(req.body); // [1] [...] try { await load_plugins.loadAndSaveNewPlugin( // [3] plugin, schema === db.connectObj.default_schema || plugin.source === "github" ); [...] } }) ); ``` - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44 ```js class Plugin { [...] constructor(o: PluginCfg | PluginPack | Plugin) { [...] this.name = o.name; // [2] [...] } ``` - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65 ```js const loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) => { [...] const loader = new PluginInstaller(plugin); // [4] const res = await loader.install(force); // [7] [...] }; ``` - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61 ```js class PluginInstaller { constructor(plugin, opts = {}) { [...] const tokens = plugin.source === "npm" ? plugin.location.split("/") : plugin.name.split("/"); // [5] [...] this.tempDir = join(this.tempRootFolder, "temp_install", ...tokens); // [6] [...] } async install(force) { [...] if (await this.prepPluginsFolder(force, pckJSON)) { // [8] [...] } async prepPluginsFolder(force, pckJSON) { [...] switch (this.plugin.source) { [...] case "git": if (force || !(await pathExists(this.pluginDir))) { await gitPullOrClone(this.plugin, this.tempDir); // [9] [...] } ``` - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112 ```js const gitPullOrClone = async (plugin, pluginDir) => { [...] if (fs.existsSync(pluginDir)) { execSync(`git ${setKey} -C ${pluginDir} pull`); } else { execSync(`git ${setKey} clone ${plugin.location} ${pluginDir}`); // [10] } [...] }; ``` ### PoC - check that the file will be created by the command `echo "hello">/tmp/HACKED` does not exists: ``` cat /tmp/HACKED cat: /tmp/HACKED: No such file or directory ``` - login with an admin account - visit `http://localhost:3000/plugins/new` - enter the following fields: - Name: `;echo "hello">/tmp/HACKED` - Source: `git` - other fields blank - click `Create` - you will get an error saying `ENOENT: no such file or directory, ....` but the command `touch /tmp/HACKED` will be executed - to verify: ``` cat /tmp/HACKED hello ``` ### Impact Remote code execution ### Recommended Mitigation Sanitize 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)

GHSA-fm76-w8jw-xf8m Affected @saltcorn/plugins loader Versions

1 component(s)
Fixed Versions:
1.0.0-beta.14
Product / Package Ecosystem Affected Versions Fixed Version
@saltcorn/plugins-loader
npm
< 1.0.0-beta.14
1.0.0-beta.14

References

Frequently Asked Questions

What is GHSA-fm76-w8jw-xf8m?
GHSA-fm76-w8jw-xf8m is a security vulnerability in @saltcorn/plugins loader involving @saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which @saltcorn/plugins loader versions are affected?
Affected versions include releases prior to 1.0.0-beta.14 across affected packages: @saltcorn/plugins-loader.
What version fixes GHSA-fm76-w8jw-xf8m?
Upgrading to 1.0.0-beta.14 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @saltcorn/plugins-loader affected?
Yes, @saltcorn/plugins-loader is affected in releases prior to 1.0.0-beta.14. Upgrade your dependency to 1.0.0-beta.14 or later.
What is the CVSS score of GHSA-fm76-w8jw-xf8m?
GHSA-fm76-w8jw-xf8m has a CVSS v3.1 base score of 7.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with GHSA-fm76-w8jw-xf8m?
GHSA-fm76-w8jw-xf8m is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check npm dependencies for GHSA-fm76-w8jw-xf8m?
Run the dependency tree command: 'npm ls @saltcorn/plugins-loader'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-fm76-w8jw-xf8m",
  "modified" : "2024-10-03T22:21:24Z",
  "published" : "2024-10-03T22:21:24Z",
  "aliases" : [ ],
  "summary" : "@saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source",
  "details" : "### 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) => {\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) => {\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) => {\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\">/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\">/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",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@saltcorn/plugins-loader"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.0-beta.14"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.0.0-beta.13"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/security/advisories/GHSA-fm76-w8jw-xf8m"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/commit/024f19a7e079913f62f4a2335ab04116ddb68192"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/saltcorn/saltcorn"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-78" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-03T22:21:24Z",
    "nvd_published_at" : null
  }
}