最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
xss攻击如何修复
时间:2026-08-21 20:13:49 编辑:袖梨 来源:一聚教程网

xss攻击的修复方案:
1.对输入的数据进行HTML转义,使其不会识别为可执行脚本,例如:
String result = HtmlUtils.htmlEscape(source);2.根据白名单的标签和属性对数据进行过滤,对可执行的脚本进行清除,例如:
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup --><dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.13.1</version></dependency>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");}
相关文章
- 涂鸦智能与万魔科技达成深度合作 联手打造更易用的智能音频产品 08-21
- 超现实照片转水彩双联画 08-21
- 小米路由器cr6608评测(小米路由器cr6608怎么样) 08-21
- 问真八字排盘免费版入口 08-21
- Linux如何清理Docker镜像 08-21
- 编程中的同步与异步:与现实世界的对比 08-21