SpringBoot配置XSS过滤器
SpringBoot基于mica-xss配置XSS过滤器
3. SpringBoot集成mica-xss
3.1
maven依赖
<!--XSS 安全过滤--> <dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-core</artifactId> <version>2.5.0.1</version> </dependency> <dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-xss</artifactId> <version>2.5.0.1</version> </dependency>
有个别人说
<!-- 这个不需要引入,因为mica-xss引入过了。但是搜索到的其他教程文章内会引入 -->
<dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-xss</artifactId> <version>2.5.0.1</version> </dependency>
3.2代码添加注解
注解:可以使用 @XssCleanIgnore 注解对方法和类级别进行忽略。
自定义:MyXssCleaner implements XssCleaner 重写 clean 方法,然后自定义的过滤注册为 bean
3.3配置项
配置 配置项 默认值 说明 mica.xss.enabled true 开启xss mica.xss.trim-text true 【全局】是否去除文本首尾空格 mica.xss.mode clear 模式:clear 清理(默认),escape 转义 mica.xss.pretty-print false clear 专用 prettyPrint,默认关闭: 保留换行 mica.xss.enable-escape false clear 专用 转义,默认关闭 mica.xss.path-patterns /** 拦截的路由,例如: /api/order/** mica.xss.path-exclude-patterns 放行的路由,默认为空
https://www.dreamlu.net/components/mica-xss.html
嗨,朋友既然来了何不关注一下!
春有百花秋有月,夏有凉风冬有雪!