Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mods(Safe I/O): Only allow creating files with whitelisted filetypes #682

Merged
merged 11 commits into from
Nov 22, 2024
18 changes: 18 additions & 0 deletions primedev/mods/modsavefiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ template <ScriptContext context> void SaveFileManager::SaveFileAsync(fs::path fi
std::thread writeThread(
[mutex, file, contents]()
{
// Check if has extension and return early if not
if (!file.has_extension())
{
spdlog::error("SAVE FAILED!");
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
spdlog::error("No file extension specified");
}

// TODO: move into list of global consts?
std::set<std::string> whitelist = {".txt", ".json"};
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved

// Check if file extension is whitelisted
std::string extension = file.extension().string();
if (whitelist.find(extension) == whitelist.end())
{
spdlog::error("SAVE FAILED!");
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
spdlog::error("Disallowed file extension: {}", extension);
}

try
{
mutex.get().lock();
Expand Down
Loading