@@ -2,6 +2,11 @@ import semmle.code.java.frameworks.Kryo
22import semmle.code.java.frameworks.XStream
33import semmle.code.java.frameworks.SnakeYaml
44import semmle.code.java.frameworks.FastJson
5+ import semmle.code.java.frameworks.JYaml
6+ import semmle.code.java.frameworks.JsonIo
7+ import semmle.code.java.frameworks.YamlBeans
8+ import semmle.code.java.frameworks.Hessian
9+ import semmle.code.java.frameworks.Castor
510import semmle.code.java.frameworks.apache.Lang
611
712class ObjectInputStreamReadObjectMethod extends Method {
@@ -50,6 +55,29 @@ class SafeKryo extends DataFlow2::Configuration {
5055 }
5156}
5257
58+ class SafeJsonIo extends DataFlow2:: Configuration {
59+ SafeJsonIo ( ) { this = "UnsafeDeserialization::SafeJsonIo" }
60+
61+ override predicate isSource ( DataFlow:: Node src ) {
62+ exists ( MethodAccess ma |
63+ ma instanceof JsonIoSafeOptionalArgs and
64+ src .asExpr ( ) = ma .getQualifier ( )
65+ )
66+ }
67+
68+ override predicate isSink ( DataFlow:: Node sink ) {
69+ exists ( MethodAccess ma |
70+ ma .getMethod ( ) instanceof JsonIoJsonToJavaMethod and
71+ sink .asExpr ( ) = ma .getArgument ( 1 )
72+ )
73+ or
74+ exists ( ClassInstanceExpr cie |
75+ cie .getConstructor ( ) .getDeclaringType ( ) instanceof JsonReader and
76+ sink .asExpr ( ) = cie .getArgument ( 1 )
77+ )
78+ }
79+ }
80+
5381predicate unsafeDeserialization ( MethodAccess ma , Expr sink ) {
5482 exists ( Method m | m = ma .getMethod ( ) |
5583 m instanceof ObjectInputStreamReadObjectMethod and
@@ -81,6 +109,27 @@ predicate unsafeDeserialization(MethodAccess ma, Expr sink) {
81109 ma .getMethod ( ) instanceof FastJsonParseMethod and
82110 not fastJsonLooksSafe ( ) and
83111 sink = ma .getArgument ( 0 )
112+ or
113+ ma .getMethod ( ) instanceof JYamlUnSafeLoadMethod and
114+ sink = ma .getArgument ( 0 )
115+ or
116+ ma .getMethod ( ) instanceof JYamlConfigUnSafeLoadMethod and
117+ sink = ma .getArgument ( 0 )
118+ or
119+ ma .getMethod ( ) instanceof JsonIoJsonToJavaMethod and
120+ sink = ma .getArgument ( 0 ) and
121+ not exists ( SafeJsonIo sji | sji .hasFlowToExpr ( ma .getArgument ( 1 ) ) )
122+ or
123+ ma .getMethod ( ) instanceof JsonIoReadObjectMethod and
124+ sink = ma .getQualifier ( )
125+ or
126+ ma .getMethod ( ) instanceof YamlReaderReadMethod and sink = ma .getQualifier ( )
127+ or
128+ ma .getMethod ( ) instanceof UnSafeHessianInputReadObjectMethod and sink = ma .getQualifier ( )
129+ or
130+ ma .getMethod ( ) instanceof UnmarshalMethod and sink = ma .getAnArgument ( )
131+ or
132+ ma .getMethod ( ) instanceof BurlapInputReadObjectMethod and sink = ma .getQualifier ( )
84133 )
85134}
86135
0 commit comments