diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2024-11-22 15:20:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-22 15:20:03 +0100 |
commit | db40260d57a9480b82d850c093aeaf14eefda9fd (patch) | |
tree | b7c06811421bcfd93246cc5b5288bb07f2406daf /primedev/mods | |
parent | 6585d629ca60e2ce457750f12d40dd9cf742ff8c (diff) | |
download | NorthstarLauncher-db40260d57a9480b82d850c093aeaf14eefda9fd.tar.gz NorthstarLauncher-db40260d57a9480b82d850c093aeaf14eefda9fd.zip |
mods(Safe I/O): Only allow creating files with whitelisted filetypes (#682)
Restricts file types that can be created via Safe I/O to a list of whitelisted file types
Diffstat (limited to 'primedev/mods')
-rw-r--r-- | primedev/mods/modsavefiles.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/primedev/mods/modsavefiles.cpp b/primedev/mods/modsavefiles.cpp index 13239c99..d73b867c 100644 --- a/primedev/mods/modsavefiles.cpp +++ b/primedev/mods/modsavefiles.cpp @@ -74,6 +74,26 @@ 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("A mod failed to save a file via Safe I/O due to the following error:"); + spdlog::error("No file extension specified"); + return; + } + + // If there's a file extension missing here that you need, feel free to make a PR adding it + static const std::set<std::string> whitelist = {".txt", ".json"}; + + // Check if file extension is whitelisted + std::string extension = file.extension().string(); + if (whitelist.find(extension) == whitelist.end()) + { + spdlog::error("A mod failed to save a file via Safe I/O due to the following error:"); + spdlog::error("Disallowed file extension: {}", extension); + return; + } + try { mutex.get().lock(); |