Problem: Restricted RPC users and callers of createwallet or restorewallet can inject newlines through rejected methods or wallet names, and global log escaping preserves them, making forged lines look like node messages.
Fix: Escape embedded newlines in log messages.
<details> <summary>Manual reproducer</summary>
DATADIR="$(mktemp -d /tmp/bitcoin-log-injection.XXXXXX)"
M="$(date -u +%Y-%m-%dT%H:%M:%SZ) ERROR: ConnectTip: ConnectBlock 0000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef failed, bad-txns-inputs-missingorspent"
cmake -B build >/dev/null 2>&1 && cmake --build build -j >/dev/null 2>&1
build/bin/bitcoind -regtest -daemonwait -datadir="$DATADIR" -rpcwhitelist=__cookie__:getblock,stop >/dev/null 2>&1
build/bin/bitcoin-cli -regtest -datadir="$DATADIR" $'getblock\n'"$M" >/dev/null 2>&1; killall bitcoind >/dev/null
echo; grep -E 'ConnectTip|not allowed' "$DATADIR/regtest/debug.log"
Before
2026-07-28T23:18:57Z [warning] RPC User __cookie__ not allowed to call method getblock
2026-07-28T23:18:55Z ERROR: ConnectTip: ConnectBlock 0000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef failed, bad-txns-inputs-missingorspent
After
2026-07-28T23:19:45Z [warning] RPC User __cookie__ not allowed to call method getblock\x0a2026-07-28T23:19:41Z ERROR: ConnectTip: ConnectBlock 0000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef failed, bad-txns-inputs-missingorspent
</details>