Feature: Add allowed_hosts to plugin section of config

This commit is contained in:
Cory Sanin 2020-12-17 15:25:05 -06:00 committed by GitHub
parent 7440d7eb2b
commit 82fd8506ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

View file

@ -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.

View file

@ -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()

View file

@ -204,6 +204,7 @@ struct FontConfiguration
struct PluginConfiguration
{
bool enable_hot_reloading;
std::string allowed_hosts;
};
enum SORT

View file

@ -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(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.");
}