Skip to content
RCE Disclosed report Beginner CVE-2020-8298

`fs-path` concatenates unsanitized input into exec()/execSync() commands

The fs-path npm module concatenates unsanitised arguments into shell commands passed to exec()/execSync(), allowing command injection. An attacker who controls a filename or path argument could execute arbitrary shell commands.

chalker Follow

Originally disclosed on HackerOne

Critical 9.6 View original
  • Triaged in 11 hours
  • Fixed in 2 months
  • Disclosed after 2 months

I would like to report command injection in fs-path. It allows to inject and execute arbitrary shell commands while performing various operations from fs-path API like copying files.

Module

module name: fs-path version: 0.0.24 npm page: https://www.npmjs.com/package/fs-path

Module Description

Useful file utitiles.

Module Stats

108 downloads in the last day 2 916 downloads in the last week 13 186 downloads in the last month

Vulnerability

Vulnerability Description

Arguments are not properly escaped before being concatenated into the command that is passed to exec()/execSync().

See https://github.com/pillys/fs-path/blob/master/lib/index.js

Steps To Reproduce:

JavaScript
const fsPath = require('fs-path');
const source = '/bin/ls';
const target =  '/tmp/foo;rm\t/tmp/foo;whoami>\t/tmp/bar';
fsPath.copySync(source, target);

Observe /tmp/bar being created with whoami output.

The same issue affects other methods in fs-path API, not just copySync.

Patch

The suggested fix is to avoid using exec/execSync and instead pass parameters as an array of arguments to corresponding child_process methods.

Supporting Material/References:

  • Arch Linux current
  • Node.js 9.7.1
  • npm 5.7.1

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

For setups where user input could end up in arguments of calls to fs-wrap API (like filename etc), users would be able to execute arbitrary shell commands.

Note that sanitization of user input on the application side might not prevent this issue, as simple path sanitization that removes stuff / and .. is not enough — commands like curl example.org | sh might pass through sanitization of user input (like filenames etc.) on the application side.

The original report as published on HackerOne, by chalker. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

For setups where user input reaches fs-path API arguments, an attacker could execute arbitrary shell commands; application-side path sanitisation may not prevent it.

What the attacker needed

Application passes user input to fs-path; attacker controls a filename or path argument

The fix

The module should avoid exec()/execSync() and instead pass arguments as an array to the corresponding child_process methods.

How it was found

  1. Require the fs-path module in a Node.js script.
  2. Call copySync with a source file and a target path that includes shell metacharacters and an extra command.
  3. Observe that the extra command runs and its output is written to a file.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This module builds shell commands by gluing together text, including file names you give it. If a file name contains special shell characters, the shell treats them as extra commands and runs them. So a user-supplied file name can become a way to run any command on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by chalker

View all

36 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.