Class SlotNameValidator
- Namespace
- KeenEyes.Serialization
- Assembly
- KeenEyes.Core.dll
Validates save slot names to prevent path traversal attacks.
public static class SlotNameValidator
- Inheritance
-
SlotNameValidator
- Inherited Members
Remarks
Slot names are used to construct file paths. Without validation, a malicious slot name could contain path separators or ".." sequences to write files outside the intended save directory.
This validator ensures slot names contain only safe characters and cannot be used to escape the save directory.
For cross-platform compatibility, this validator always rejects characters that are invalid on Windows, even when running on Linux/macOS. This ensures saves created on any platform can be opened on any other platform.
Methods
TryValidate(string, out string?)
Tries to validate a slot name without throwing.
public static bool TryValidate(string slotName, out string? errorMessage)
Parameters
slotNamestringThe slot name to validate.
errorMessagestringThe error message if validation fails.
Returns
- bool
True if the slot name is valid; otherwise, false.
Validate(string)
Validates a slot name and throws if it contains unsafe characters.
public static void Validate(string slotName)
Parameters
slotNamestringThe slot name to validate.
Exceptions
- ArgumentException
Thrown when the slot name contains path separators, ".." sequences, or other characters that could enable path traversal.