-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix: truffle unbox
use spawnSync
to run the post-install hook
#5765
base: develop
Are you sure you want to change the base?
Fix: truffle unbox
use spawnSync
to run the post-install hook
#5765
Conversation
truffle unbox
Thanks, @GuillaumeRx! |
truffle unbox
truffle unbox
Ignore STDIO in execSync when running the post-install hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and LGTM! Thanks, @GuillaumeRx!
We need another approval, and CI passing ofc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @GuillaumeRx !
packages/box/lib/utils/unbox.ts
Outdated
@@ -148,7 +148,7 @@ function installBoxDependencies({ hooks }: boxConfig, destination: string) { | |||
const postUnpack = hooks["post-unpack"]; | |||
|
|||
if (postUnpack.length === 0) return; | |||
execSync(postUnpack, { cwd: destination }); | |||
execSync(postUnpack, { cwd: destination, stdio: "ignore" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would increasing maxBuffer
be better? Ignoring stdio altogether hides warnings.
Or use spawn instead of exec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer using spawn to get around the buffer issue. Thanks, @cliffoo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review ! I'll push an update using spawn
tomorrow 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @GuillaumeRx, the move to spawn has to make sure we don't break other boxes that use complex commands as well as parsing hooks.post-unpack
because spawn
and execSync
APIs describe a utility's command and its arguments differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like parsing can be avoided by setting shell
to true
(gist)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execSync
will only output stderr
to the parent process stderr. Should I replicate this behaviour with spawn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works locally! Thanks @GuillaumeRx.
This implementation removes child process' stderr/stdout
|
||
spawnSync(postUnpack, { | ||
cwd: destination, | ||
shell: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow to run complex commands without parsing. ref: #5765 (comment)
spawnSync(postUnpack, { | ||
cwd: destination, | ||
shell: true, | ||
stdio: ["ignore", process.stdout, process.stderr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore stdin
and pipe stdout
/ stderr
to parent process. I also piped stdout
because - after looking at some boxes - most of them use --loglevel=error
to elevate the logging to stderr
.
execSync
was previously left at its default config that didn't pipe stdout
, now that it is with spawnSync
the log level flag is not required anymore.
truffle unbox
Ignore STDIO in execSync when running the post-install hooktruffle unbox
use spawnSync
to run the post-install hook
hhmvvsmmmmm so this prompted us to revisit the post-install hook workflow as a whole: the security implications of allowing box creators to execute arbitrary commands on the user end (e.g. And for Thanks again @GuillaumeRx 👍 |
Team is revisiting the post-install hook workflow due to security concerns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @GuillaumeRx,
We decided that since this PR doesn't affect the vulnerability issue, we could merge it. However, not sanitizing inputs when using spawnSync
and shell
is a new concern, e.g. expanding *
and $
in the shell. To be honest, I'm unsure how to proceed and need some time to research this.
|
||
spawnSync(postUnpack, { | ||
cwd: destination, | ||
shell: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned there's no sanitization checks on this arbitrary command as noted in the docs
If the shell option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.
This is blocked by #5952 Update since we've discussed this internally: This PR can be merged once we restrict use of the |
PR description
This replace
execSync
in favor ofspawnSync
to run the post-install hook avoiding aENOBUFS
error due to Yarn 3 filling the 200 ko Buffer limit of the spawned process.Testing instructions
truffle unbox metamask/snap-box
commandDemo
With a
npm
box:_g_t_box-test.2022-12-08.13-29-36.mp4
With a
yarn
boxyarn.truffle.unbox.mp4