Skip to content

fix(exec): properly handles paths with spaces and quotes#365

Merged
nfischer merged 1 commit intomasterfrom
properly-escape-tempdir
Feb 19, 2016
Merged

fix(exec): properly handles paths with spaces and quotes#365
nfischer merged 1 commit intomasterfrom
properly-escape-tempdir

Conversation

@nfischer
Copy link
Copy Markdown
Member

This fixes #17. This is based off #263, but it also escapes quotes in the path.

The issue comes from the fact that exec() executes a script created in the temporary directory. On unix systems, this is usually /tmp/, which has no unusual characters in the name. Windows users usually have a temporary directory that is a subdirectory of their home folder (which has their username as part of the path). Therefore, Windows users with usernames containing either a space or a " couldn't use exec() properly.

This now properly surrounds the strings with quotes, and escapes any quote characters inside for security, preventing scenarios, such as creating a directory named /tmp"; echo hijacked; echo " (perhaps $TMP is modified to point there, and this is chosen as the temporary directory). echo hijacked represents an arbitrary command. As it's currently implemented, #263 is still susceptible.

@nfischer nfischer added fix Bug/defect, or a fix for such a problem exec Issues specific to the shell.exec() API security labels Feb 19, 2016
@nfischer nfischer added this to the v0.7.0 milestone Feb 19, 2016
@nfischer
Copy link
Copy Markdown
Member Author

@ariporad since this is built off of #263, let's wait to see if that PR gets updated in a few days.

@nfischer
Copy link
Copy Markdown
Member Author

@ariporad Looks like #263 was closed in favor of this, so I think this is ready for review now

@ariporad
Copy link
Copy Markdown
Contributor

@nfischer: Can we add a test for this? (If possible), otherwise, LGTM!

@nfischer
Copy link
Copy Markdown
Member Author

@ariporad It might be difficult to test it as-is, since it involves creating a directory with that name and mocking tempdir() to return the insecure name. I tested this on my Ubuntu machine and it handled it well.

If you can think of a unit test however, feel free to add it. I just couldn't think of anything.

@nfischer
Copy link
Copy Markdown
Member Author

I'm going to merge this now. If we can think of any tests for this, we can add them later on.

nfischer added a commit that referenced this pull request Feb 19, 2016
fix(exec): properly handles paths with spaces and quotes
@nfischer nfischer merged commit 14d518c into master Feb 19, 2016
@nfischer nfischer deleted the properly-escape-tempdir branch February 19, 2016 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exec Issues specific to the shell.exec() API fix Bug/defect, or a fix for such a problem security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exec does not working in mingw bash in windows

2 participants