mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-28 12:50:20 +02:00
feat: add regex removal for log sesnitive data
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
63d40ecda4
commit
e325806173
@ -834,6 +834,10 @@ SET(LAUNCHER_SOURCES
|
||||
icons/IconList.h
|
||||
icons/IconList.cpp
|
||||
|
||||
# log utils
|
||||
logs/AnonymizeLog.cpp
|
||||
logs/AnonymizeLog.h
|
||||
|
||||
# GUI - windows
|
||||
ui/GuiUtil.h
|
||||
ui/GuiUtil.cpp
|
||||
|
68
launcher/logs/AnonymizeLog.cpp
Normal file
68
launcher/logs/AnonymizeLog.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2025 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "AnonymizeLog.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
struct RegReplace {
|
||||
RegReplace(QRegularExpression r, QString w) : reg(r), with(w) { reg.optimize(); }
|
||||
QRegularExpression reg;
|
||||
QString with;
|
||||
};
|
||||
|
||||
static const QVector<RegReplace> anonymizeRules = {
|
||||
RegReplace(QRegularExpression("C:\\\\Users\\\\([^\\\\]+)\\\\", QRegularExpression::CaseInsensitiveOption),
|
||||
"C:\\Users\\********\\"), // windows
|
||||
RegReplace(QRegularExpression("C:\\/Users\\/([^\\/]+)\\/", QRegularExpression::CaseInsensitiveOption),
|
||||
"C:/Users/********/"), // windows with forward slashes
|
||||
RegReplace(QRegularExpression("(?<!\\\\w)\\/home\\/[^\\/]+\\/", QRegularExpression::CaseInsensitiveOption),
|
||||
"/home/********/"), // linux
|
||||
RegReplace(QRegularExpression("(?<!\\\\w)\\/Users\\/[^\\/]+\\/", QRegularExpression::CaseInsensitiveOption),
|
||||
"/Users/********/"), // macos
|
||||
RegReplace(QRegularExpression("\\(Session ID is [^\\)]+\\)", QRegularExpression::CaseInsensitiveOption),
|
||||
"(Session ID is <SESSION_TOKEN>)"), // SESSION_TOKEN
|
||||
RegReplace(QRegularExpression("new refresh token: \"[^\"]+\"", QRegularExpression::CaseInsensitiveOption),
|
||||
"new refresh token: \"<TOKEN>\""), // refresh token
|
||||
RegReplace(QRegularExpression("\"device_code\" : \"[^\"]+\"", QRegularExpression::CaseInsensitiveOption),
|
||||
"\"device_code\" : \"<DEVICE_CODE>\""), // device code
|
||||
};
|
||||
|
||||
void anonymizeLog(QString& log)
|
||||
{
|
||||
for (auto rule : anonymizeRules) {
|
||||
log.replace(rule.reg, rule.with);
|
||||
}
|
||||
}
|
40
launcher/logs/AnonymizeLog.h
Normal file
40
launcher/logs/AnonymizeLog.h
Normal file
@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2025 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
void anonymizeLog(QString& log);
|
@ -41,7 +41,9 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QUrlQuery>
|
||||
#include "logs/AnonymizeLog.h"
|
||||
|
||||
const std::array<PasteUpload::PasteTypeInfo, 4> PasteUpload::PasteTypes = { { { "0x0.st", "https://0x0.st", "" },
|
||||
{ "hastebin", "https://hst.sh", "/documents" },
|
||||
@ -184,10 +186,7 @@ auto PasteUpload::Sink::finalize(QNetworkReply&) -> Task::State
|
||||
return Task::State::Succeeded;
|
||||
}
|
||||
|
||||
Net::NetRequest::Ptr PasteUpload::make(const QString& log,
|
||||
const PasteUpload::PasteType pasteType,
|
||||
const QString customBaseURL,
|
||||
ResultPtr result)
|
||||
Net::NetRequest::Ptr PasteUpload::make(const QString& log, PasteUpload::PasteType pasteType, QString customBaseURL, ResultPtr result)
|
||||
{
|
||||
auto base = PasteUpload::PasteTypes.at(pasteType);
|
||||
QString baseUrl = customBaseURL.isEmpty() ? base.defaultBase : customBaseURL;
|
||||
@ -202,3 +201,8 @@ Net::NetRequest::Ptr PasteUpload::make(const QString& log,
|
||||
up->m_sink.reset(new Sink(pasteType, baseUrl, result));
|
||||
return up;
|
||||
}
|
||||
|
||||
PasteUpload::PasteUpload(const QString& log, PasteType pasteType) : m_log(log), m_paste_type(pasteType)
|
||||
{
|
||||
anonymizeLog(m_log);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
#include <array>
|
||||
@ -93,10 +94,10 @@ class PasteUpload : public Net::NetRequest {
|
||||
ResultPtr m_result;
|
||||
QByteArray m_output;
|
||||
};
|
||||
PasteUpload(const QString& log, const PasteType pasteType) : m_log(log), m_paste_type(pasteType) {}
|
||||
PasteUpload(const QString& log, PasteType pasteType);
|
||||
virtual ~PasteUpload() = default;
|
||||
|
||||
static NetRequest::Ptr make(const QString& log, const PasteType pasteType, const QString baseURL, ResultPtr result);
|
||||
static NetRequest::Ptr make(const QString& log, PasteType pasteType, QString baseURL, ResultPtr result);
|
||||
|
||||
private:
|
||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "logs/AnonymizeLog.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "net/PasteUpload.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
@ -172,8 +173,9 @@ std::optional<QString> GuiUtil::uploadPaste(const QString& name, const QString&
|
||||
return {};
|
||||
}
|
||||
|
||||
void GuiUtil::setClipboardText(const QString& text)
|
||||
void GuiUtil::setClipboardText(QString text)
|
||||
{
|
||||
anonymizeLog(text);
|
||||
QApplication::clipboard()->setText(text);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
namespace GuiUtil {
|
||||
std::optional<QString> uploadPaste(const QString& name, const QFileInfo& filePath, QWidget* parentWidget);
|
||||
std::optional<QString> uploadPaste(const QString& name, const QString& data, QWidget* parentWidget);
|
||||
void setClipboardText(const QString& text);
|
||||
void setClipboardText(QString text);
|
||||
QStringList BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget* parentWidget);
|
||||
QString BrowseForFile(QString context, QString caption, QString filter, QString defaultPath, QWidget* parentWidget);
|
||||
} // namespace GuiUtil
|
||||
|
Loading…
x
Reference in New Issue
Block a user