Skip to content

fix(security): use mktemp for cloudflared download to prevent TOCTOU race - #689

Merged
ericksoa merged 1 commit into
mainfrom
fix/brev-cloudflared-mktemp
Mar 23, 2026
Merged

ericksoa merged 1 commit into
mainfrom
fix/brev-cloudflared-mktemp

Conversation

@ericksoa

@ericksoa ericksoa commented Mar 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Replace hardcoded /tmp/cloudflared download path in brev-setup.sh with a mktemp -d based path to prevent TOCTOU race conditions where an attacker could replace the binary between download and sudo install.

Test plan

  • All tests and pre-commit hooks pass
  • Manual: brev-setup.sh downloads and installs cloudflared successfully

Summary by CodeRabbit

  • Bug Fixes
    • Improved cloudflared installer robustness by using isolated temporary storage during the installation process, preventing potential file path conflicts.
    • Enhanced vLLM startup initialization reliability through improved readiness detection.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated the cloudflared installer to use a temporary directory created with mktemp -d instead of a hardcoded path, with cleanup via rm -rf. Changed the vLLM startup readiness loop variable from i to _.

Changes

Cohort / File(s) Summary
Cloudflared installer
scripts/brev-setup.sh
Modified to create a temporary directory for downloading the cloudflared release, install from that path, and remove the temp directory afterward. Changed vLLM startup readiness loop variable from i to _.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A temporary path, so clean and so neat, 🐰
No /tmp clutter beneath our soft feet,
The variables whisper their names fade to dark,
While cloudflared dances through cleanup's bright mark,
Small fixes that keep our scripts lean and sleek! ✨

🚥 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 accurately describes the main security fix: replacing a hardcoded path with mktemp to prevent TOCTOU race conditions in the cloudflared download process.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/brev-cloudflared-mktemp

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.

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

109-112: Consider adding trap-based cleanup for robustness.

If curl or install fails, the temp directory will be orphaned on the filesystem due to set -e causing immediate exit. While not a security issue (each run creates a new random directory), a trap would ensure cleanup happens even on failure.

♻️ Suggested improvement for both openshell and cloudflared installations

For the cloudflared section:

  tmpdir=$(mktemp -d)
+ trap 'rm -rf "$tmpdir"' EXIT
  curl -fsSL "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${CF_ARCH}" -o "$tmpdir/cloudflared"
  sudo install -m 755 "$tmpdir/cloudflared" /usr/local/bin/cloudflared
- rm -rf "$tmpdir"

