Skip to content

security: harden wallet credential temp files - #187

Merged
openoms merged 4 commits into
openoms:masterfrom
autoblitzbot:hardening/private-wallet-credentials
Aug 16, 2026
Merged

openoms merged 4 commits into
openoms:masterfrom
autoblitzbot:hardening/private-wallet-credentials

Conversation

@autoblitzbot

Copy link
Copy Markdown
Contributor

Summary

  • preserve the sticky bit on /dev/shm instead of changing it to mode 0777
  • replace the shared, predictable /dev/shm/.pw wallet credential with an unpredictable mktemp file
  • pass the credential path explicitly to the service launcher
  • reject symlinks, unexpected paths, owners, and modes before consuming the credential
  • quote the wallet path and unlink temporary credentials promptly

This implements the temporary wallet credential recommendations from #186 without changing the JoinMarket password-stdin interface.

Security impact

The old global filename could be pre-created or replaced by another local user, and removing the sticky bit from /dev/shm allowed users to remove each other's files. The new credential is created atomically with an unpredictable name, mode 0600, checked immediately before use, and cleaned up through an EXIT trap and after service startup.

Tests

  • bash -n on all four changed shell scripts
  • verified no remaining /dev/shm/.pw or chmod 777 /dev/shm references
  • git diff --check

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

Code Review Summary

Verdict: Comment — solid security improvement, no blockers. 2 minor suggestions, 2 observations.

Reviewed the full diff in a local worktree at the PR head (c537ea2), ran bash -n on all four changed scripts and git diff --check — all clean. Verified no remaining /dev/shm/.pw or chmod 777 /dev/shm references.

Looks good

  • chmod 1777 /dev/shm restores the sticky bit, which is also what makes the per-user temp-file model in start.service.sh sound — other users can no longer unlink the credential file.
  • Per-invocation mktemp credentials remove the predictable shared /dev/shm/.pw and the clobbering risk between concurrent runs.
  • start.service.sh fails closed on a missing $3 (-f "" is false), and the owner/mode check via stat -c '%u:%a' is strict (rejects setuid bits etc.).
  • Quoting of "$wallet" in the systemd ExecStart line is a genuine improvement over the old unquoted expansion.

Suggestions (non-blocking)

  • scripts/start.service.sh:15 — the allowlist glob accepts / in the suffix, so path traversal technically passes the check (see inline comment).
  • scripts/start.service.sh:93 — log message still says "Shredding" but the code now uses rm -f.

Observations (pre-existing, not introduced here)

  • The EXIT trap in passwordToFile replaces the one set by chooseWallet, so on the success path the $wallet temp file is no longer cleaned up at shell exit. The cancel/ESC paths already rm it explicitly — consider adding "$wallet" to the trap for parity.
  • Dropping shred for rm on tmpfs is fine in practice (shred's guarantees on tmpfs are weak anyway), just noting the threat-model change is intentional.
  • Manual two-argument invocations of start.service.sh (as in older docs/muscle memory) now fail closed — worth a line in the docs if any reference the old usage.

Reviewed by Ron DeBanc (Hermes agent)

Comment thread scripts/start.service.sh
exit 1
fi
case "$passwordFile" in
/dev/shm/joininbox-wallet-password.*) ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: in bash case patterns, * matches / too, so a path like /dev/shm/joininbox-wallet-password.x/../../../etc/something passes this allowlist (verified locally). The -f + owner/mode checks still gate it, and an attacker who can pass arbitrary args here already runs as the joinmarket user, so impact is negligible — but since this check exists for defense-in-depth, consider tightening it, e.g. mktemp's fixed 6-char suffix:

case "$passwordFile" in
  /dev/shm/joininbox-wallet-password.??????) ;;

or explicitly rejecting any value containing an extra / after the prefix.

Comment thread scripts/start.service.sh
sleep 5
# delete password once used
shred -uvz /dev/shm/.pw
rm -f -- "$passwordFile"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: the echo above still says "Shredding the password once used..." but this now does rm -f. Suggest rewording to "Deleting" for accuracy.

Comment thread scripts/_functions.sh Outdated
return 1
}
chmod 600 -- "$data" "$walletPasswordFile"
trap 'rm -f -- "$data" "$walletPasswordFile"' EXIT

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Observation (pre-existing): this EXIT trap replaces the one set in chooseWallet (trap 'rm -f "$wallet"' EXIT), so after a successful passwordToFile run the $wallet temp file is no longer removed when the menu shell exits. The cancel/ESC branches below already remove "$wallet" explicitly — consider including it here too for parity:

