Repository navigation
fix(security): use mktemp for cloudflared download to prevent TOCTOU race - #689
Conversation
📝 WalkthroughWalkthroughUpdated the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 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 docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/brev-setup.sh (1)
109-112: Consider adding trap-based cleanup for robustness.If
curlorinstallfails, the temp directory will be orphaned on the filesystem due toset -ecausing 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
📒 Files selected for processing (1)
scripts/brev-setup.sh
…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.
Summary
Replace hardcoded
/tmp/cloudflareddownload path inbrev-setup.shwith amktemp -dbased path to prevent TOCTOU race conditions where an attacker could replace the binary between download andsudo install.Test plan
brev-setup.shdownloads and installs cloudflared successfullySummary by CodeRabbit