-
Notifications
You must be signed in to change notification settings - Fork 125
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
[Safe I/O] Only allow creating files with whitelisted filetypes #682
base: main
Are you sure you want to change the base?
Changes from 2 commits
7a5253b
0ff334c
59d19a8
d679e05
f492899
314b86a
04b7527
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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!"); | ||
spdlog::error("No file extension specified"); | ||
} | ||
|
||
// TODO: move into list of global consts? | ||
std::set<std::string> whitelist = {".txt", ".json"}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for this being a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly arbitrary choice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then it should probably be a vector. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can probably also be made There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @barnabwhy done via 314b86a @catornot going back to this, wouldn't a set make more sense as soon as the list of extensions gets quite long? Like rn it's only 2 cause that's the two most important plaintext filetypes I could think of but the idea is that the list would get extended quite a bit later down the line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how many filetypes will you need? |
||
|
||
// Check if file extension is whitelisted | ||
std::string extension = file.extension().string(); | ||
if (whitelist.find(extension) == whitelist.end()) | ||
{ | ||
spdlog::error("SAVE FAILED!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should maybe make it more clear that it's an issue with a mod so users don't freak out. |
||
spdlog::error("Disallowed file extension: {}", extension); | ||
} | ||
|
||
try | ||
{ | ||
mutex.get().lock(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment