fix(installer): resolve macOS crashes, missing variables, and safe sys.argv sha256 fallback in install.sh (closes #16251) - #8185
Conversation
FlintLeng
left a comment
There was a problem hiding this comment.
PR Review: macOS Installer — Code Injection Fix + Safe sys.argv sha256
Reviewed on: 2026-08-07
Bounty
rustchain-bounties#16251: security fix — claim confirmed by PR body.
Summary
Resubmission addressing @Scottcjn review feedback. Fixes code injection in the miner ID generation step of install.sh on macOS, and adds safe sha256 fallbacks across platforms.
Security Analysis ✅
Code injection via echo -n: The old code:
miner_id=$(echo -n "${wallet}-${arch}-$(hostname)" | sha256sum 2>/dev/null | cut -c1-16 || echo "${wallet}")If $wallet, $arch, or hostname contain shell metacharacters (;, backticks, $()), they would be evaluated by the shell. A wallet named x; rm -rf / would execute arbitrary code.
The fix is correct and defence-in-depth:
printf '%s-%s-%s'—printfwith%sformat strings safely quotes each argument; no shell evaluation- Cascade fallback:
sha256sum→shasum -a 256→python3 hashlib.sha256()→ wallet name only - The Python fallback uses positional
sys.argv[1],[2],[3]— not f-string or format interpolation. This eliminates the injection vector entirely. The old comment said "safe positional arguments" which is the correct fix.
The MINER_CRYPTO_URL addition for macOS is a prerequisite for the sha256 fallback — the macOS miner needs miner_crypto.py to be present. Correct.
Test Coverage
test_macos_installer_compatibility.py validates two things:
MINER_CRYPTO_URLis defined inside the Darwin block- Both
shasum -a 256andhashlib.sha256are present in the script
These are structural assertions on the script content, appropriate for installer tests that can't easily run a full install in a test environment.
Minor Notes
-
|| echo "${wallet}"is still in the sha256sum/shasum branches — this is fine as a last-resort fallback, but it means a macOS box with no sha256 tools gets a predictable miner_id (wallet-only), which could collide across machines. Document this limitation. -
The Python fallback uses
f"{sys.argv[1]}-{sys.argv[2]}-{sys.argv[3]}"— thefprefix here is on a single line without external input;sys.argvelements are passed as literal arguments, so no injection risk. Clean.
Wallet: RTC019e78d600fb3131c29d7ba80aba8fe644be426e
✅ LGTM — clean security fix that eliminates the injection vector and provides robust cross-platform fallbacks.
Resubmitting PR per @Scottcjn review:
Security Hardening
python3 -cfallback with safe positional arguments (sys.argv[1],sys.argv[2],sys.argv[3]), eliminating potential arbitrary code injection via--wallet.echo -nwithprintf '%s-%s-%s'for clean POSIX execution.Fixes & Compatibility
MINER_CRYPTO_URLin Darwin branch and uses portableshasum -a 256/python3 sys.argvfallbacks whensha256sumis missing.tests/test_macos_installer_compatibility.py100%.Closes #16251
Bounty claim: Scottcjn/rustchain-bounties#16251 (10 RTC)
Wallet: RTCfe13452d122263caf633ab1876bd9631133b68b1