esapl入门及预防xss,sql注入漏洞
1.esapl解決过滤特殊字符,以及sql盲注问题(现阶段已知,不足之处请多指教)
针对web+spring+hibernate 老项目: 有maven仓库的可以参考这个: 配置文件:(放在工程目录下,放在本地虽然可以运行,但不可以部署项目,识别不到说明位置不对,重新放配置文件位置) ESAPI.properties; validation.properties; 例如: 个人方案:当时尝试把esapl文件夹去掉,直接找配置文件就可以找到! .jar包放到lib下: esapi-2.1.0.jar esapi.tld(本项目放在了lib外面);
使用: (1.)针对xss漏洞(过滤特殊字符原理) //对用户输入“input”进行HTML编码,防止XSS input = ESAPI.encoder().encodeForHTML(input); //根据自己不同的需要可以选用以下方法 //input = ESAPI.encoder().encodeForHTMLAttribute(input); //input = ESAPI.encoder().encodeForJavaScript(input); //input = ESAPI.encoder().encodeForCSS(input); //input = ESAPI.encoder().encodeForURL(input); (2.)针对sql注入漏洞(除了支持mysql还支持oracle) //解决注入问题(mysql的没有试过) String input1="用户输入1"; String input2="用户输入2"; mysql: input1 = ESAPI.encoder().encodeForSQL(new MySQLCodec(MySQLCodec.Mode.STANDARD),input1); input2 = ESAPI.encoder().encodeForSQL(new MySQLCodec(MySQLCodec.Mode.STANDARD),input2); Oracle: Codec ORACLE_CODEC = new OracleCodec(); input1 = ESAPI.encoder().encodeForSQL(ORACLE_CODEC,input1); String sqlStr="select name from tableA where id="+input1 +"and date_created =" + input2+""