Skip to content

fix(security): stop piping curl output directly to sudo bash - #869

Merged
cv merged 2 commits into
NVIDIA:mainfrom
fdzdev:fix/brev-curl-sudo-pipe
Mar 31, 2026
Merged

cv merged 2 commits into
NVIDIA:mainfrom
fdzdev:fix/brev-curl-sudo-pipe

Conversation

@fdzdev

@fdzdev fdzdev commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

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

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.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Downloads the NodeSource installer into a temp file, verifies its SHA-256 checksum (using sha256sum or shasum -a 256), fails if verification is unavailable or mismatched, then executes the verified installer with sudo -E bash, and cleans up the temp file via trap/rm. (38 words)

Changes

Cohort / File(s) Summary
NodeSource Installation Security
scripts/brev-setup.sh
Replaced streaming installer (`curl ...

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I found a script and hid it well,
Checked its teeth before the spell.
I hop away when work is done,
Clean trail left under the sun.
Safe burrow, tidy — now I run! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(security): stop piping curl output directly to sudo bash' directly and clearly summarizes the main security improvement in the changeset—replacing unsafe curl-to-bash piping with safer download-and-verify-then-execute pattern.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cec1e42 and ba5fe4c.

📒 Files selected for processing (1)
  • scripts/brev-setup.sh

Comment thread scripts/brev-setup.sh Resolved

@cv cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
scripts/brev-setup.sh (1)

47-48: Add checksum tool fallback for minimal-image portability.

shasum is not guaranteed on all minimal images. The codebase already uses this pattern in install.sh (checking sha256sum first, then falling back to shasum). 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

📥 Commits

Reviewing files that changed from the base of the PR and between 245be19 and db57ed5.

📒 Files selected for processing (1)
  • scripts/brev-setup.sh

@fdzdev
fdzdev force-pushed the fix/brev-curl-sudo-pipe branch from db57ed5 to 8d86fe6 Compare March 26, 2026 00:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between db57ed5 and 8d86fe6.

📒 Files selected for processing (1)
  • scripts/brev-setup.sh

Comment thread scripts/brev-setup.sh Resolved
@wscurran wscurran added bug platform: brev Affects Brev hosted development environments labels Mar 30, 2026
- 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
@fdzdev
fdzdev force-pushed the fix/brev-curl-sudo-pipe branch from 8d86fe6 to 692363d Compare March 31, 2026 05:25
@fdzdev

fdzdev commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

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.

fdzdev added a commit to fdzdev/NemoClaw that referenced this pull request Mar 31, 2026
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 cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cv
cv merged commit 9b26ac9 into NVIDIA:main Mar 31, 2026
1 check passed
fdzdev added a commit to fdzdev/NemoClaw that referenced this pull request Mar 31, 2026
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
laitingsheng pushed a commit that referenced this pull request Apr 2, 2026
## 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]>
lakamsani pushed a commit to lakamsani/NemoClaw that referenced this pull request Apr 4, 2026
)

## 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]>
gemini2026 pushed a commit to gemini2026/NemoClaw that referenced this pull request Apr 14, 2026
)

## 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]>
@wscurran wscurran added bug-fix PR fixes a bug or regression and removed priority: high labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression platform: brev Affects Brev hosted development environments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants