fix(build): quote paths in root logrotate cleanup to prevent arbitrary deletion#1602
Open
pragmaxim wants to merge 1 commit into
Open
fix(build): quote paths in root logrotate cleanup to prevent arbitrary deletion#1602pragmaxim wants to merge 1 commit into
pragmaxim wants to merge 1 commit into
Conversation
…y deletion The generated Debian package installs a daily cron wrapper that runs bin/logrotate.sh as root, while postinst chowns the per-coin log directory to the unprivileged Blockbook service user. The cleanup script expanded the discovered log path unquoted in both `fuser` and `rm -f $log`, so a file whose name contains shell word-splitting tokens (e.g. "blockbook-bitcoin.log -rf /opt/coins/data/bitcoin/backend") would be split into multiple operands. On GNU rm, `-rf` is honored even after an earlier operand, letting the service user cause the root cron job to recursively delete an attacker-chosen path outside the log tree (backend/RocksDB data, config, other coins' data). Quote "$LOGS" and "$log" and pass `--` before operands so an attacker-controlled path is always treated as a single non-option argument. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generated Blockbook Debian package installs a daily cron wrapper that runs
bin/logrotate.shas root, whilepostinstchowns the per-coinlogs/directory to the unprivilegedblockbook-<coin>service user. The cleanup script expanded the discovered log path unquoted in bothfuserandrm -f $log:A file created by the service user whose name contains shell word-splitting tokens — e.g.
blockbook-bitcoin.log -rf /opt/coins/data/bitcoin/backend— is split into multiplermoperands. On GNUrm,-rfis honored even after a leading operand, so the root cron job can be steered into recursively deleting an attacker-chosen path outside the log tree (backend node data, Blockbook RocksDB, config, other coins' data). Thefind -mtime +7filter is not a barrier since the attacker controls the file's mtime.This is a local privilege-boundary issue (root-mediated arbitrary recursive deletion), reachable by anyone who can write as the Blockbook service user — the realistic outcome of a Blockbook process compromise.
Fix
Quoting keeps the path a single word;
--terminates option parsing so a name beginning with-can't be interpreted as a flag.Scope
Change is limited to
build/templates/blockbook/logrotate.sh.postinst's unquoted$direxpansions use build-time template values (BlockbookInstallPath,Coin.Alias), not runtime attacker input, so they carry no injection vector and are left untouched.As defense-in-depth follow-up, package log cleanup could move to a standard
logrotate.dconfig so a root process never walks a service-user-owned tree treating paths as shell words.🤖 Generated with Claude Code