Strip session keys and IVs from the logs

Logging these isn't a major issue because they change each session and
the privilege level to access the logs is the same as those to access the
private key of Moonlight client itself, but there's also no good reason to
log them either.
This commit is contained in:
Cameron Gutman 2024-05-27 22:02:02 -04:00
parent e07f069222
commit a0a8b70bc1

View file

@ -11,6 +11,7 @@
#include <QCursor>
#include <QElapsedTimer>
#include <QTemporaryFile>
#include <QRegularExpression>
// Don't let SDL hook our main function, since Qt is already
// doing the same thing. This needs to be before any headers
@ -60,6 +61,8 @@ static QElapsedTimer s_LoggerTime;
static QTextStream s_LoggerStream(stderr);
static QMutex s_LoggerLock;
static bool s_SuppressVerboseOutput;
static QRegularExpression k_RikeyRegex("&rikey=\\w+");
static QRegularExpression k_RikeyIdRegex("&rikeyid=[\\d-]+");
#ifdef LOG_TO_FILE
// Max log file size of 10 MB
#define MAX_LOG_SIZE_BYTES (10 * 1024 * 1024)
@ -72,6 +75,10 @@ void logToLoggerStream(QString& message)
{
QMutexLocker lock(&s_LoggerLock);
// Strip session encryption keys and IVs from the logs
message.replace(k_RikeyRegex, "&rikey=REDACTED");
message.replace(k_RikeyIdRegex, "&rikeyid=REDACTED");
#ifdef LOG_TO_FILE
if (s_LogLimitReached) {
return;