@@ -13,6 +13,20 @@ import semmle.code.java.frameworks.Hibernate
1313/** A sink for database query language injection vulnerabilities. */
1414abstract class QueryInjectionSink extends DataFlow:: Node { }
1515
16+ /**
17+ * A unit class for adding additional taint steps.
18+ *
19+ * Extend this class to add additional taint steps that should apply to the SQL
20+ * injection taint configuration.
21+ */
22+ class AdditionalQueryInjectionTaintStep extends Unit {
23+ /**
24+ * Holds if the step from `node1` to `node2` should be considered a taint
25+ * step for SQL injection taint configurations.
26+ */
27+ abstract predicate step ( DataFlow:: Node node1 , DataFlow:: Node node2 ) ;
28+ }
29+
1630/** A sink for SQL injection vulnerabilities. */
1731private class SqlInjectionSink extends QueryInjectionSink {
1832 SqlInjectionSink ( ) {
@@ -49,3 +63,30 @@ private class PersistenceQueryInjectionSink extends QueryInjectionSink {
4963 )
5064 }
5165}
66+
67+ /** A sink for MongoDB injection vulnerabilities. */
68+ private class MongoDbInjectionSink extends QueryInjectionSink {
69+ MongoDbInjectionSink ( ) {
70+ exists ( MethodAccess call |
71+ call .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "com.mongodb" , "BasicDBObject" ) and
72+ call .getMethod ( ) .hasName ( "parse" ) and
73+ this .asExpr ( ) = call .getArgument ( 0 )
74+ )
75+ or
76+ exists ( CastExpr c |
77+ c .getExpr ( ) = this .asExpr ( ) and
78+ c .getTypeExpr ( ) .getType ( ) .( RefType ) .hasQualifiedName ( "com.mongodb" , "DBObject" )
79+ )
80+ }
81+ }
82+
83+ private class MongoJsonStep extends AdditionalQueryInjectionTaintStep {
84+ override predicate step ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
85+ exists ( MethodAccess ma |
86+ ma .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "com.mongodb.util" , "JSON" ) and
87+ ma .getMethod ( ) .hasName ( "parse" ) and
88+ ma .getArgument ( 0 ) = node1 .asExpr ( ) and
89+ ma = node2 .asExpr ( )
90+ )
91+ }
92+ }
0 commit comments