diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 57b6606162..e798d581e8 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -8,6 +8,7 @@ - Feature: [#13495] [Plugin] Add properties for park value, guests and company value. - Feature: [#13509] [Plugin] Add ability to format strings using OpenRCT2 string framework. - Feature: [#13512] [Plugin] Add item separators to list view. +- Feature: Add allowed_hosts to plugin section of config - Change: [#13346] Change FootpathScenery to FootpathAddition in all occurrences. - Fix: [#12895] Mechanics are called to repair rides that have already been fixed. - Fix: [#13257] Rides that are exactly the minimum objective length are not counted. diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 551ca9b009..66f1105ae0 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -537,6 +537,7 @@ namespace Config { auto model = &gConfigPlugin; model->enable_hot_reloading = reader->GetBoolean("enable_hot_reloading", false); + model->allowed_hosts = reader->GetString("allowed_hosts", ""); } } @@ -545,6 +546,7 @@ namespace Config auto model = &gConfigPlugin; writer->WriteSection("plugin"); writer->WriteBoolean("enable_hot_reloading", model->enable_hot_reloading); + writer->WriteString("allowed_hosts", model->allowed_hosts); } static bool SetDefaults() diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 060c212dc7..9e523d6225 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -204,6 +204,7 @@ struct FontConfiguration struct PluginConfiguration { bool enable_hot_reloading; + std::string allowed_hosts; }; enum SORT diff --git a/src/openrct2/scripting/ScSocket.hpp b/src/openrct2/scripting/ScSocket.hpp index 4c173bf5d0..323c145678 100644 --- a/src/openrct2/scripting/ScSocket.hpp +++ b/src/openrct2/scripting/ScSocket.hpp @@ -83,6 +83,22 @@ namespace OpenRCT2::Scripting return s == "localhost" || s == "127.0.0.1" || s == "::"; } + static bool IsOnWhiteList(std::string_view host) + { + constexpr char delimiter = ','; + size_t start_pos = 0; + size_t end_pos = 0; + while ((end_pos = gConfigPlugin.allowed_hosts.find(delimiter, start_pos)) != std::string::npos) + { + if (host == gConfigPlugin.allowed_hosts.substr(start_pos, end_pos - start_pos)) + { + return true; + } + start_pos = end_pos + 1; + } + return host == gConfigPlugin.allowed_hosts.substr(start_pos, gConfigPlugin.allowed_hosts.length() - start_pos); + } + public: ScSocketBase(const std::shared_ptr& plugin) : _plugin(plugin) @@ -166,7 +182,7 @@ namespace OpenRCT2::Scripting { duk_error(ctx, DUK_ERR_ERROR, "Socket is already connecting."); } - else if (!IsLocalhostAddress(host)) + else if (!IsLocalhostAddress(host) && !IsOnWhiteList(host)) { duk_error(ctx, DUK_ERR_ERROR, "For security reasons, only connecting to localhost is allowed."); }