mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[Client] Warn when data paths point inside the program directory (#7473)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
f83a61979f
commit
57a6a0d9cb
10 changed files with 247 additions and 1 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "libcockatrice/settings/settings_manager.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class QObject;
|
||||
|
|
@ -121,3 +123,52 @@ void PathsSettings::setSpoilerDatabasePath(const QString &_spoilerDatabasePath)
|
|||
setValue(_spoilerDatabasePath, "spoilerDatabase");
|
||||
emit cardDatabasePathChanged();
|
||||
}
|
||||
|
||||
QStringList PathsSettings::pathsInsideDir(const QString &baseDir) const
|
||||
{
|
||||
QStringList offenders;
|
||||
const auto check = [&offenders, &baseDir](const QString &path) {
|
||||
if (!path.isEmpty() && isInsideDir(path, baseDir)) {
|
||||
offenders.append(QDir::cleanPath(path));
|
||||
}
|
||||
};
|
||||
|
||||
check(getDeckPath());
|
||||
check(getFiltersPath());
|
||||
check(getReplaysPath());
|
||||
check(getPicsPath());
|
||||
check(getCustomPicsPath());
|
||||
check(getThemesPath());
|
||||
check(getCardDatabasePath());
|
||||
check(getCustomCardDatabasePath());
|
||||
check(getTokenDatabasePath());
|
||||
check(getSpoilerCardDatabasePath());
|
||||
check(getRedirectCachePath());
|
||||
|
||||
offenders.removeDuplicates();
|
||||
return offenders;
|
||||
}
|
||||
|
||||
bool PathsSettings::isInsideDir(const QString &path, const QString &baseDir)
|
||||
{
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||
// Windows and default macOS volumes are case-insensitive filesystems.
|
||||
constexpr Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
|
||||
#else
|
||||
constexpr Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
|
||||
#endif
|
||||
const QString base = QDir::cleanPath(baseDir);
|
||||
const QString cleaned = QDir::cleanPath(path);
|
||||
const QString prefix = base.endsWith(QLatin1Char('/')) ? base : base + QLatin1Char('/');
|
||||
return cleaned == base || cleaned.startsWith(prefix, caseSensitivity);
|
||||
}
|
||||
|
||||
bool PathsSettings::getAppDirWarningAcknowledged() const
|
||||
{
|
||||
return getValue("appDirWarningAcknowledged").toBool();
|
||||
}
|
||||
|
||||
void PathsSettings::setAppDirWarningAcknowledged(bool _appDirWarningAcknowledged)
|
||||
{
|
||||
setValue(_appDirWarningAcknowledged, "appDirWarningAcknowledged");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue