Package io.karatelabs.http
Class PathSecurity
java.lang.Object
io.karatelabs.http.PathSecurity
Provides protection against path traversal attacks in resource resolution.
Path traversal attacks attempt to access files outside the intended directory
by using sequences like ../ or encoded variants like %2e%2e/.
This class validates paths before they are used for resource resolution, rejecting any path that contains traversal sequences.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when a path traversal attempt is detected. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
PathSecurity
public PathSecurity()
-
-
Method Details
-
isSafe
Check if a path is safe (does not contain traversal sequences).This method checks for:
..- Direct parent directory reference- URL-encoded variants (
%2e,%2E) - Double-encoded variants
- Backslash variants (Windows-style)
- Parameters:
path- the path to validate- Returns:
- true if the path is safe, false if it contains traversal sequences
-
validate
Validate a path and throw an exception if unsafe.- Parameters:
path- the path to validate- Throws:
PathSecurity.PathTraversalException- if the path contains traversal sequences
-