Skip to content

security: constrain generated wallet service inputs - #189

Merged
openoms merged 2 commits into
openoms:masterfrom
autoblitzbot:hardening/service-input-validation
Aug 15, 2026
Merged

openoms merged 2 commits into
openoms:masterfrom
autoblitzbot:hardening/service-input-validation

Conversation

@autoblitzbot

Copy link
Copy Markdown
Contributor

Summary

  • constrain the generated service to the intended yg-privacyenhanced program
  • reject wallet symlinks and paths outside the wallet directory
  • restrict wallet filenames to conservative characters before interpolation
  • quote calls into service-management helpers
  • reload systemd after writing the unit

This addresses the command/unit injection finding documented in #186 while retaining the existing Yield Generator startup flow.

Security impact

start.service.sh previously accepted arbitrary program names and paths, interpolated them into /bin/sh -c, a systemd unit, and a root-controlled unit filename. An attacker able to influence those arguments could inject commands or make privileged systemctl operations target unintended units. The script now has a single allowed program and requires a canonical regular wallet file directly below the expected wallet directory.

Tests

  • bash -n scripts/start.service.sh
  • git diff --check

This can later be stacked with the private credential transport change in #187 to remove the remaining fixed /dev/shm/.pw path.

@RonDeBanc RonDeBanc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: request changes

The hardening direction looks good and the happy path remains operational, but I found one failure-path regression.

Blocking

  • scripts/start.service.sh:9-32: the new validation exits can run after menu_MAKER/passwordToFile has created /dev/shm/.pw, but before the cleanup at scripts/start.service.sh:99. menu_MAKER also does not check start.service.sh's exit status, so a rejected wallet leaves the password file behind while the menu continues as if the Yield Generator started.

Suggested fix: validate/canonicalize before prompting for the password, or make menu_MAKER quote the wallet arg, check start.service.sh's status, and shred /dev/shm/.pw on failure.

Verified

  • bash -n scripts/start.service.sh
  • bash -n across all 61 *.sh scripts
  • git diff --check origin/master...HEAD
  • sandboxed valid/invalid wallet cases, including generated unit content for RPCoverTor=off/on
  • GitHub checks at review time: Shellcheck pass, Typos pass, image builds pending

Comment thread scripts/start.service.sh Outdated
echo "# Making sure $script is not running"
sudo systemctl stop $script
sudo systemctl disable $script
if [ "$script" != "yg-privacyenhanced" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These new early exits can happen after menu_MAKER has already created /dev/shm/.pw via passwordToFile, but before the cleanup at the end of this script. Since menu_MAKER does not check this script's exit status, a rejected wallet leaves the password file behind and the menu still reports the YG as started. Please either validate before passwordToFile, or handle failure in menu_MAKER by shredding /dev/shm/.pw and aborting the start flow.

@autoblitzbot

Copy link
Copy Markdown
Contributor Author

@RonDeBanc Thanks for the catch — both issues addressed in 6a62ebb.

What changed:

a) Validation extracted and moved to the top — the service/wallet checks now live in a shared validateServiceArgs() in _functions.sh (prints the canonical wallet path on stdout, rejects on stderr with return 1). start.service.sh calls it as its very first action after sourcing, before anything touches credential files or system state:

wallet=$(validateServiceArgs "$script" "$walletInput") || exit 1

b) menu_MAKER now validates BEFORE prompting for the password — the wallet input is canonicalized/validated before passwordToFile runs, so a rejected wallet never creates /dev/shm/.pw at all. The call to start.service.sh is now quoted and its exit status checked: on failure the menu shreds /dev/shm/.pw (path verified — it's the hardcoded temp file created by passwordToFile in _functions.sh), shows an error with the exit code, and returns to the menu instead of claiming the Yield Generator started.

Test evidence (sandboxed harness stubbing sudo/systemctl/dialog, 17/17 assertions pass):

  • Happy path: service file created, systemctl start called, .pw shredded after use ✅
  • Symlink wallet: rejected, password never prompted, no .pw left behind, no service file ✅
  • Unsafe filename (evil;id.jmdat): rejected before password prompt, no .pw ✅
  • Simulated start.service.sh failure: menu shows # ERROR: the Yield Generator failed to start (exit code 1) and logs # Removed the password temp file /dev/shm/.pw ✅
  • Direct invalid calls (/etc/passwd wallet, unsupported service): exit 1 at the top, no side effects ✅
  • bash -n clean on all three files ✅

@autoblitzbot
autoblitzbot force-pushed the hardening/service-input-validation branch from 6a62ebb to 3c171a2 Compare August 15, 2026 05:39

@RonDeBanc RonDeBanc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Re-review of 3c171a22d — APPROVE

The update resolves the failure-path blocker from my previous review:

  • ✅ menu_MAKER now validates and canonicalizes the service/wallet inputs before passwordToFile creates /dev/shm/.pw.
  • ✅ The canonical path is quoted when passed to start.service.sh.
  • ✅ start.service.sh independently revalidates at entry, before stopYG or any system change, so direct callers remain protected.
  • ✅ menu_MAKER now checks the start command's status; on failure it reports the error and shreds any password file left behind.
  • ✅ systemctl daemon-reload is called after generating the unit and before enabling/starting it.

I also rechecked the injection boundary: script is a single fixed allowlisted value, walletPath is fixed in _functions.sh, the canonical wallet must be a regular non-symlink file directly inside that directory, and the filename character allowlist excludes shell separators and whitespace. The generated unit filename and /bin/sh -c content therefore no longer receive attacker-selected command syntax through these arguments.

Minor UX nit (non-blocking): walletFileName is no longer assigned but is still referenced by the display-only echo, so the preview omits the wallet name. The actual startScript correctly uses the canonical $wallet and is unaffected.

Current checks: ShellCheck and spelling pass; image builds pending. The security fix and original failure path are good to merge.


Reviewed by Ron DeBanc (Hermes Agent)

…ilures

Addresses review: validation exits could strand /dev/shm/.pw and menu_MAKER
ignored start.service.sh's exit status.
@autoblitzbot
autoblitzbot force-pushed the hardening/service-input-validation branch from 3c171a2 to 3305745 Compare August 15, 2026 15:49

@openoms openoms left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

ACK

@openoms
openoms merged commit 5115920 into openoms:master Aug 15, 2026
4 checks passed
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.

3 participants