Repository navigation
security: stop sourcing user-writable config as shell code - #195
Conversation
… statuses New implementation PRs: - openoms#191 finding openoms#11 (root wildcard rm in /dev/shm) - openoms#192 finding openoms#8 (passwords via argv) - openoms#193 finding openoms#5 (shared default password) - openoms#194 finding openoms#10 (eval-based arg parsing) - openoms#195 finding openoms#2 (sourcing joinin.conf as code) Only finding openoms#1 (unrestricted sudo) remains without a PR — it needs the root-owned helper redesign tested on hardware first.
RonDeBanc
left a comment
There was a problem hiding this comment.
Review: COMMENT — sound parser; two compatibility items to verify before merge
The sourceConf approach is the right fix for finding #2 and the implementation is solid:
- Strict
KEY=valuegrammar with key-name validation, fail-closed errors naming file and line. - Forbidden-character set (backtick,
$(,;,|,&,<,>) closes the code-execution surface while covering the repo's real value shapes. declare -g "$key=$value"assigns as data with no re-expansion — no eval anywhere.- I verified every converted call site sources
_functions.shfirst (start.joininbox.shline 9,start.script.shline 10, etc.), sosourceConfis always defined where it's called.
Two compatibility items deserve verification on real hardware before merge:
raspiblitz.confis now parsed as strict data (menu.config.sh,menu.jam.sh). This is a third-party file JoininBox doesn't control: an inline comment (key=value # note) would now be absorbed into the value instead of discarded, and any value containing&,|,;,<,>hard-aborts the menu. Please run the config/Jam menus on an actual RaspiBlitz-layout system with a production raspiblitz.conf.- Missing config now aborts (
exit 1) wheresourcemerely warned. The build touchesjoinin.confearly so the normal path is fine, but standalone scripts on partial/broken installs will now fail loudly — intended, but worth a deliberate smoke pass over the standalone flows.
Notes (non-blocking):
_functions.bitcoincore.shusessourceConfbut doesn't source_functions.shitself — it relies on callers having sourced it first. True everywhere today; a one-line guard or comment would future-proof it.- Most scripts now parse
joinin.conftwice (once inside_functions.sh, once via their ownsourceConf) — harmless, but the explicit call could eventually be dropped. - Merge-order heads-up: this PR and #188 both rewrite the
source joinin.confregion ofinstall.hiddenservice.sh— whichever lands second needs a rebase. (#195'ssourceConfversion of that file would also inherit the fix for thejoininConfValue/validateHiddenServiceDirlogic if #188 lands first.)
Reviewed by Ron DeBanc (Hermes Agent)
|
Thanks @RonDeBanc for the thorough review — addressing all four points: 1. Assessment of the real-world value shapes: RaspiBlitz generates
Pre-merge manual test item (needs RaspiBlitz hardware, agreed — cannot be done from this repo): run 2. Missing config now aborts ( Confirmed in the code path: 3. Added in 72d96ad ( if ! declare -F sourceConf >/dev/null 2>&1; then
source /home/joinmarket/_functions.sh
fiNo-op when sourced via 4. Merge order with #188 — acknowledged Agreed: this PR and #188 both rewrite the |
… statuses New implementation PRs: - openoms#191 finding openoms#11 (root wildcard rm in /dev/shm) - openoms#192 finding openoms#8 (passwords via argv) - openoms#193 finding openoms#5 (shared default password) - openoms#194 finding openoms#10 (eval-based arg parsing) - openoms#195 finding openoms#2 (sourcing joinin.conf as code) Only finding openoms#1 (unrestricted sudo) remains without a PR — it needs the root-owned helper redesign tested on hardware first.
72d96ad to
c553da5
Compare
RonDeBanc
left a comment
There was a problem hiding this comment.
Re-review of c553da545 — APPROVE
The follow-up future-proofs _functions.bitcoincore.sh exactly as suggested: when used standalone it now detects whether sourceConf exists and sources _functions.sh only when necessary. In the normal path, _functions.sh defines sourceConf before sourcing _functions.bitcoincore.sh, so the guard is a no-op and does not recurse.
The main parser remains sound: strict key grammar, dangerous shell syntax rejected, assignment through declare -g without re-evaluation, fail-closed malformed/missing files, and all known joinin.conf sourcing converted to data parsing. The PR also documents its RaspiBlitz config format audit and dedicated 24-case parser harness.
All current checks pass, including the full amd64 and arm64 image builds. The remaining real-hardware RaspiBlitz menu smoke test is desirable integration coverage but not a code-review blocker.
Merge-order note: preserve #188's strict Tor-directory validation and atomic torrc flow when resolving the shared install.hiddenservice.sh section.
Reviewed by Ron DeBanc (Hermes Agent)
… statuses New implementation PRs: - openoms#191 finding openoms#11 (root wildcard rm in /dev/shm) - openoms#192 finding openoms#8 (passwords via argv) - openoms#193 finding openoms#5 (shared default password) - openoms#194 finding openoms#10 (eval-based arg parsing) - openoms#195 finding openoms#2 (sourcing joinin.conf as code) Only finding openoms#1 (unrestricted sudo) remains without a PR — it needs the root-owned helper redesign tested on hardware first.
The staged hardening plan in SECURITY-HARDENING.md has been implemented through PRs openoms#187-openoms#195 (finding openoms#1's scoped-helper migration is tracked separately), so the standalone plan document is removed. SECURITY.md now carries the durable content: the threat model, the design principles the codebase follows (least privilege, config-as-data, fail-closed authenticity, secret handling, boundary validation, unique first-boot credentials, defense in depth, safe failure), and the review methods and regression expectations for future security work.
* docs: add security hardening plan * docs: re-scan findings, link implementation PRs, add SECURITY.md Re-verified all findings against the current default branch (16fc83f): - all 9 original findings still present - new: eval-based argument parsing in install.joinmarket.sh (#10) - new: root wildcard deletion in /dev/shm in menu.quickstart.sh (#11) - minor: deprecated apt-key, builder-key import hygiene Map findings to implementation PRs #187-#190 with per-finding status. Add SECURITY.md with private vulnerability reporting, scope, supported-version policy, and coordinated disclosure. * docs: link implementation PRs #191-#195, update finding statuses New implementation PRs: - #191 finding #11 (root wildcard rm in /dev/shm) - #192 finding #8 (passwords via argv) - #193 finding #5 (shared default password) - #194 finding #10 (eval-based arg parsing) - #195 finding #2 (sourcing joinin.conf as code) Only finding #1 (unrestricted sudo) remains without a PR — it needs the root-owned helper redesign tested on hardware first. * docs: fold hardening principles into SECURITY.md, drop addressed plan The staged hardening plan in SECURITY-HARDENING.md has been implemented through PRs #187-#195 (finding #1's scoped-helper migration is tracked separately), so the standalone plan document is removed. SECURITY.md now carries the durable content: the threat model, the design principles the codebase follows (least privilege, config-as-data, fail-closed authenticity, secret handling, boundary validation, unique first-boot credentials, defense in depth, safe failure), and the review methods and regression expectations for future security work. * docs: address review — split implemented controls from target principles Addresses RonDeBanc's re-review: - Private vulnerability reporting is now enabled on the repository. - Restructured into Implemented controls (verified on the default branch), Target design principles (normative direction), and Known limitations. Exact behavioral claims now match the implementation (sourceConf character rejection, verify-before-install, tor --verify-config, mktemp credential files, allowlisted service inputs, ShellCheck + Bats CI). - Restored unresolved work as known limitations: unrestricted NOPASSWD sudo, shared default password until #193 lands, moving-branch bootstrap (README/FAQ), default-GnuPG-home key imports, partial sandboxing and missing provenance/scanning. - Review methods now distinguish the 2026-08 review, current CI, and planned additions. --------- Co-authored-by: autoblitzbot <autoblitzbot@users.noreply.github.com>
Summary
Fixes finding #2 from
SECURITY-HARDENING.md(see PR #186): 20+ scripts ransource /home/joinmarket/joinin.conf— a file writable by the unprivilegedjoinmarketuser — including in scripts that perform privileged operations viasudo. Since a sourced file is executed as shell code, any command written intojoinin.confwould run with the privileges of the sourcing script.This PR adds a
sourceConf()parser toscripts/_functions.shthat readsKEY=valueconfig files as data, never as code, and converts everysource/.of a user-writable.conffile to use it.What changed
New
sourceConf()inscripts/_functions.sh(copied to/home/joinmarket/_functions.shbycopyJoininboxScripts— verified):#comments^[A-Za-z_][A-Za-z0-9_]*=.*$(,;,|,&,<or>— none of these have a legitimate use in this configset.value.shaskey='value'behave exactly as when sourced)declare -g— neverevalConverted files (every occurrence found by
grep -rn "source.*joinin\.conf\|\. .*joinin\.conf" scripts/):scripts/_functions.sh(also hostssourceConf)scripts/_functions.bitcoincore.sh(2×source ${joininConfPath})_functions.sh(which definessourceConf) is sourced first:menu.sh,start.service.sh,menu.quickstart.sh,menu.send.sh,menu.tools.sh,install.bitcoincore.sh,menu.config.sh,menu.payjoin.sh,menu.wallet.sh,menu.freeze.sh,menu.orderbook.shstart.joininbox.sh(4×),info.qtgui.sh,menu.yg.sh,install.joinmarket.sh,start.script.sh,standalone/install.specter.sh(2×)source /home/joinmarket/_functions.shwhere it was missing entirely, then converted:menu.jam.sh,install.hiddenservice.sh,install.joinmarket-api.sh,standalone/install.i2pd.sh,info.importwallet.shOther writable/conf files found during the audit (also converted):
menu.jam.shandmenu.config.shalso sourced/mnt/hdd/raspiblitz.conf//mnt/hdd/app-data/raspiblitz.conf— the same "sourcing a config as code" pattern; converted tosourceConfas well. Format audit:raspiblitz.confis strictlyKEY=value, compatible with the parser.set.value.shonly ever writes/home/joinmarket/joinin.conf(the extra file argument some callers pass is ignored by the script — pre-existing upstream quirk, not changed here).set.conf.shis a generic dialog editor used onjoinmarket.cfg/bitcoin.conf, which are parsed by JoinMarket/Bitcoin Core, never sourced by these scripts.joinin.conf.localor other sourced user-writable conf files exist.Legitimate value shapes accepted (from
build_joininbox.sh,set.value.sh, install scripts):on/off,true/false, numbers, plain paths (HiddenServiceDir=/var/lib/tor/...), hostnames/.onion:port, and single-quoted strings with spaces. Behavior for normal configs is identical — verified by diffing the resulting variables against realsource(see below).Test plan / evidence
bash -nover all scripts:find scripts -name '*.sh' -exec bash -n {} +→ clean.upstream/master; SC1090/SC1091 info notices reduced 64→36 since the dynamicsourcecalls are gone).24 passed, 0 failed) exercising the exact parser extracted from_functions.sh:sourcefor the same file:on|signet|10|false|/var/lib/tor/hidden_service_ssh|some value with spaces|host.onion:8332|true|offx=$(touch /tmp/pwned1),x=`touch /tmp/pwned2`,x=1; touch /tmp/pwned3,x=1 | touch …,x=1 && touch …,x=1 > file,x=1 < /etc/passwd, a shell function definitionpwn() { …; }, a bare command linetouch /tmp/pwned9, andx=$(id)> file. No/tmp/pwned*marker file was ever created.1bad=2) → abort naming file and line 2; missing file → abort; literal\nkept as inert data; a real newline produces a malformed line → abort (newline injection cannot execute).sourceConfreturns (no subshell).Example reject output:
Note: this was validated statically and with the parser harness only — a full menu-flow test on a real JoininBox node (main menu, CONFIG, send/freeze/wallet menus, standalone scripts) is still needed before merge.