@@ -60,9 +60,11 @@ class ThreatModelFlowSource extends DataFlow::Node {
6060}
6161
6262/** A data flow source of remote user input. */
63- abstract class RemoteFlowSource extends DataFlow :: Node {
63+ abstract class RemoteFlowSource extends SourceNode {
6464 /** Gets a string that describes the type of this remote flow source. */
6565 abstract string getSourceType ( ) ;
66+
67+ override string getThreatModel ( ) { result = "remote" }
6668}
6769
6870/**
@@ -204,14 +206,47 @@ abstract class UserInput extends DataFlow::Node { }
204206private class RemoteUserInput extends UserInput instanceof RemoteFlowSource { }
205207
206208/** 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+ }
208212
209213/**
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+ *
210220 * A node with input from the local environment, such as files, standard in,
211221 * environment variables, and main method parameters.
212222 */
213- class EnvInput extends LocalUserInput {
223+ deprecated class EnvInput extends DataFlow :: Node {
214224 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 ( ) {
215250 // Parameters to a main method.
216251 exists ( MainMethod main | this .asParameter ( ) = main .getParameter ( 0 ) )
217252 or
@@ -220,23 +255,35 @@ class EnvInput extends LocalUserInput {
220255 f .getAnAnnotation ( ) .getType ( ) .getQualifiedName ( ) = "org.kohsuke.args4j.Argument"
221256 )
222257 or
223- // Results from various specific methods.
224- this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof EnvReadMethod
225- or
226258 // Access to `System.in`.
227259 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 ( ) {
229270 // Access to files.
230271 this .asExpr ( )
231272 .( ConstructorCall )
232273 .getConstructedType ( )
233274 .hasQualifiedName ( "java.io" , "FileInputStream" )
234275 }
276+
277+ override string getThreatModel ( ) { result = "file" }
235278}
236279
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 {
239284 DatabaseInput ( ) { this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof ResultSetGetStringMethod }
285+
286+ override string getThreatModel ( ) { result = "database" }
240287}
241288
242289/** A method that reads from the environment, such as `System.getProperty` or `System.getenv`. */
0 commit comments