Created
April 12, 2024 10:16
-
-
Save mdabir1203/94cabfc32f85a6726fb236e3e5cf7d0c to your computer and use it in GitHub Desktop.
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) { } } | |
Author
mdabir1203
commented
Apr 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment