@@ -60,9 +60,11 @@ class ThreatModelFlowSource extends DataFlow::Node {
60
60
}
61
61
62
62
/** A data flow source of remote user input. */
63
- abstract class RemoteFlowSource extends DataFlow :: Node {
63
+ abstract class RemoteFlowSource extends SourceNode {
64
64
/** Gets a string that describes the type of this remote flow source. */
65
65
abstract string getSourceType ( ) ;
66
+
67
+ override string getThreatModel ( ) { result = "remote" }
66
68
}
67
69
68
70
/**
@@ -204,14 +206,47 @@ abstract class UserInput extends DataFlow::Node { }
204
206
private class RemoteUserInput extends UserInput instanceof RemoteFlowSource { }
205
207
206
208
/** A node with input that may be controlled by a local user. */
207
- abstract class LocalUserInput extends UserInput { }
209
+ abstract class LocalUserInput extends UserInput , SourceNode {
210
+ override string getThreatModel ( ) { result = "local" }
211
+ }
208
212
209
213
/**
214
+ * DEPRECATED: Use the threat models feature.
215
+ * That is, use `ThreatModelFlowSource` as the class of nodes for sources
216
+ * and set up the threat model configuration to filter source nodes.
217
+ * Alternatively, use `getThreatModel` to filter nodes to create the
218
+ * class of nodes you need.
219
+ *
210
220
* A node with input from the local environment, such as files, standard in,
211
221
* environment variables, and main method parameters.
212
222
*/
213
- class EnvInput extends LocalUserInput {
223
+ deprecated class EnvInput extends DataFlow :: Node {
214
224
EnvInput ( ) {
225
+ this instanceof EnvironmentInput or
226
+ this instanceof CliInput or
227
+ this instanceof FileInput
228
+ }
229
+ }
230
+
231
+ /**
232
+ * A node with input from the local environment, such as
233
+ * environment variables.
234
+ */
235
+ private class EnvironmentInput extends LocalUserInput {
236
+ EnvironmentInput ( ) {
237
+ // Results from various specific methods.
238
+ this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof EnvReadMethod
239
+ }
240
+
241
+ override string getThreatModel ( ) { result = "environment" }
242
+ }
243
+
244
+ /**
245
+ * A node with input from the command line, such as standard in
246
+ * and main method parameters.
247
+ */
248
+ private class CliInput extends LocalUserInput {
249
+ CliInput ( ) {
215
250
// Parameters to a main method.
216
251
exists ( MainMethod main | this .asParameter ( ) = main .getParameter ( 0 ) )
217
252
or
@@ -220,23 +255,35 @@ class EnvInput extends LocalUserInput {
220
255
f .getAnAnnotation ( ) .getType ( ) .getQualifiedName ( ) = "org.kohsuke.args4j.Argument"
221
256
)
222
257
or
223
- // Results from various specific methods.
224
- this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof EnvReadMethod
225
- or
226
258
// Access to `System.in`.
227
259
exists ( Field f | this .asExpr ( ) = f .getAnAccess ( ) | f instanceof SystemIn )
228
- or
260
+ }
261
+
262
+ override string getThreatModel ( ) { result = "cli" }
263
+ }
264
+
265
+ /**
266
+ * A node with input from the local environment, such as files.
267
+ */
268
+ private class FileInput extends LocalUserInput {
269
+ FileInput ( ) {
229
270
// Access to files.
230
271
this .asExpr ( )
231
272
.( ConstructorCall )
232
273
.getConstructedType ( )
233
274
.hasQualifiedName ( "java.io" , "FileInputStream" )
234
275
}
276
+
277
+ override string getThreatModel ( ) { result = "file" }
235
278
}
236
279
237
- /** A node with input from a database. */
238
- class DatabaseInput extends LocalUserInput {
280
+ /**
281
+ * A node with input from a database.
282
+ */
283
+ private class DatabaseInput extends LocalUserInput {
239
284
DatabaseInput ( ) { this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof ResultSetGetStringMethod }
285
+
286
+ override string getThreatModel ( ) { result = "database" }
240
287
}
241
288
242
289
/** A method that reads from the environment, such as `System.getProperty` or `System.getenv`. */
0 commit comments