Repository navigation
fix(security): stop piping curl output directly to sudo bash - #869
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughDownloads the NodeSource installer into a temp file, verifies its SHA-256 checksum (using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/brev-setup.sh`:
- Around line 42-45: After creating the temp file with node_setup="$(mktemp)",
add an EXIT trap to always remove that file on any exit (success or failure) so
the temp file isn't leaked; specifically, register a trap like trap 'rm -f
"$node_setup"' EXIT immediately after the mktemp call (and keep the existing rm
-f "$node_setup" for the normal path or remove the explicit rm and rely on the
trap if preferred) to guarantee cleanup even when set -euo pipefail causes early
exits.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6f09ee8e-c4b1-4253-9856-5e21ceba8d14
📒 Files selected for processing (1)
scripts/brev-setup.sh
cv
left a comment
There was a problem hiding this comment.
This is security theater — the threat model for curl | sudo bash is that an attacker controls the HTTP response (MITM, compromised CDN, DNS hijack). Downloading to a temp file and immediately executing it doesn't change that; no human inspects the file in between, so the attack surface is identical.
Real mitigations would be something like:
- Pin a checksum of the expected installer script and verify before executing
- Use the distro package manager directly with a signed apt repo instead of nodesource's bootstrap script
- Verify a GPG signature on the downloaded script
As-is this just adds complexity (mktemp, trap, cleanup) without actually reducing risk.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/brev-setup.sh (1)
47-48: Add checksum tool fallback for minimal-image portability.
shasumis not guaranteed on all minimal images. The codebase already uses this pattern ininstall.sh(checkingsha256sumfirst, then falling back toshasum). Currently, failure to find a tool reports as "checksum mismatch," which is misleading. Implement the same fallback here to detect missing tools explicitly rather than masking it as a verification error.Suggested patch
- echo "$NODESOURCE_SHA256 $node_setup" | shasum -a 256 -c - >/dev/null \ - || fail "NodeSource installer checksum mismatch — expected $NODESOURCE_SHA256" + if command -v sha256sum >/dev/null 2>&1; then + echo "$NODESOURCE_SHA256 $node_setup" | sha256sum -c - >/dev/null \ + || fail "NodeSource installer checksum mismatch — expected $NODESOURCE_SHA256" + elif command -v shasum >/dev/null 2>&1; then + echo "$NODESOURCE_SHA256 $node_setup" | shasum -a 256 -c - >/dev/null \ + || fail "NodeSource installer checksum mismatch — expected $NODESOURCE_SHA256" + else + fail "No SHA-256 verification tool found (need sha256sum or shasum)" + fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/brev-setup.sh` around lines 47 - 48, The current checksum step pipes to shasum and reports a misleading "checksum mismatch" when shasum is absent; update the checksum logic in the brev-setup.sh block that contains the echo "... | shasum -a 256 -c -" command to first detect and use sha256sum if available, otherwise use shasum if available, and if neither exists call fail with a clear message like "checksum tool not found"; keep the verification behavior the same (fail on mismatch) but ensure the absence of tools is detected explicitly and reported via the existing fail function instead of being masked as a mismatch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@scripts/brev-setup.sh`:
- Around line 47-48: The current checksum step pipes to shasum and reports a
misleading "checksum mismatch" when shasum is absent; update the checksum logic
in the brev-setup.sh block that contains the echo "... | shasum -a 256 -c -"
command to first detect and use sha256sum if available, otherwise use shasum if
available, and if neither exists call fail with a clear message like "checksum
tool not found"; keep the verification behavior the same (fail on mismatch) but
ensure the absence of tools is detected explicitly and reported via the existing
fail function instead of being masked as a mismatch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ade4f10e-8a37-4173-872c-4c0aa422a6c8
📒 Files selected for processing (1)
scripts/brev-setup.sh
db57ed5 to
8d86fe6
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/brev-setup.sh`:
- Around line 42-49: The install entrypoint still pipes the NodeSource installer
directly into bash; replicate the secure pattern used for
NODESOURCE_URL/NODESOURCE_SHA256 by creating a temp file (mktemp), using curl
-fsSL to download to that temp (store in a variable like node_setup), adding a
trap to rm -f the temp, verify the file with shasum -a 256 -c against
NODESOURCE_SHA256 and on mismatch call fail, then execute with sudo -E bash
"$node_setup" (instead of piping), mirroring the logic from the existing block
that uses NODESOURCE_URL, NODESOURCE_SHA256, node_setup, trap and fail.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 951135c0-1221-4182-9c90-3c2bb839c5c7
📒 Files selected for processing (1)
scripts/brev-setup.sh
- Pin SHA-256 checksum for NodeSource installer script - Verify checksum before root execution (sha256sum with shasum fallback) - Download to temp dir with cleanup trap Made-with: Cursor
8d86fe6 to
692363d
Compare
|
Addressed in the latest push — the script now pins a SHA-256 checksum for the NodeSource installer and verifies it before execution (sha256sum with shasum fallback). If the checksum doesn't match, it fails hard. Re: distro package manager approach — agree that's the most robust long-term fix (avoid the bootstrap script entirely), but it's a larger change. Happy to do that as a follow-up if you'd prefer, but the checksum pinning closes the immediate MITM/CDN-compromise vector. |
Consolidate 3 separate sudo apt-get update calls into a single upfront index refresh, reducing privilege escalation surface. Add audit header documenting all sudo calls by category: [pkg], [bin], [svc], [cfg], [run] (NVBUG 6002888). No sudo calls removed — all are required for system package management on Brev VMs. The dangerous [run] category (NodeSource setup) is addressed separately in PR NVIDIA#869. Made-with: Cursor
cv
left a comment
There was a problem hiding this comment.
Thanks for addressing this. The latest revision now applies a real mitigation: the NodeSource installer is downloaded to a temp file, verified against a pinned SHA-256 checksum (with sha256sum/shasum fallback), and only then executed. That addresses my original concern that the previous version was just download-and-execute without reducing the threat from a compromised response.
Using a signed package source directly would still be a stronger long-term direction, but this is a reasonable security improvement for the current scope.
Consolidate 3 separate sudo apt-get update calls into a single upfront index refresh, reducing privilege escalation surface. Add audit header documenting all sudo calls by category: [pkg], [bin], [svc], [cfg], [run] (NVBUG 6002888). No sudo calls removed — all are required for system package management on Brev VMs. The dangerous [run] category (NodeSource setup) is addressed separately in PR NVIDIA#869. Made-with: Cursor Signed-off-by: Facundo Fernandez <[email protected]> Made-with: Cursor
## Summary - `brev-setup.sh` pipes `curl` output directly to `sudo -E bash -`, executing arbitrary remote code as root without inspection (CWE-250, NVBUG 6002888) - Replaces with download-to-tempfile then `sudo -E bash "$tmpfile"` — the script is auditable on disk before root execution - Temp file cleaned up after execution - Other `sudo apt-get` and `sudo install` calls are left as-is (they legitimately need root for system package management) ## Test plan - [ ] Run `brev-setup.sh` on a fresh Brev VM without Node.js — Node.js installs successfully - [ ] Temp file is removed after execution (`ls /tmp/tmp.*` shows no leftover) - [ ] If `curl` fails (e.g. no network), `set -e` exits before `sudo bash` runs <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved the installer process to run from a downloaded temporary file instead of streaming, reducing risk during setup. * Added checksum verification for the downloaded installer to guard against tampering. * Ensured temporary installer artifacts are reliably removed on exit to improve cleanup and security. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Carlos Villela <[email protected]>
) ## Summary - `brev-setup.sh` pipes `curl` output directly to `sudo -E bash -`, executing arbitrary remote code as root without inspection (CWE-250, NVBUG 6002888) - Replaces with download-to-tempfile then `sudo -E bash "$tmpfile"` — the script is auditable on disk before root execution - Temp file cleaned up after execution - Other `sudo apt-get` and `sudo install` calls are left as-is (they legitimately need root for system package management) ## Test plan - [ ] Run `brev-setup.sh` on a fresh Brev VM without Node.js — Node.js installs successfully - [ ] Temp file is removed after execution (`ls /tmp/tmp.*` shows no leftover) - [ ] If `curl` fails (e.g. no network), `set -e` exits before `sudo bash` runs <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved the installer process to run from a downloaded temporary file instead of streaming, reducing risk during setup. * Added checksum verification for the downloaded installer to guard against tampering. * Ensured temporary installer artifacts are reliably removed on exit to improve cleanup and security. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Carlos Villela <[email protected]>
) ## Summary - `brev-setup.sh` pipes `curl` output directly to `sudo -E bash -`, executing arbitrary remote code as root without inspection (CWE-250, NVBUG 6002888) - Replaces with download-to-tempfile then `sudo -E bash "$tmpfile"` — the script is auditable on disk before root execution - Temp file cleaned up after execution - Other `sudo apt-get` and `sudo install` calls are left as-is (they legitimately need root for system package management) ## Test plan - [ ] Run `brev-setup.sh` on a fresh Brev VM without Node.js — Node.js installs successfully - [ ] Temp file is removed after execution (`ls /tmp/tmp.*` shows no leftover) - [ ] If `curl` fails (e.g. no network), `set -e` exits before `sudo bash` runs <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved the installer process to run from a downloaded temporary file instead of streaming, reducing risk during setup. * Added checksum verification for the downloaded installer to guard against tampering. * Ensured temporary installer artifacts are reliably removed on exit to improve cleanup and security. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Carlos Villela <[email protected]>
Summary
brev-setup.shpipescurloutput directly tosudo -E bash -, executing arbitrary remote code as root without inspection (CWE-250, NVBUG 6002888)sudo -E bash "$tmpfile"— the script is auditable on disk before root executionsudo apt-getandsudo installcalls are left as-is (they legitimately need root for system package management)Test plan
brev-setup.shon a fresh Brev VM without Node.js — Node.js installs successfullyls /tmp/tmp.*shows no leftover)curlfails (e.g. no network),set -eexits beforesudo bashrunsSummary by CodeRabbit