Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
for (auto i = filter_ranges.rbegin(); i != filter_ranges.rend(); ++i) {
pstrFilteredOut->replace(i->first, i->second - i->first, "(…)");
}
// Prefix "!" to mark redacted commands as non-executable when recalled from history
if (!filter_ranges.empty() && !pstrFilteredOut->starts_with('!')) {
pstrFilteredOut->insert(0, 1, '!');
}
}
switch(state) // final state
{
Expand Down Expand Up @@ -405,7 +409,11 @@ void RPCExecutor::request(const QString &command, const QString& wallet_name)
" example: getblock(getblockhash(0) 1)[tx]\n\n"

"Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
" example: getblock(getblockhash(0),1)[tx][0]\n\n"

"Commands starting with a leading '!' indicate redacted entries.\n"
"Their sensitive arguments were removed and they cannot be executed.\n"
" example: !walletpassphrase(...)\n\n")));
return;
}
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
Expand Down Expand Up @@ -994,6 +1002,16 @@ void RPCConsole::on_lineEdit_returnPressed()
return;
}

// Prevent execution of redacted entries (prefixed with '!') and notify the user
if (cmd.startsWith('!')) {
QMessageBox::information(this, tr("Sensitive command"), tr(
"Command not executed: this is a redacted entry.\n"
"Sensitive arguments were removed. Retype the full command to run it again."
));
ui->lineEdit->clear();
return;
}

std::string strFilteredCmd;
try {
std::string dummy;
Expand Down
18 changes: 12 additions & 6 deletions src/qt/test/rpcnestedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,24 @@ void RPCNestedTests::rpcNestedTests()
QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");

RPCConsole::RPCParseCommandLine(nullptr, result, "createwallet test true", false, &filtered);
QVERIFY(filtered == "!createwallet(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "createwalletdescriptor abc", false, &filtered);
QVERIFY(filtered == "!createwalletdescriptor(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "migratewallet abc abc", false, &filtered);
QVERIFY(filtered == "!migratewallet(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc", false, &filtered);
QVERIFY(filtered == "signmessagewithprivkey(…)");
QVERIFY(filtered == "!signmessagewithprivkey(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc,def", false, &filtered);
QVERIFY(filtered == "signmessagewithprivkey(…)");
QVERIFY(filtered == "!signmessagewithprivkey(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "signrawtransactionwithkey(abc)", false, &filtered);
QVERIFY(filtered == "signrawtransactionwithkey(…)");
QVERIFY(filtered == "!signrawtransactionwithkey(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "walletpassphrase(help())", false, &filtered);
QVERIFY(filtered == "walletpassphrase(…)");
QVERIFY(filtered == "!walletpassphrase(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "walletpassphrasechange(help(walletpassphrasechange(abc)))", false, &filtered);
QVERIFY(filtered == "walletpassphrasechange(…)");
QVERIFY(filtered == "!walletpassphrasechange(…)");
RPCConsole::RPCParseCommandLine(nullptr, result, "help(encryptwallet(abc, def))", false, &filtered);
QVERIFY(filtered == "help(encryptwallet(…))");
QVERIFY(filtered == "!help(encryptwallet(…))");

RPCConsole::RPCExecuteCommandLine(m_node, result, "rpcNestedTest");
QVERIFY(result == "[]");
Expand Down
Loading