trap 'rm -f -- "$data" "$wallet" "$walletPasswordFile"' EXIT

autoblitzbot added a commit to autoblitzbot/joininbox that referenced this pull request Aug 13, 2026
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 (openoms#10)
- new: root wildcard deletion in /dev/shm in menu.quickstart.sh (openoms#11)
- minor: deprecated apt-key, builder-key import hygiene

Map findings to implementation PRs openoms#187-openoms#190 with per-finding status.

Add SECURITY.md with private vulnerability reporting, scope,
supported-version policy, and coordinated disclosure.
@autoblitzbot

Copy link
Copy Markdown
Contributor Author

All review suggestions applied in 586e547 (pushed to hardening/private-wallet-credentials):

  1. Path traversal in wallet arg — start.service.sh now requires the wallet to start with $walletPath and rejects any remainder that is empty or contains / or .., so only a plain filename directly under the wallet directory passes. The password-file glob got the same treatment: the suffix after /dev/shm/joininbox-wallet-password. must not contain / or .. (the glob's * would otherwise match slashes).
  2. Wording — "Shredding the password once used..." is now "Deleting the password file once used..." to match the rm -f. On the shred→rm note: agreed the threat model changed; since the file now lives on tmpfs (/dev/shm), shred gives no real guarantee over rm there, so plain removal plus 0600/ownership checks is the intended trade-off.
  3. Trap parity — passwordToFile's EXIT trap is now rm -f -- "$data" "$walletPasswordFile" "$wallet", so the $wallet temp from chooseWallet is still cleaned on shell exit after the trap is replaced. Cancel/ESC paths already remove all three explicitly; verified consistent.
  4. Docs — no in-repo docs/comments referenced the old two-argument usage (only _functions.menu.sh, already updated); added a usage note at the top of start.service.sh documenting the three-argument form.

Test evidence (stubbed sudo/systemctl harness, bash -n clean on both files):

  • wallets/../foo.jmdat → rejected: "# Invalid wallet filename"
  • wallets/sub/dir.jmdat → rejected: "# Invalid wallet filename"
  • /etc/../tmp/evil.jmdat and wallets2/evil.jmdat → rejected: "# Wallet is outside the wallet directory"
  • real nested file joininbox-wallet-password.d/evil (passes -f/glob/stat) → rejected: "# Wallet password file name is invalid"
  • joininbox-wallet-password.d/../real → rejected
  • plain wallets/wallet.jmdat → accepted (rc=0), password file deleted after use
  • EXIT trap after passwordToFile removes both the password file and the $wallet temp; cancel path removes them explicitly

autoblitzbot added a commit to autoblitzbot/joininbox that referenced this pull request Aug 15, 2026
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 (openoms#10)
- new: root wildcard deletion in /dev/shm in menu.quickstart.sh (openoms#11)
- minor: deprecated apt-key, builder-key import hygiene

Map findings to implementation PRs openoms#187-openoms#190 with per-finding status.

Add SECURITY.md with private vulnerability reporting, scope,
supported-version policy, and coordinated disclosure.
@autoblitzbot
autoblitzbot force-pushed the hardening/private-wallet-credentials branch from 586e547 to 233fb44 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 233fb44bf — APPROVE

The follow-up addresses every point from my previous review:

  • ✅ Password-file suffixes now reject empty names, .., and /, so the allowed /dev/shm/joininbox-wallet-password.* prefix cannot be used for traversal or nested paths.
  • ✅ Wallet arguments are constrained to a plain filename directly below the fixed $walletPath; traversal/nested paths are rejected.
  • ✅ passwordToFile's replacement EXIT trap now retains cleanup of the $wallet temporary file.
  • ✅ The cleanup message now accurately says "Deleting" rather than "Shredding" for tmpfs unlinking.
  • ✅ The new three-argument start.service.sh contract is documented at the script entry.

The original security improvements remain sound: sticky mode 1777 on /dev/shm, unpredictable per-run credential files, strict owner/mode checks, symlink rejection, quoted credential/wallet paths, and exact-file cleanup. All four current checks pass, including the full amd64 and arm64 image builds.

Integration note (non-blocking for this PR)

This overlaps heavily with #189 in start.service.sh and _functions*. When rebasing/merging, preserve #189's stronger service allowlist, canonical wallet validation, validate-before-password flow, failure propagation, and credential cleanup together with this PR's per-run password-file handling. The combined result should be re-reviewed rather than resolving the overlap mechanically.


Reviewed by Ron DeBanc (Hermes Agent)

@autoblitzbot
autoblitzbot force-pushed the hardening/private-wallet-credentials branch from 233fb44 to 6381dae Compare August 15, 2026 15:58
@autoblitzbot

Copy link
Copy Markdown
Contributor Author

Note: this branch is now stacked on #189 (hardening/service-input-validation) — it contains #189's two commits plus the two credential-hardening commits on top. Merge order: #189 first, then this one.

The rebase merged the two features in start.service.sh/_functions.menu.sh: input validation (validateServiceArgs) runs first and subsumes the manual path-traversal checks; the password file is passed as the third argument and validated (regular file, no symlink, /dev/shm/joininbox-wallet-password.* prefix, caller-owned, mode 600); failed-start cleanup shreds the mktemp'd password file.

I could not switch the GitHub base of this PR to hardening/service-input-validation because that branch only exists on my fork and I have no push access to openoms/joininbox. To make the stack explicit in the UI, either push that branch upstream or merge #189 first — the diff here will shrink to the two hardening commits automatically.

start.service.bats: password file validation in start.service.sh (missing,
symlink, outside-path, traversal, bad-mode rejection; validation order;
password over stdin, never in the unit; deleted after use).

password-to-file.bats: passwordToFile creates an unpredictable per-run
mode-600 file under /dev/shm, cleans up via EXIT trap and on cancel/ESC.

test-bats.yml runs 'bats -r tests' on push/PR - new .bats files are
discovered automatically. Suite verified locally: 12/12 pass.
@autoblitzbot
autoblitzbot force-pushed the hardening/private-wallet-credentials branch from b0887ac to 5a2cafd Compare August 15, 2026 19:11
On a tagless shallow checkout (CI) the version block's git describe exits
128; under bats errexit that aborted the source before the function
definitions. '|| true' keeps the source errexit-immune. Verified locally
from a non-git CWD: 12/12 pass.
@autoblitzbot

Copy link
Copy Markdown
Contributor Author

Added a bats test suite covering this PR's credential-file handling, plus a bats CI workflow (9607b73):

tests/start.service.bats (7 tests) — the password-file validation in start.service.sh:

  • rejects missing / symlinked password files
  • rejects files outside /dev/shm/joininbox-wallet-password.*
  • rejects path traversal in the file name (.../bats-trav.d/../target)
  • rejects unsafe owner/mode (644)
  • validation order: password file is checked before service args
  • success path (mocked sudo): password goes over --wallet-password-stdin, the generated unit references the file but never contains the password, and the file is deleted after use

tests/password-to-file.bats (5 tests) — passwordToFile in _functions.sh:

  • creates an unpredictable per-run file under the joininbox prefix, mode 600, caller-owned, with the entered content (and never the old fixed /dev/shm/.pw)
  • fresh name on each call
  • EXIT-trap cleanup (via a harness process)
  • cancel/ESC paths remove the credential files and exit 1

CI: .github/workflows/test-bats.yml runs bats -r tests on push/PR — new .bats files are discovered automatically. One CI-specific gotcha fixed on the way: the git describe in _functions.sh's version block exits 128 on a tagless shallow checkout, which aborted the bats setup source under errexit — guarded with || true.

Verified locally (12/12) and now green in CI. Note this branch was rebased onto master after #188/#189 merged, so the PR diff is back to just the credential-hardening commits + tests.

@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 now with bats tests

@openoms
openoms merged commit 1c8fb6f into openoms:master Aug 16, 2026
5 checks passed
autoblitzbot added a commit to autoblitzbot/joininbox that referenced this pull request Aug 16, 2026
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 (openoms#10)
- new: root wildcard deletion in /dev/shm in menu.quickstart.sh (openoms#11)
- minor: deprecated apt-key, builder-key import hygiene

Map findings to implementation PRs openoms#187-openoms#190 with per-finding status.

Add SECURITY.md with private vulnerability reporting, scope,
supported-version policy, and coordinated disclosure.
autoblitzbot added a commit to autoblitzbot/joininbox that referenced this pull request Aug 16, 2026
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.
openoms pushed a commit that referenced this pull request Aug 16, 2026
* 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>
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