Apply the same pattern to the openshell installation section (lines 89-94).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/brev-setup.sh` around lines 109 - 112, Create a trap-based cleanup
for the temporary directory: after tmpdir=$(mktemp -d) install a trap that
removes "$tmpdir" on EXIT (e.g., trap 'rm -rf "$tmpdir"' EXIT) so the directory
is cleaned whether curl/install succeeds or the script exits; ensure the trap
references the same tmpdir variable and is present before running curl/install,
and optionally clear the trap or let the final rm -rf "$tmpdir" satisfy cleanup;
apply the identical pattern to the openshell installation block that also
creates a tmpdir.
🤖 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 109-112: Create a trap-based cleanup for the temporary directory:
after tmpdir=$(mktemp -d) install a trap that removes "$tmpdir" on EXIT (e.g.,
trap 'rm -rf "$tmpdir"' EXIT) so the directory is cleaned whether curl/install
succeeds or the script exits; ensure the trap references the same tmpdir
variable and is present before running curl/install, and optionally clear the
trap or let the final rm -rf "$tmpdir" satisfy cleanup; apply the identical
pattern to the openshell installation block that also creates a tmpdir.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e4b30969-246a-41db-a6df-c5d09687fac5

📥 Commits

Reviewing files that changed from the base of the PR and between 055e334 and d22eb7d.

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

@ericksoa
ericksoa merged commit a09cfa9 into main Mar 23, 2026
7 checks passed
@ericksoa ericksoa self-assigned this Mar 23, 2026
@wscurran wscurran added bug and removed bug labels Mar 23, 2026
Ryuketsukami pushed a commit to Ryuketsukami/NemoClaw that referenced this pull request Mar 24, 2026
alexcode-cc pushed a commit to alexcode-cc/NemoClaw that referenced this pull request Mar 24, 2026
jessesanford pushed a commit to jessesanford/NemoClaw that referenced this pull request Mar 24, 2026
@wscurran wscurran added bug-fix PR fixes a bug or regression and removed priority: high labels Jun 3, 2026
@cv
cv deleted the fix/brev-cloudflared-mktemp branch June 28, 2026 00:21
cv added a commit that referenced this pull request Nov 20, 2026
…hropic endpoint fix (#14672)

Pins Fabric to NVIDIA/NeMo-Fabric `release/0.7` at `c6d1093d`, the merge
of NVIDIA/NeMo-Fabric#689. A Hermes route to an `anthropic` provider now
reaches the provider's endpoint whatever its path, so its limit and the
inference guide's workaround are removed.

## Problem

Fabric's Hermes adapter wrote an `anthropic` route into Hermes's
configuration as Hermes's `anthropic` provider. Hermes uses that
provider's `base_url` only for an Anthropic, Claude, or Azure host or a
path ending in `/anthropic` or `/anthropic/v1`. For any other endpoint,
such as `https://gateway.example/v1`, Hermes's API server, dashboard and
terminal UI sent requests to `https://api.anthropic.com`. OpenShell
refused them, and the agent didn't answer (NVIDIA/NeMo-Fabric#666).

Resolves #14538.

## Change

- **Pin:** Fabric `c6d1093d` in `versions.json` (with the archive's
SHA-256), the Cargo manifests and `Cargo.lock`. The documentation links
move to the same revision, and every linked path exists there.
- **What the pin brings:** `0dfdb254`, the current pin, is an ancestor.
The new commits are:
- #689, which writes an `anthropic` route with an endpoint as Hermes's
`custom` provider with the Anthropic Messages transport.
- #691, which restores Fabric's package versions to 0.7.0, so
`nemo-fabric-core` is 0.7.0 again.
  - #693 and #673, which change only documentation.
- **Catalog:** `image/fabric/catalog.json` is regenerated; only its
revision and checksum change. The schema snapshots and contract fixtures
regenerate unchanged. The fixture image's digest, which covers the
catalog, moves in two cases, and so do the inference names derived from
it in `openshift-external-two-providers.tftest.hcl`.
- **Live case:** in `docker-openclaw-hermes-interfaces`,
`hermes-messages` uses a new `anthropic` provider at the stub's
`/custom/v1`, which the stub now serves too. Its existing reply
assertions now show that Hermes calls the configured endpoint. OpenClaw
stays on `/anthropic/v1`. The case makes no extra requests.
- **Docs:**
- The limits row for Hermes's `anthropic` endpoint paths, the inference
guide's "Pointing Hermes at an Anthropic Endpoint" section, and the rc11
release note's link to it are removed.
  - Release notes get a line under "Changes Since v0.1.0-rc11".
- Under "Breaking Changes Since v0.1.0-rc11", they now say that
OpenClaw's `plugins.entries` setting is now `plugins.bundled.entries`
and `plugins.external.entries`. That rename came with the previous pin,
`0dfdb254` (NVIDIA/NeMo-Fabric#680).

## Beyond CI

- On linux/arm64, `cargo ci live-docker` passed with this change:
`hermes-messages`'s API server and its Fabric invocations answered with
the stub's reply through the `/custom/v1` provider.
- In NVIDIA/NeMo-Fabric#689's NemoClaw check, the same `/custom/v1`
route failed at `terraform_data.request["messages_chat"]` with Fabric
`56a4207b`, which predates the fix.
- I computed the archive's SHA-256 from codeload twice, with the same
result.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants