Skip to content
Permalink
Browse files Browse the repository at this point in the history
Protect a few more settings from being set from mods
Of those settings main_menu_script has concrete security impact, the rest are added out of abundance of caution.
  • Loading branch information
sfan5 committed May 29, 2022
1 parent bccaf5f commit da71e86
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/script/lua_api/l_settings.cpp
Expand Up @@ -27,9 +27,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"


/* This protects:
* 'secure.*' settings from being set
* some mapgen settings from being set
/* This protects the following from being set:
* 'secure.*' settings
* some security-relevant settings
* (better solution pending)
* some mapgen settings
* (not security-criticial, just to avoid messing up user configs)
*/
#define CHECK_SETTING_SECURITY(L, name) \
Expand All @@ -41,7 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
static inline int checkSettingSecurity(lua_State* L, const std::string &name)
{
if (ScriptApiSecurity::isSecure(L) && name.compare(0, 7, "secure.") == 0)
throw LuaError("Attempt to set secure setting.");
throw LuaError("Attempted to set secure setting.");

bool is_mainmenu = false;
#ifndef SERVER
Expand All @@ -54,6 +56,17 @@ static inline int checkSettingSecurity(lua_State* L, const std::string &name)
return -1;
}

const char *disallowed[] = {
"main_menu_script", "shader_path", "texture_path", "screenshot_path",
"serverlist_file", "serverlist_url", "map-dir", "contentdb_url",
};
if (!is_mainmenu) {
for (const char *name2 : disallowed) {
if (name == name2)
throw LuaError("Attempted to set disallowed setting.");
}
}

return 0;
}

Expand Down

0 comments on commit da71e86

Please sign in to comment.