Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unlimited shelljs commands with ES6 proxies

License

NotificationsYou must be signed in to change notification settings

nfischer/shelljs-exec-proxy

 
 

Repository files navigation

GitHub ActionsCodecovnpmnpm downloads

Unleash the power of unlimited ShellJS commands...with ES6 Proxies!

Do you likeShellJS, but wish it had yourfavorite commands? Skip the weirdexec() calls by usingshelljs-exec-proxy:

// Our goal: make a commit: `$ git commit -am "I'm updating the \"foo\" module to be more secure"`// Standard ShellJS requires the exec function, with confusing string escaping:shell.exec('git commit -am "I\'m updating the \\"foo\\" module to be more secure"');// Skip the extra string escaping with shelljs-exec-proxy!shell.git.commit('-am',`I'm updating the "foo" module to be more secure`);

Installation

$ npm install --save shelljs-exec-proxy

Get that JavaScript feeling back in your code

constshell=require('shelljs-exec-proxy');shell.git.status();shell.git.add('.');shell.git.commit('-am','Fixed issue #1');shell.git.push('origin','main');

Security improvements

Current versions of ShellJS export the.exec() method, which if not usedcarefully, could introduce command injection Vulnerabilities to your module.Here's an insecure code snippet:

shell.ls('dir/*.txt').forEach(file=>{shell.exec('git add '+file);}

This leaves you vulnerable to files like:

Example file nameUnintended behavior
File 1.txtThis tries to add bothFile and1.txt, instead ofFile 1.txt
foo;rm -rf *This executes bothgit add foo andrm -rf *, unexpectedly deleting your files!
ThisHas"quotes'.txtThis tries runninggit add ThisHas"quotes'.txt, producing a Bash syntax error

shelljs-exec-proxy solves all these problems:

shell.ls('dir/*.txt').forEach(file=>{shell.git.add(file);}
Example file nameBehavior
File 1.txtArguments are automatically quoted, so spaces aren't an issue
foo;rm -rf *Only one command runs at a time (semicolons are treated literally) and wildcards aren't expanded
ThisHas"quotes'.txtQuote characters are automatically escaped for you, so there are never any issues

About

Unlimited shelljs commands with ES6 proxies

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp