@@ -691,6 +691,55 @@ void RPCConsole::WriteCommandHistory()
691691 settings.endArray ();
692692}
693693
694+ void RPCConsole::ClearCommandHistory ()
695+ {
696+ // Overwrite each command in history with dummy data before clearing
697+ // This helps ensure the sensitive data is overwritten in memory
698+ for (QString& cmd : history) {
699+ // Overwrite with characters of same length (don't store new length info)
700+ cmd.fill (' x' ); // First pass: fill with 'x'
701+ cmd.fill (' \0 ' ); // Second pass: fill with null chars
702+ }
703+
704+ // Overwrite saved history in settings with dummy data
705+ QSettings settings;
706+
707+ // First pass: read existing commands and overwrite with dummy data of same length
708+ QStringList dummy_commands;
709+ int size = settings.beginReadArray (" nRPCConsoleWindowHistory" );
710+ for (int i = 0 ; i < size; ++i) {
711+ settings.setArrayIndex (i);
712+ QString cmd = settings.value (" cmd" ).toString ();
713+ // Store dummy command with same length as original (don't leak length info)
714+ dummy_commands.append (QString (cmd.size (), ' x' ));
715+ }
716+ settings.endArray ();
717+
718+ // Write dummy data to overwrite the original commands
719+ if (!dummy_commands.empty ()) {
720+ settings.beginWriteArray (" nRPCConsoleWindowHistory" );
721+ for (int i = 0 ; i < dummy_commands.size (); ++i) {
722+ settings.setArrayIndex (i);
723+ settings.setValue (" cmd" , dummy_commands[i]);
724+ }
725+ settings.endArray ();
726+ settings.sync (); // Force to disk
727+ }
728+
729+ // Clear the history list
730+ history.clear ();
731+ historyPtr = 0 ;
732+ cmdBeforeBrowsing.clear ();
733+
734+ // Second pass: write empty history to settings
735+ settings.beginWriteArray (" nRPCConsoleWindowHistory" );
736+ // Empty array - no entries written
737+ settings.endArray ();
738+
739+ // Force settings to sync to disk
740+ settings.sync ();
741+ }
742+
694743RPCConsole::~RPCConsole ()
695744{
696745 QSettings settings;
@@ -1182,6 +1231,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11821231 return ;
11831232 }
11841233
1234+ // Special command to clear command history
1235+ if (cmd == QLatin1String (" /clearhistory" )) {
1236+ QMessageBox::StandardButton reply = QMessageBox::question (this ,
1237+ tr (" Clear Command History" ),
1238+ tr (" This will permanently clear your command history and console output.<br><br>"
1239+ " While this action is irreversible, it cannot be guaranteed to be "
1240+ " completely irrecoverable from disk.<br><br>"
1241+ " Are you sure you want to proceed?" ),
1242+ QMessageBox::Yes | QMessageBox::No,
1243+ QMessageBox::No);
1244+
1245+ if (reply == QMessageBox::Yes) {
1246+ ClearCommandHistory ();
1247+ clear (false ); // Clear console output too
1248+ message (CMD_REPLY, tr (" Command history and console output cleared." ));
1249+ }
1250+ ui->lineEdit ->clear ();
1251+ return ;
1252+ }
1253+
11851254 if (m_is_executing) {
11861255 return ;
11871256 }
0 commit comments