diff options
| author | tobtoht <tob@featherwallet.org> | 2026-06-20 20:15:20 +0000 |
|---|---|---|
| committer | tobtoht <tob@featherwallet.org> | 2026-06-20 20:15:20 +0000 |
| commit | 003e667576f38812e27cbb79125a0ba96036225d (patch) | |
| tree | c4ac0b7ccba01138bbb1fd0d1d30041965647ff8 /src | |
| parent | a003cb75b6416488d0a448198e6de03211ae1a67 (diff) | |
| parent | 0fbb1716fba3847a7d6f60287d20c1d9f03489cf (diff) | |
| download | monzero-gui-003e667576f38812e27cbb79125a0ba96036225d.tar.gz monzero-gui-003e667576f38812e27cbb79125a0ba96036225d.tar.xz monzero-gui-003e667576f38812e27cbb79125a0ba96036225d.zip | |
Merge pull request #4609
0fbb171 TransactionHistory: prevent CSV formula injection in writeCSV (Thomas)
ACKs: selsta
Diffstat (limited to 'src')
| -rw-r--r-- | src/libwalletqt/TransactionHistory.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 764a3178..f5c3b752 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -36,6 +36,31 @@ #include <QWriteLocker> #include <QtGlobal> +namespace { + QString sanitizeCSVField(QString field) + { + field.remove(QChar('"')); + + if (field.isEmpty()) { + return field; + } + + const QChar first = field.at(0); + const bool needsPrefix = + first == QChar('=') || + first == QChar('+') || + first == QChar('-') || + first == QChar('@') || + first.isSpace() || + first.category() == QChar::Other_Control; + + if (needsPrefix) { + field.prepend(QChar('\'')); + } + + return field; + } +} bool TransactionHistory::transaction(int index, std::function<void (TransactionInfo &)> callback) { @@ -196,10 +221,8 @@ QString TransactionHistory::writeCSV(quint32 accountIndex, QString out) else { continue; // skip TransactionInfo::Direction_Both } - QString label = info.label(); - label.remove(QChar('"')); // reserved - QString description = info.description(); - description.remove(QChar('"')); // reserved + QString label = sanitizeCSVField(info.label()); + QString description = sanitizeCSVField(info.description()); quint64 blockHeight = info.blockHeight(); QDateTime timeStamp = info.timestamp(); QString date = info.date() + " " + info.time(); |
