Описание
@saltcorn/plugins-loader unsanitized plugin name leads to a remote code execution (RCE) vulnerability when creating plugins using git source
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
- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44
- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65
PoC
- check that the file will be created by the command
echo "hello">/tmp/HACKEDdoes not exists:
- 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
- Name:
- click
Create - you will get an error saying
ENOENT: no such file or directory, ....but the commandtouch /tmp/HACKEDwill be executed - to verify:
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)
Ссылки
- https://github.com/saltcorn/saltcorn/security/advisories/GHSA-fm76-w8jw-xf8m
- https://github.com/saltcorn/saltcorn/commit/024f19a7e079913f62f4a2335ab04116ddb68192
- https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/download_utils.js#L112
- https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/plugins-loader/plugin_installer.js#L41-L61
- https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/saltcorn-data/models/plugin.ts#L44
- https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/load_plugins.js#L64-L65
- https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/plugins.js#L1400
Пакеты
@saltcorn/plugins-loader
<= 1.0.0-beta.13
1.0.0-beta.14
7.3 High
CVSS4
7.2 High
CVSS3
Дефекты
7.3 High
CVSS4
7.2 High
CVSS3