@@ -59,7 +59,7 @@ module UnsafeDeserialization {
59
59
* User input to object method call deserialization flow tracking.
60
60
*/
61
61
class TaintToObjectMethodTrackingConfig extends TaintTracking:: Configuration {
62
- TaintToObjectMethodTrackingConfig ( ) { this = "UnsafeDeserialization1 " }
62
+ TaintToObjectMethodTrackingConfig ( ) { this = "TaintToObjectMethodTrackingConfig " }
63
63
64
64
override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
65
65
@@ -68,11 +68,81 @@ module UnsafeDeserialization {
68
68
override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
69
69
}
70
70
71
+ /**
72
+ * User input to `JsonConvert` call deserialization flow tracking.
73
+ */
74
+ class JsonConvertTrackingConfig extends TaintTracking:: Configuration {
75
+ JsonConvertTrackingConfig ( ) { this = "JsonConvertTrackingConfig" }
76
+
77
+ override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
78
+
79
+ override predicate isSink ( DataFlow:: Node sink ) {
80
+ sink instanceof NewtonsoftJsonConvertDeserializeObjectMethodSink
81
+ }
82
+
83
+ override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
84
+ }
85
+
86
+ /**
87
+ * Tracks unsafe `TypeNameHandling` setting to `JsonConvert` call
88
+ */
89
+ class TypeNameTrackingConfig extends DataFlow:: Configuration {
90
+ TypeNameTrackingConfig ( ) { this = "TypeNameTrackingConfig" }
91
+
92
+ override predicate isSource ( DataFlow:: Node source ) {
93
+ (
94
+ source .asExpr ( ) instanceof MemberConstantAccess and
95
+ source .getType ( ) instanceof TypeNameHandlingEnum
96
+ or
97
+ source .asExpr ( ) instanceof IntegerLiteral
98
+ ) and
99
+ source .asExpr ( ) .hasValue ( ) and
100
+ not source .asExpr ( ) .getValue ( ) = "0"
101
+ }
102
+
103
+ override predicate isSink ( DataFlow:: Node sink ) {
104
+ exists ( MethodCall mc , Method m , Expr expr |
105
+ m = mc .getTarget ( ) and
106
+ (
107
+ not mc .getArgument ( 0 ) .hasValue ( ) and
108
+ m instanceof NewtonsoftJsonConvertClassDeserializeObjectMethod
109
+ ) and
110
+ expr = mc .getAnArgument ( ) and
111
+ sink .asExpr ( ) = expr and
112
+ expr .getType ( ) instanceof JsonSerializerSettingsClass
113
+ )
114
+ }
115
+
116
+ override predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
117
+ node1 .asExpr ( ) instanceof IntegerLiteral and
118
+ node2 .asExpr ( ) .( CastExpr ) .getExpr ( ) = node1 .asExpr ( )
119
+ or
120
+ node1 .getType ( ) instanceof TypeNameHandlingEnum and
121
+ exists ( PropertyWrite pw , Property p , Assignment a |
122
+ a .getLValue ( ) = pw and
123
+ pw .getProperty ( ) = p and
124
+ p .getDeclaringType ( ) instanceof JsonSerializerSettingsClass and
125
+ p .hasName ( "TypeNameHandling" ) and
126
+ (
127
+ node1 .asExpr ( ) = a .getRValue ( ) and
128
+ node2 .asExpr ( ) = pw .getQualifier ( )
129
+ or
130
+ exists ( ObjectInitializer oi |
131
+ node1 .asExpr ( ) = oi .getAMemberInitializer ( ) .getRValue ( ) and
132
+ node2 .asExpr ( ) = oi
133
+ )
134
+ )
135
+ )
136
+ }
137
+ }
138
+
71
139
/**
72
140
* User input to static method or constructor call deserialization flow tracking.
73
141
*/
74
142
class TaintToConstructorOrStaticMethodTrackingConfig extends TaintTracking:: Configuration {
75
- TaintToConstructorOrStaticMethodTrackingConfig ( ) { this = "UnsafeDeserialization2" }
143
+ TaintToConstructorOrStaticMethodTrackingConfig ( ) {
144
+ this = "TaintToConstructorOrStaticMethodTrackingConfig"
145
+ }
76
146
77
147
override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
78
148
@@ -826,4 +896,18 @@ module UnsafeDeserialization {
826
896
)
827
897
}
828
898
}
899
+
900
+ /** Newtonsoft.Json.JsonConvert */
901
+ private class NewtonsoftJsonConvertDeserializeObjectMethodSink extends ConstructorOrStaticMethodSink {
902
+ NewtonsoftJsonConvertDeserializeObjectMethodSink ( ) {
903
+ exists ( MethodCall mc , Method m |
904
+ m = mc .getTarget ( ) and
905
+ (
906
+ not mc .getArgument ( 0 ) .hasValue ( ) and
907
+ m instanceof NewtonsoftJsonConvertClassDeserializeObjectMethod
908
+ ) and
909
+ this .asExpr ( ) = mc .getArgument ( 0 )
910
+ )
911
+ }
912
+ }
829
913
}
0 commit comments