Skip to content

Commit

Permalink
fix 'access denied' in file.remove for entry points 'export', 'config'
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Oct 21, 2024
1 parent 4084a99 commit 183b734
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/logic/scripting/lua/libs/libfile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <filesystem>
#include <string>
#include <set>

#include "coders/gzip.hpp"
#include "engine.hpp"
Expand Down Expand Up @@ -53,11 +54,15 @@ static int l_file_write(lua::State* L) {
return 1;
}

static std::set<std::string> writeable_entry_points {
"world", "export", "config"
};

static int l_file_remove(lua::State* L) {
std::string rawpath = lua::require_string(L, 1);
fs::path path = resolve_path(rawpath);
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
if (entryPoint != "world") {
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
throw std::runtime_error("access denied");
}
return lua::pushboolean(L, fs::remove(path));
Expand All @@ -67,7 +72,7 @@ static int l_file_remove_tree(lua::State* L) {
std::string rawpath = lua::require_string(L, 1);
fs::path path = resolve_path(rawpath);
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
if (entryPoint != "world") {
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
throw std::runtime_error("access denied");
}
return lua::pushinteger(L, fs::remove_all(path));
Expand Down

0 comments on commit 183b734

Please sign in to comment.