-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[ENHANCEMENT] FileUtil additions + sandboxing #3032
base: develop
Are you sure you want to change the base?
Conversation
Wouldn't this theoretically allow mods to do malicious things? Unless somehow directories that are not Funkin's are restricted. |
mods can already do that with the functions already in var root:String = "./";
while (FileUtil.doesFileExist(root)) {root += "../";}
FileUtil.writeStringToPath(root.substring(0, root.length - 6) + "some important path here", "", FileWriteMode.Force); though sandboxing to only the game root directory is definitely needed i think thats an issue for another pr |
Fair enough! Sandboxing would be very nice. |
itd be an easy addition like using this in all the functions that have a path input /**
* Prevent paths from exiting the root.
*
* @param path The path to sanitize.
* @return The sanitized path.
*/
public static function sanitizePath(path:String):String
{
path = path.trim().replace('\\', '/');
if (path.contains(':'))
{
path = path.substring(path.lastIndexOf(':') + 1);
}
while (path.charAt(0) == '/')
{
path = path.substring(1);
}
var parts:Array<String> = path.split('/');
var sanitized:Array<String> = [];
for (part in parts)
{
switch (part)
{
case '.':
case '':
continue;
case '..':
if (sanitized.length > 0) sanitized.pop();
default:
sanitized.push(part);
}
}
return sanitized.join('/');
} however the problem is that theres a few places internally where they use the functions to do stuff outside of the root folder (unit tests/polymod asset redirect/etc) |
Shouldn't it be better to extend FileUtilBase and override all functions including those that cause trouble or am i dumb ? |
wait nvm static doesnt have inheritance pr is fine so far |
Pretty interesting! Of note, you could change the names so that the one that gets used by the core game is still |
Briefly describe the issue(s) fixed.
im currently working on a mod launcher/manager/updater mod, and require certain file manipulation functions that are blacklisted and also not currently present in
FileUtil
, so this pr aims to expandFileUtil
functionality by adding the following:this pr also sandboxes all the functions!! the core functionality is now housed in
FileUtilBase
(used only internally, blacklisted in scripts), whichFileUtil
uses, sanitizing the paths first and preventing them from leaving the game folderfunctions that have the capability to modify/delete are prevented from messing with
assets
,manifest
and everything in it,plugins
and everything in it, and the dlls and game executableall functions above have been tested; if anyone finds any faults, please make them known