-
-
Save fmeum/974f813405e07f1fa4ff5be6fad834d7 to your computer and use it in GitHub Desktop.
A draft of a path traversal sanitizer for Jazzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PathTraversalSanitizer { | |
@MethodHook(type = HookType.AFTER, targetClassName = "java.io.File", | |
targetMethod = "<init>", targetMethodDescriptor = "(Ljava/lang/String;)") | |
public static void | |
fileConstructorHook(MethodHandle method, Object thisObject, Object[] arguments, int hookId, Object returnValue) { | |
File file = (File) thisObject; | |
String pathname = (String) arguments[0]; | |
try { | |
// Check whether the canonical path of `file` lies inside a known list of allowed paths. | |
if (!file.getCanonicalPath().startsWith("/expected/path")) { | |
// If not, throw a distinctive exception that is reported by Jazzer. | |
throw new PotentialPathTraversalException(); | |
} | |
} catch(IOException e) { | |
// ... | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment