Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#java# 规范 配置全局反序列化白名单 增补修订建议 #18

Open
k4n5ha0 opened this issue May 24, 2021 · 0 comments
Open

#java# 规范 配置全局反序列化白名单 增补修订建议 #18

k4n5ha0 opened this issue May 24, 2021 · 0 comments

Comments

@k4n5ha0
Copy link

k4n5ha0 commented May 24, 2021

jep290安全策略:全进程反序列化原则上使用白名单优先的设计模式,只有允许的类才能被反序列化,其它一律被阻止。

// 能被反序列化的流的限制
maxdepth=value // 单次反序列化堆栈最大深度
maxrefs=value  // 单次反序列化类的内部引用的最大数目
maxbytes=value // 单次反序列化输入流的字节数上限
maxarray=value // 单次反序列化输入流中数组数上限
// 以下示例介绍了限制反序列化的类名称的配置方法

// 允许唯一类 org.example.Teacher ,输入字节数最大为100,并阻止其它一切的类
jdk.serialFilter=maxbytes=100;org.example.Teacher;!*

// 允许 org.example. 下的所有类,输入字节数最大为100,并阻止其它一切的类
jdk.serialFilter=maxbytes=100;org.example.*;!*

// 允许 org.example. 下的所有类和子类,输入字节数最大为100,并阻止其它一切的类
jdk.serialFilter=maxbytes=100;org.example.**;!*

//允许一切类
jdk.serialFilter=*;

;    作为表达式的分隔符
.*   代表当前包下的所有类
.**  代表当前包下所有类和所有子类
!   代表取反,禁止匹配符号后的表达式被反序列化
*    通配符
  1. 使用配置文件配置白名单
jdk11+:%JAVA_HOME%\conf\security\java.security
 jdk8: %JAVA_HOME%\jre\lib\security\java.security
  1. 启动参数配置白名单
java -Djdk.serialFilter=org.example.**;maxbytes=100;!*
  1. 使用代码配置白名单
Properties props = System.getProperties();
props.setProperty("jdk.serialFilter", "org.example.**;maxbytes=100;!*");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant