Skip to content

Commit a0422e5

Browse files
committed
qt: Comment out sensitive commands in history to prevent re-execution
1 parent 5c5704e commit a0422e5

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/qt/rpcconsole.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public Q_SLOTS:
9696

9797
Q_SIGNALS:
9898
void reply(int category, const QString &command);
99+
void noop();
99100

100101
private:
101102
interfaces::Node& m_node;
@@ -361,6 +362,8 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
361362
for (auto i = filter_ranges.rbegin(); i != filter_ranges.rend(); ++i) {
362363
pstrFilteredOut->replace(i->first, i->second - i->first, "(…)");
363364
}
365+
// Prefix "#" to comment out sensitive commands when recalled from history, preventing re-execution
366+
if (filter_ranges.size() > 0 && !pstrFilteredOut->starts_with("#")) pstrFilteredOut->insert(0, "#");
364367
}
365368
switch(state) // final state
366369
{
@@ -405,9 +408,16 @@ void RPCExecutor::request(const QString &command, const QString& wallet_name)
405408
" example: getblock(getblockhash(0) 1)[tx]\n\n"
406409

407410
"Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
408-
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
411+
" example: getblock(getblockhash(0),1)[tx][0]\n\n"
412+
413+
"Lines starting with '#' are treated as comments and are not executed.\n"
414+
" example: # Hello world\n\n")));
415+
return;
416+
} else if (executableCommand.starts_with("#")) {
417+
Q_EMIT noop();
409418
return;
410419
}
420+
411421
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
412422
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
413423
return;
@@ -1094,6 +1104,12 @@ void RPCConsole::startExecutor()
10941104
m_is_executing = false;
10951105
});
10961106

1107+
connect(m_executor, &RPCExecutor::noop, this, [this]() {
1108+
ui->messagesWidget->undo();
1109+
scrollToEnd();
1110+
m_is_executing = false;
1111+
});
1112+
10971113
// Make sure executor object is deleted in its own thread
10981114
connect(&thread, &QThread::finished, m_executor, &RPCExecutor::deleteLater);
10991115

src/qt/test/rpcnestedtests.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,24 @@ void RPCNestedTests::rpcNestedTests()
8585
QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
8686
QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");
8787

88+
RPCConsole::RPCParseCommandLine(nullptr, result, "createwallet test true", false, &filtered);
89+
QVERIFY(filtered == "#createwallet(…)");
90+
RPCConsole::RPCParseCommandLine(nullptr, result, "createwalletdescriptor abc", false, &filtered);
91+
QVERIFY(filtered == "#createwalletdescriptor(…)");
92+
RPCConsole::RPCParseCommandLine(nullptr, result, "migratewallet abc abc", false, &filtered);
93+
QVERIFY(filtered == "#migratewallet(…)");
8894
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc", false, &filtered);
89-
QVERIFY(filtered == "signmessagewithprivkey(…)");
95+
QVERIFY(filtered == "#signmessagewithprivkey(…)");
9096
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc,def", false, &filtered);
91-
QVERIFY(filtered == "signmessagewithprivkey(…)");
97+
QVERIFY(filtered == "#signmessagewithprivkey(…)");
9298
RPCConsole::RPCParseCommandLine(nullptr, result, "signrawtransactionwithkey(abc)", false, &filtered);
93-
QVERIFY(filtered == "signrawtransactionwithkey(…)");
99+
QVERIFY(filtered == "#signrawtransactionwithkey(…)");
94100
RPCConsole::RPCParseCommandLine(nullptr, result, "walletpassphrase(help())", false, &filtered);
95-
QVERIFY(filtered == "walletpassphrase(…)");
101+
QVERIFY(filtered == "#walletpassphrase(…)");
96102
RPCConsole::RPCParseCommandLine(nullptr, result, "walletpassphrasechange(help(walletpassphrasechange(abc)))", false, &filtered);
97-
QVERIFY(filtered == "walletpassphrasechange(…)");
103+
QVERIFY(filtered == "#walletpassphrasechange(…)");
98104
RPCConsole::RPCParseCommandLine(nullptr, result, "help(encryptwallet(abc, def))", false, &filtered);
99-
QVERIFY(filtered == "help(encryptwallet(…))");
105+
QVERIFY(filtered == "#help(encryptwallet(…))");
100106

101107
RPCConsole::RPCExecuteCommandLine(m_node, result, "rpcNestedTest");
102108
QVERIFY(result == "[]");

0 commit comments

Comments
 (0)