Skip to content

fix(security): build container command as argv, not sh -c (CWE-78); bind Mysterium UI to localhost#51

Merged
GeiserX merged 1 commit into
mainfrom
security/deploy-command-hardening
Jul 5, 2026
Merged

fix(security): build container command as argv, not sh -c (CWE-78); bind Mysterium UI to localhost#51
GeiserX merged 1 commit into
mainfrom
security/deploy-command-hardening

Conversation

@GeiserX

@GeiserX GeiserX commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Vulnerability (S3, CWE-78 command injection)

The deploy path built the container command as config.Cmd = {"sh", "-c", substitute(command, env)}user credentials interpolated into a shell string. Catalog commands that interpolate secrets: honeygain (-pass ${HONEYGAIN_PASSWORD}), iproyal (-password ${IPROYALPAWNS_PASSWORD}), traffmonetizer (--token ${TRAFFMONETIZER_TOKEN}), packetshare (-password=${...}). A credential containing ;, $(), backtick, quote, &, |, or whitespace could break the deploy or inject commands into the container.

Fix

buildCommandArgs tokenizes the maintainer template first (trusted — only static flags + ${VAR} placeholders), then substitutes env per token, and passes the result as config.Cmd with no shell. A ${CRED} becomes exactly one inert argv element regardless of its content. tokenizeCommand is a quote-aware POSIX-ish splitter (no expansion). Empty command → nil (image default preserved, as before).

This also fixes a latent correctness bug: Docker Cmd appends to the image ENTRYPOINT, so argv [-email, x, -pass, y] is the intended <binary> -email x -pass y; the old sh -c "<flags>" passed sh -c … to the entrypoint (already broken for flag-style commands). Values with spaces (a device name "My Laptop") now stay one arg too.

S2 — Mysterium management exposure

services/bandwidth/mysterium.yml bound --ui.address=0.0.0.0 --tequilapi.address=0.0.0.0 under network_mode: host, exposing the node control UI/API (4449) to the LAN/VPS. Now 127.0.0.1. Host-net + NET_ADMIN kept (required for VPN NAT traversal; the collector uses the cloud API, not the local tequilapi).

Verification

  • go build ./..., go vet ./..., go test -race ./... — all green (incl. new tokenizeCommand + injection unit tests: a credential p; rm -rf / / $(x) / backticks / space ends up as exactly one argv element).
  • Live injection demo (busybox): the old sh -c form executed an injected ; <cmd>; the new argv form printed the identical value as one literal argument — no execution.

Residual (non-blocking): per-DePIN-image argv-to-entrypoint spot-checks would need image pulls; the argv form is the standard Docker pattern and strictly better than the (already-broken) sh -c form for these flag commands.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how container commands are started so quoted values, spaces, and special characters are handled more reliably.
    • Fixed credential-style values so they stay intact when passed to services, reducing launch issues.
    • Updated one service to bind local interfaces more securely, instead of listening on all network addresses.

@gitguardian

gitguardian Bot commented Jul 5, 2026

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@GeiserX, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 878ab3a5-b321-4568-a5b0-a21b2b769f7b

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc9117 and 1e391fd.

📒 Files selected for processing (3)
  • internal/runtime/runtime.go
  • internal/runtime/runtime_test.go
  • services/bandwidth/mysterium.yml
📝 Walkthrough

Walkthrough

Docker container command construction switches from a shell-string (sh -c) execution model to argv-based tokenization via new buildCommandArgs and tokenizeCommand functions in runtime.go, with accompanying tests. Separately, mysterium.yml changes UI/tequilapi bind addresses from 0.0.0.0 to 127.0.0.1.

Changes

Command argv safety

Layer / File(s) Summary
Argv tokenization and substitution implementation
internal/runtime/runtime.go
Deploy now builds container.Config.Cmd via buildCommandArgs, which tokenizes the command template with tokenizeCommand and substitutes ${VAR} per token, replacing the prior sh -c string-based command.
Tokenization and credential safety tests
internal/runtime/runtime_test.go
New tests cover whitespace splitting, equals-joined flags, quoted values, whitespace collapsing, and verify credentials with shell metacharacters become single safe argv elements; empty template returns nil.

Bandwidth Service Address Binding

Layer / File(s) Summary
Loopback address binding update
services/bandwidth/mysterium.yml
--ui.address and --tequilapi.address changed from 0.0.0.0 to 127.0.0.1.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Related issues: None specified.

Related PRs: None specified.

Suggested labels: security, runtime, refactor

Suggested reviewers: GeiserX

🐰 A shell escaped, no more sneaky quotes,
Argv tokens now carry the notes,
Loopback binds tight, no open door,
Tests stand guard forevermore.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the command-argv security hardening and localhost binding changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/deploy-command-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 62.81%. Comparing base (f944d6c) to head (1e391fd).

Files with missing lines Patch % Lines
internal/runtime/runtime.go 97.72% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #51      +/-   ##
==========================================
+ Coverage   61.91%   62.81%   +0.89%     
==========================================
  Files           8        8              
  Lines        1783     1826      +43     
==========================================
+ Hits         1104     1147      +43     
  Misses        597      597              
  Partials       82       82              
Files with missing lines Coverage Δ
internal/runtime/runtime.go 51.57% <97.72%> (+4.81%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ind Mysterium UI to localhost

The deploy path built the container command as sh -c "<substituted>", interpolating
user credentials into a shell string. Several catalog commands interpolate secrets
(honeygain, iproyal, traffmonetizer, packetshare), so a credential containing shell
metacharacters (; $() backticks | & quotes) or whitespace could break the deploy or
inject commands into the container (CWE-78).

buildCommandArgs now tokenizes the trusted maintainer template first (tokenizeCommand,
a quote-aware splitter with no expansion), then substitutes env per token, and passes
the result as config.Cmd with no shell -- a ${CRED} becomes exactly one inert argv
element regardless of its content. Empty command -> nil (image default preserved). This
also fixes a latent bug: argv is the intended '<entrypoint> -flag value' form, where the
old sh -c passed 'sh -c <flags>' to the image entrypoint.

Also binds Mysterium's UI/tequilapi to 127.0.0.1 (was 0.0.0.0, exposing the node control
API to the LAN under host networking); host-net + NET_ADMIN kept for VPN NAT traversal.

Verified: go build/vet/test -race green (tokenizer + injection unit tests); a live
busybox demo confirmed the old sh -c ran an injected ; command while the argv form keeps
it inert.
@GeiserX GeiserX force-pushed the security/deploy-command-hardening branch from 239950d to 1e391fd Compare July 5, 2026 07:56
@GeiserX GeiserX merged commit 0c36493 into main Jul 5, 2026
5 checks passed
@GeiserX GeiserX deleted the security/deploy-command-hardening branch July 5, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant