JSOUP is XSS prevention tool. Jsoup can detect xss script in html and url also. Now i am giving example with url. Jsoup can validate the url with the help of "isValidate()" method. "isValidate()" method return type is boolean. If return type is true that means url having xss script so we need to clean the url with the help of "clean()" method. "clean()" method will return clean url as string.
Antisamy also one of the tool to prevent xss script but, its customized one so we need to configure everything. Its not better than JSOUP
Steps to use JSOUP:
- JSOUP can handle all cheat sheet scenarios. url of cheat sheet is: "https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet"
- JSOUP has clear api. "http://jsoup.org/apidocs/"
Antisamy also one of the tool to prevent xss script but, its customized one so we need to configure everything. Its not better than JSOUP
Steps to use JSOUP:
1. Download jsoup jar file
2. Write the code like the following
package
import
java.io.UnsupportedEncodingException;
import
org.jsoup.Jsoup;
import
org.jsoup.safety.Whitelist;
public
class JsoupSolution {
*/
String input =
//String unsafe = "';alert(String.fromCharCode(88,83,83))//';alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>";
//String input = "\"behavior%3aurl(%23default%23time2)\"onbegin%3d\"alert('xss')\"";
//String input = "<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">";
//String input = "<form BACKGROUND=\"javascript:alert('XSS')\">";
//String input = "<form bgcolor=\"#000000\"";
out.println("Input : "+ input);
boolean oneMoreCheck = Jsoup.isValid(safe, Whitelist.basic());
if(oneMoreCheck){
System.
if(!check){
System.
out.println("its invalid string");
String safe = Jsoup.clean(input, Whitelist.basic());
System.
out.println("Cleaned code: "+ safe);
System.
out.println("its cleaned string by jsoup");
System.
out.println("its safe code [after clean]");
}
else{
System.
out.println("its Harmfull code");
}
}
else{
System.
out.println("its valid string");
}
}
}
}
No comments:
Post a Comment