Skip to content

Allow arguments to be passed out-of-band from script text #83

Closed
@charles-dyfis-net

Description

@charles-dyfis-net

Templating filenames as strings into a shell script -- as gulp-shell recommends -- is extremely dangerous practice from a security perspective. The best-practice approach is for script text to be hardcoded, and for parameters to be passed out-of-band, as arguments or in the environment. Demonstrating two possible argument vectors with the same literal argument:

dangerString="/tmp/evil/$(rm -rf $HOME)'$(rm -rf $HOME)'"

# this argument vector is harmless, and will correctly make a directory with the given name
['sh', '-c', 'directory=$1; mkdir -p "$directory", _, dangerString]

# this argument vector is dangerous, and will destroy the user's home directory
['sh', '-c', "mkdir -p <%= dangerString %>"]

Note the literal single quotes in dangerString, such that even putting single quotes around the expansion cannot prevent one or the other of the command substitutions contained within from being expanded.

Not only should a tool that's advertised as a way to call a shell from JavaScript implement a safe way to do so, but it should document and advertise safe practices as the preferred way to use it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions