Spring工具包-xss

Spring工具包XSS组件,防止XSS注入风险

Posted by guanyang on 2022-06-08
Words 220 and Reading Time 1 Minutes
Viewed Times

概览

  • 针对请求对象的所有String字段自动进行trim、checkXss
  • 如果监测有xss风险,将抛出XssException,可针对此异常定制全局异常处理

使用指南

1
2
3
4
5
<dependency>
<groupId>org.gy.framework</groupId>
<artifactId>spring-base-xss</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>

配置说明

  • 应用入口类添加@EnableXss注解,启动Xss检查
  • 当前组件只针对RestController或者Controller标注的类进行xss校验
  • 请求对象需要添加@Valid或者@Validated注解才会进行校验
  • 如果某些特殊场景需要跳过Xss检查,可以在对应字段上添加如下注解
    1
    2
    3
    //check设置false,跳过xss检查,trim设置true,进行去空格处理
    @XssCheck(check = false, trim = true)
    private String name;

If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !

...

...

00:00
00:00