
xss攻击的修复方案:
1.对输入的数据进行HTML转义,使其不会识别为可执行脚本,例如:
String result = HtmlUtils.htmlEscape(source);
2.根据白名单的标签和属性对数据进行过滤,对可执行的脚本进行清除,例如:
org.jsoup
jsoup
1.13.1
String result = Jsoup.clean(source, Whitelist.basic());
//默认的基础白名单配置
public static Whitelistbasic(){
return new Whitelist()
.addTags(
"a","b","blockquote","br","cite","code","dd","dL","dt","em",
"i","Li","oL","p","pre","q","small","span","strike","strong","sub"
"sup","U","uL")
.addAttributes(tag:"a", ...attributes:"href")
.addAttributes(tag:”bLockquote", ...attributes:"cite")
.addAttributes(tag:"q", ...attritoutes:"cite")
.addProtocols(tag:"a", attribute:"href", ...potocols:"ftp", "http", "https", "mailto")
.addProtocols(tag:"bLockquote", attribute:"cite", ...protocolo:"http", "https")
.addProtocols(tag:"cite",attribute:"cite", ...protocols:"http", "https")
.addEnforcedAttribute(tag:"a",attribute:"rel",value:"nofollow")
;
}
以上就是关于“xss攻击如何修复”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm