Created
March 8, 2018 16:52
-
-
Save yehgdotnet/837c7c6d3f5da89f0fa97b7758521634 to your computer and use it in GitHub Desktop.
Loose source checking - why referer bypass occurs
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
Insecure: | |
public class LooseSourceCheck { | |
public static void showExample(String url){ | |
try{ | |
if(url.startsWith("http://trustedsubdomain")){ | |
System.out.print(String.format("Trusted subdomain: ", url)); | |
} | |
else { | |
throw new IOException("Untrusted subdomain: " + url); | |
} | |
} | |
catch(Exception ex){ | |
} | |
} | |
} | |
Secure: | |
public class StrictSourceCheck { | |
public static void showExample(){ | |
try{ | |
String[] approved_hosts = { | |
"trust1.yehg.net", | |
"trust2.yehg.net", | |
"trust3.yehg.net", | |
"trust4.yehg.net" | |
}; | |
String url = "http://trust1.attacker.net/hack.jpg"; | |
URL netUrl = new URL(url); | |
String host = netUrl.getHost(); | |
Boolean b = Arrays.asList( approved_hosts ).contains(host); | |
if(!b){ | |
System.out.println("Untrusted domain: " + url); | |
}else{ | |
System.out.println("Trusted domain: " + url ); | |
} | |
} | |
catch(Exception ex){ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment