[Client] Redact share secrets from activation URL logs

This commit is contained in:
Lukas Brübach 2026-09-19 07:27:05 +02:00 committed by GitHub
parent ad08fbbe79
commit d21dfccbef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,6 +44,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTranslator> #include <QTranslator>
#include <QUrl>
#include <algorithm> #include <algorithm>
#include <libcockatrice/card/database/card_database_manager.h> #include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/rng/rng_sfmt.h> #include <libcockatrice/rng/rng_sfmt.h>
@ -177,6 +178,18 @@ QString const generateClientID()
return strClientID; return strClientID;
} }
static QString redactActivationUrl(const QString &url)
{
// Activation URLs carry secrets in their query string (e.g. the deck share
// token); log only the scheme and the action (cockatrice://opendeck), never
// the parameters.
if (!url.startsWith(QStringLiteral("cockatrice://"))) {
return url;
}
const QUrl parsed(url);
return parsed.scheme() + "://" + parsed.host();
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -273,7 +286,12 @@ int main(int argc, char *argv[])
SingleInstanceManager instance; SingleInstanceManager instance;
if (hasActivationFiles) { if (hasActivationFiles) {
qInfo() << "Activation launch, files:" << startupFiles; QStringList redactedFiles;
redactedFiles.reserve(startupFiles.size());
for (const QString &file : startupFiles) {
redactedFiles.append(redactActivationUrl(file));
}
qCInfo(MainLog) << "Activation launch, files:" << redactedFiles;
// Activation launch: hand off to the primary instance if one is // Activation launch: hand off to the primary instance if one is
// running, otherwise become the primary ourselves. Do this before // running, otherwise become the primary ourselves. Do this before
// constructing the main window so a hand-off exits cheaply. // constructing the main window so a hand-off exits cheaply.
@ -346,7 +364,7 @@ int main(int argc, char *argv[])
auto handleActivation = [&ui](const QString &file) { auto handleActivation = [&ui](const QString &file) {
if (file.startsWith("cockatrice://")) { if (file.startsWith("cockatrice://")) {
qInfo() << "Handling URL activation:" << file; qCInfo(MainLog) << "Handling URL activation:" << redactActivationUrl(file);
// Route through the window's persistent url parser: it serializes // Route through the window's persistent url parser: it serializes
// link chains so activations handed over while another chain is // link chains so activations handed over while another chain is
// still connecting do not connect concurrently. // still connecting do not connect concurrently.