Package fr.pacdu.pacpackquests.util
Class PathSecurity
java.lang.Object
fr.pacdu.pacpackquests.util.PathSecurity
Utility class providing path validation, canonicalization, and security checks
against path traversal attacks and reserved filesystem names.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats an arbitrary string to be safe for filenames and filesystem paths: converts to lowercase, decomposes accents/diacritics, and removes invalid characters.static PathReturns the absolute, normalized root directory for quests.getSafeCategoryDir(String category) Returns the safe category directory Path if valid, or empty Optional if unsafe or invalid.getSafeQuestFile(String category, String questId) Returns the safe quest JSON file Path if both category and questId are valid, or empty Optional if unsafe or invalid.static booleanisPathContained(Path parent, Path child) Checks if child path is strictly inside parent path (not equal, no traversal escaping).static booleanChecks if the given identifier is safe to be used in file and directory names.
-
Method Details
-
isValidIdentifier
Checks if the given identifier is safe to be used in file and directory names. Must be 1-64 characters matching [a-z0-9_], and not a reserved Windows device name.- Parameters:
id- The identifier string to check.- Returns:
trueif valid and safe;falseotherwise.
-
getQuestsRootDir
Returns the absolute, normalized root directory for quests.- Returns:
- The canonical
Pathto the quests root directory.
-
isPathContained
Checks if child path is strictly inside parent path (not equal, no traversal escaping).- Parameters:
parent- The trusted base directory path.child- The candidate target path to verify.- Returns:
trueif child is strictly inside parent;falseotherwise.
-
getSafeCategoryDir
Returns the safe category directory Path if valid, or empty Optional if unsafe or invalid. -
getSafeQuestFile
Returns the safe quest JSON file Path if both category and questId are valid, or empty Optional if unsafe or invalid. -
formatStringToValidPath
Formats an arbitrary string to be safe for filenames and filesystem paths: converts to lowercase, decomposes accents/diacritics, and removes invalid characters.- Parameters:
str- The raw input string.- Returns:
- The sanitized, path-safe string.
-