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

fix(core): don't allow arbitrary code execution when manipulating cache #9329

Merged

Conversation

sorin-davidoi
Copy link
Contributor

Current Behavior

A carefully crafted NX_CACHE_DIRECTORY (environment variable) can make NX execute arbitrary commands. The same holds true for the cacheDirectory field in nx.json.

Expected Behavior

NX should not execute arbitrary code embedded in the NX_CACHE_DIRECTORY environment variable.

Fix

The Node documentation for exec states:

Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.

The folder variable comes directly from the NX_CACHE_DIRECTORY environment variable (or from nx.json). Careful crafting of this variable can result in NX executing arbitrary commands.

This patch fixes this by using execFile, which does not spawn a shell.

@nx-cloud
Copy link

nx-cloud bot commented Mar 15, 2022

☁️ Nx Cloud Report

CI ran the following commands for commit 25b9f27. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Mar 15, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/J4Mobp9MTRHPaqz8xK9m74pwpjCJ
✅ Preview: Canceled

[Deployment for 25b9f27 canceled]

The Node documentation for `exec` states:

> Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.

The `folder` variable comes directly from the `NX_CACHE_DIRECTORY` environment variable (or from `nx.json`). Careful crafting of this variable can result in NX executing arbitrary commands.

This patch fixes this by using `execFile`, which does not spawn a shell.
@AgentEnder AgentEnder force-pushed the fix-task-runner-cache-shell-commands branch from 4ab065c to 25b9f27 Compare March 15, 2022 13:38
@FrozenPandaz
Copy link
Collaborator

Thank you for your contribution! LGTM 🎉

@FrozenPandaz FrozenPandaz merged commit 75f9ece into nrwl:master Mar 18, 2022
@sorin-davidoi sorin-davidoi deleted the fix-task-runner-cache-shell-commands branch March 21, 2022 08:49
FrozenPandaz pushed a commit that referenced this pull request Mar 21, 2022
…he (#9329)

The Node documentation for `exec` states:

> Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.

The `folder` variable comes directly from the `NX_CACHE_DIRECTORY` environment variable (or from `nx.json`). Careful crafting of this variable can result in NX executing arbitrary commands.

This patch fixes this by using `execFile`, which does not spawn a shell.
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants