Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean command fails in path with spaces #181

Closed
RoyalIcing opened this issue Oct 1, 2016 · 4 comments
Closed

Clean command fails in path with spaces #181

RoyalIcing opened this issue Oct 1, 2016 · 4 comments
Labels

Comments

@RoyalIcing
Copy link

RoyalIcing commented Oct 1, 2016

⠋ Cleaning app/bin/sh: /Users/pgwsmith/Work/Royal: No such file or directory                                                   
✖ Cleaning app                                                                                                                 
Error running command: Command failed: /Users/pgwsmith/Work/Royal Icing/creme-brulee/web/flambe/node_modules/nwb/node_modules/rimraf/bin.js coverage list

Seems to be due to the space in the path. I checked out the source code at https://github.com/insin/nwb/blob/master/src/commands/clean-app.js and couldn’t see an easy fix.

Is it possibly line 10 here needs quotes for the args (although each arg would have to be quoted I think)?

let command = `${require.resolve(`.bin/${bin}`)} ${args.join(' ')}`

let command = `${require.resolve(`.bin/${bin}`)} ${args.join(' ')}`

->

let command = `${require.resolve(`.bin/${bin}`)} "${args.join(' ')}"`

Or perhaps in

let dist = args._[1] || 'dist'
:

let dist = args._[1] || 'dist'

->

let dist = `"${args._[1]}"` || 'dist'
@RoyalIcing
Copy link
Author

Actually testing this more, it seems nwb clean-app works but npm run clean with "clean": "nwb clean-app" does not.

@insin
Copy link
Owner

insin commented Oct 3, 2016

Thanks for the bug report - I assume if we pass the arguments as a separate array instead of hardcoding them into the command to be executed, Node should handle escaping them properly. Will give it a go soon.

@insin insin added the bug label Oct 3, 2016
@vpezeshkian
Copy link

vpezeshkian commented Oct 3, 2016

I have faced this issue today and I did some debugging, it turns out "for me" that rimraf does not handle paths with spaces...

@isaacs
Copy link

isaacs commented Oct 5, 2016

Rimraf handles spaces just fine.

The bug here is that you're passing a string to exec, you're not calling spawn with an array of arguments.

Consider if you had a file called foo bar with a space. If you call rm foo bar on the shell, it's going to remove the files foo and bar.

In Node.js, if you call var childProcess = spawn('rm', ['foo bar']) then that's going to pass foo bar as a literal argument to the rm process.

But if you call exec('rm foo bar') then it's going to pass the string "rm foo bar" as an argument to sh like spawn('sh', ['-c', 'rm foo bar']) and it's going to fail.

You should really almost never be passing strings from userland or the filesystem directly into a command like this. It's almost always a security vulnerability. For example, I could publish a module with a file named some-file\ndo-something-evil and your program would happily execute the shell script:

rm some-file
do-something-evil

and then evil things would happen and I'd have control of your machine.

Since rimraf can be used as a module, and this script is in JavaScript, there's no need to execSync it. Just require() it and use the function.

insin added a commit that referenced this issue Dec 11, 2016
Use rimraf as a function, fixes #181

Includes a bit of refactoring to reduce duplicated spinner management
insin added a commit that referenced this issue Dec 13, 2016
Use rimraf as a function, fixes #181

Includes a bit of refactoring to reduce duplicated spinner management
@insin insin closed this as completed in 4f9cc4b Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants