@@ -75,9 +75,11 @@ class JsonConvertTrackingConfig extends TaintTracking::Configuration {
75
75
}
76
76
77
77
/**
78
+ * DEPRECATED: Use `TypeNameTracking` instead.
79
+ *
78
80
* Tracks unsafe `TypeNameHandling` setting to `JsonConvert` call
79
81
*/
80
- class TypeNameTrackingConfig extends DataFlow:: Configuration {
82
+ deprecated class TypeNameTrackingConfig extends DataFlow:: Configuration {
81
83
TypeNameTrackingConfig ( ) { this = "TypeNameTrackingConfig" }
82
84
83
85
override predicate isSource ( DataFlow:: Node source ) {
@@ -127,6 +129,62 @@ class TypeNameTrackingConfig extends DataFlow::Configuration {
127
129
}
128
130
}
129
131
132
+ /**
133
+ * Configuration module for tracking unsafe `TypeNameHandling` setting to `JsonConvert` calls.
134
+ */
135
+ private module TypeNameTrackingConfig implements DataFlow:: ConfigSig {
136
+ predicate isSource ( DataFlow:: Node source ) {
137
+ (
138
+ source .asExpr ( ) instanceof MemberConstantAccess and
139
+ source .getType ( ) instanceof TypeNameHandlingEnum
140
+ or
141
+ source .asExpr ( ) instanceof IntegerLiteral
142
+ ) and
143
+ source .asExpr ( ) .hasValue ( ) and
144
+ not source .asExpr ( ) .getValue ( ) = "0"
145
+ }
146
+
147
+ predicate isSink ( DataFlow:: Node sink ) {
148
+ exists ( MethodCall mc , Method m , Expr expr |
149
+ m = mc .getTarget ( ) and
150
+ (
151
+ not mc .getArgument ( 0 ) .hasValue ( ) and
152
+ m instanceof NewtonsoftJsonConvertClassDeserializeObjectMethod
153
+ ) and
154
+ expr = mc .getAnArgument ( ) and
155
+ sink .asExpr ( ) = expr and
156
+ expr .getType ( ) instanceof JsonSerializerSettingsClass
157
+ )
158
+ }
159
+
160
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
161
+ node1 .asExpr ( ) instanceof IntegerLiteral and
162
+ node2 .asExpr ( ) .( CastExpr ) .getExpr ( ) = node1 .asExpr ( )
163
+ or
164
+ node1 .getType ( ) instanceof TypeNameHandlingEnum and
165
+ exists ( PropertyWrite pw , Property p , Assignment a |
166
+ a .getLValue ( ) = pw and
167
+ pw .getProperty ( ) = p and
168
+ p .getDeclaringType ( ) instanceof JsonSerializerSettingsClass and
169
+ p .hasName ( "TypeNameHandling" ) and
170
+ (
171
+ node1 .asExpr ( ) = a .getRValue ( ) and
172
+ node2 .asExpr ( ) = pw .getQualifier ( )
173
+ or
174
+ exists ( ObjectInitializer oi |
175
+ node1 .asExpr ( ) = oi .getAMemberInitializer ( ) .getRValue ( ) and
176
+ node2 .asExpr ( ) = oi
177
+ )
178
+ )
179
+ )
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Configuration module for tracking unsafe `TypeNameHandling` setting to `JsonConvert` calls.
185
+ */
186
+ module TypeNameTracking = DataFlow:: Global< TypeNameTrackingConfig > ;
187
+
130
188
/**
131
189
* User input to static method or constructor call deserialization flow tracking.
132
190
*/
0 commit comments