<dependency>
<groupId>commons-iogroupId>
<artifactId>commons-ioartifactId>
<version>2.4version>
dependency>
File file = new File(logpath);
FileInputStream logfile = new FileInputStream(file);
import org.apache.commons.io.FileUtils;
File file = FileUtils.getFile(logpath);
FileInputStream logfile = FileUtils.openInputStream(file);
@InitBinder 只对当前Controller生效,因此可以创建BaseController,其他Controller直接继承该类import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RestController;
/**
* 奇安信 Controller.
* @author lw-rxz
*/
@RestController
public class BaseController {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setDisallowedFields("test");
}
}
@RequestBody传参, @InitBinder 是无效的,因此通过@JsonIgnoreProperties(ignoreUnknown = true)解决

pom.xml:引入jasypt
<dependency>
<groupId>com.github.ulisesbocchiogroupId>
<artifactId>jasypt-spring-boot-starterartifactId>
<version>2.0.0version>
dependency>

BasicTextEncryptor对应jar包org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar
生成密钥,替换配置文件
import org.jasypt.util.text.BasicTextEncryptor;
/**
* 生成密文.
* @author lw-rxz
*/
public class JasyptUtils {
public static void main(String[] args) {
//PBEWithMD5AndDES
BasicTextEncryptor encryptor = new BasicTextEncryptor();
//加密
encryptor.setPassword("key");
System.out.println(encryptor.encrypt("%8Y!R-PHSA1LJ9_z"));
//解密
System.out.println(encryptor.decrypt("gZdoGpddkg8dCtdlYmjlAulXUo+Cqr6/LgxcUgfmVOE="));
}
}
jasypt:
encryptor:
password: key
也可以自定义的密码串标识,默认为:ENC(…)
property:
prefix: "xx@["
suffix: "]"

jasypt一开始引入的2.1.1版本,结构导致校验包javax.validation失效,换成2.0.0即可
<dependency>
<groupId>javax.validationgroupId>
<artifactId>validation-apiartifactId>
<version>2.0.1.Finalversion>
dependency>
jasypt:
encryptor:
password: key #依然报明文缺陷
替换为环境变量或者作为命令行传入:

官网
--jasypt.encryptor.password=key
-Djasypt.encryptor.password=password
主要为了防止空指针,实际上都没有问题,比如baseMapper.selectList(null);但还会提示缺陷,这种可以通过创建常量null
public static Object NULL = null;
baseMapper.selectList((XXX)NULL );//需要转换一下,比如(Test)NULL
还有一种就是创建空对象,不要使用null
QueryWrapper queryMapper = null;
if (name!= null) {
queryMapper = new QueryWrapper<>();
queryMapper.eq("name", name);
}
baseMapper.selectList(queryMapper)
替换为:
QueryWrapper queryMapper = new QueryWrapper<>();
if (name!= null) {
queryMapper.eq("name", name);
}
baseMapper.selectList(queryMapper)
除了明文处理,其他几种缺陷感觉非常多此一举,仅仅就是为了不被扫描到缺陷,所以上面很多改动的意义也仅仅是为了通过扫描。
20230912------------又开始了,发现一份官方文档,可以参考下:
奇安信漏洞说明
