Skip to content

fix(installer): resolve macOS crashes, missing variables, and safe sys.argv sha256 fallback in install.sh (closes #16251) - #8185

Open
lequangsang01 wants to merge 2 commits into
Scottcjn:mainfrom
lequangsang01:fix/bounty-16251-macos-installer-fix
Open

fix(installer): resolve macOS crashes, missing variables, and safe sys.argv sha256 fallback in install.sh (closes #16251)#8185
lequangsang01 wants to merge 2 commits into
Scottcjn:mainfrom
lequangsang01:fix/bounty-16251-macos-installer-fix

Conversation

@lequangsang01

Copy link
Copy Markdown
Contributor

Resubmitting PR per @Scottcjn review:

Security Hardening

  • Replaced inline string interpolation in python3 -c fallback with safe positional arguments (sys.argv[1], sys.argv[2], sys.argv[3]), eliminating potential arbitrary code injection via --wallet.
  • Replaced echo -n with printf '%s-%s-%s' for clean POSIX execution.

Fixes & Compatibility

  1. Darwin/macOS Support: Correctly defines MINER_CRYPTO_URL in Darwin branch and uses portable shasum -a 256 / python3 sys.argv fallbacks when sha256sum is missing.
  2. Test Suite: Passes tests/test_macos_installer_compatibility.py 100%.

Closes #16251
Bounty claim: Scottcjn/rustchain-bounties#16251 (10 RTC)

Wallet: RTCfe13452d122263caf633ab1876bd9631133b68b1

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/S PR: 11-50 lines labels Aug 5, 2026

@FlintLeng FlintLeng 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.

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:

  1. printf '%s-%s-%s'printf with %s format strings safely quotes each argument; no shell evaluation
  2. Cascade fallback: sha256sumshasum -a 256python3 hashlib.sha256() → wallet name only
  3. 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:

  1. MINER_CRYPTO_URL is defined inside the Darwin block
  2. Both shasum -a 256 and hashlib.sha256 are 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

  1. || 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.

  2. The Python fallback uses f"{sys.argv[1]}-{sys.argv[2]}-{sys.argv[3]}" — the f prefix here is on a single line without external input; sys.argv elements 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants