forked from mirrors/0ad
Hide userreporter ID from mods and logfiles, since it shall be used as an authentication token for GDPR personal data requests, refs #5257, f51f78c999 / D1563.
Comments by: Vladislav in irc on 2018-08-13 This was SVN commit r21867.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -21,9 +21,26 @@
|
||||
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/Profile.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
// These entries will not be readable nor writable for JS, so that malicious mods can't leak personal or sensitive data
|
||||
static const std::unordered_set<std::string> g_ProtectedConfigNames = {
|
||||
"userreport.id" // authentication token for GDPR personal data requests
|
||||
};
|
||||
|
||||
bool JSI_ConfigDB::IsProtectedConfigName(const std::string& name)
|
||||
{
|
||||
if (g_ProtectedConfigNames.find(name) != g_ProtectedConfigNames.end())
|
||||
{
|
||||
LOGERROR("Access denied (%s)", name.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::GetConfigNamespace(const std::wstring& cfgNsString, EConfigNamespace& cfgNs)
|
||||
{
|
||||
if (cfgNsString == L"default")
|
||||
@@ -64,6 +81,9 @@ bool JSI_ConfigDB::SetChanges(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), co
|
||||
|
||||
std::string JSI_ConfigDB::GetValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name)
|
||||
{
|
||||
if (IsProtectedConfigName(name))
|
||||
return "";
|
||||
|
||||
EConfigNamespace cfgNs;
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return std::string();
|
||||
@@ -75,6 +95,9 @@ std::string JSI_ConfigDB::GetValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate
|
||||
|
||||
bool JSI_ConfigDB::CreateValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name, const std::string& value)
|
||||
{
|
||||
if (IsProtectedConfigName(name))
|
||||
return false;
|
||||
|
||||
EConfigNamespace cfgNs;
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
@@ -85,6 +108,9 @@ bool JSI_ConfigDB::CreateValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), c
|
||||
|
||||
bool JSI_ConfigDB::RemoveValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name)
|
||||
{
|
||||
if (IsProtectedConfigName(name))
|
||||
return false;
|
||||
|
||||
EConfigNamespace cfgNs;
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
@@ -99,18 +125,19 @@ bool JSI_ConfigDB::WriteFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), con
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
|
||||
bool ret = g_ConfigDB.WriteFile(cfgNs, path);
|
||||
return ret;
|
||||
return g_ConfigDB.WriteFile(cfgNs, path);
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::WriteValueToFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path)
|
||||
{
|
||||
if (IsProtectedConfigName(name))
|
||||
return false;
|
||||
|
||||
EConfigNamespace cfgNs;
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
|
||||
bool ret = g_ConfigDB.WriteValueToFile(cfgNs, name, value, path);
|
||||
return ret;
|
||||
return g_ConfigDB.WriteValueToFile(cfgNs, name, value, path);
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
|
||||
@@ -119,8 +146,7 @@ bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
|
||||
bool ret = g_ConfigDB.Reload(cfgNs);
|
||||
return ret;
|
||||
return g_ConfigDB.Reload(cfgNs);
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::SetFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const Path& path)
|
||||
|
||||
Reference in New Issue
Block a user