@@ -4,6 +4,22 @@ import java
44import semmle.code.java.dataflow.FlowSources
55import semmle.code.java.security.QueryInjection
66
7+ /** A sink for MongoDB injection vulnerabilities. */
8+ class MongoDbInjectionSink extends QueryInjectionSink {
9+ MongoDbInjectionSink ( ) {
10+ exists ( MethodAccess call |
11+ call .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "com.mongodb" , "BasicDBObject" ) and
12+ call .getMethod ( ) .hasName ( "parse" ) and
13+ this .asExpr ( ) = call .getArgument ( 0 )
14+ )
15+ or
16+ exists ( CastExpr c |
17+ c .getExpr ( ) = this .asExpr ( ) and
18+ c .getTypeExpr ( ) .getType ( ) .( RefType ) .hasQualifiedName ( "com.mongodb" , "DBObject" )
19+ )
20+ }
21+ }
22+
723private class QueryInjectionFlowConfig extends TaintTracking:: Configuration {
824 QueryInjectionFlowConfig ( ) { this = "SqlInjectionLib::QueryInjectionFlowConfig" }
925
@@ -16,6 +32,10 @@ private class QueryInjectionFlowConfig extends TaintTracking::Configuration {
1632 node .getType ( ) instanceof BoxedType or
1733 node .getType ( ) instanceof NumberType
1834 }
35+
36+ override predicate isAdditionalTaintStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
37+ mongoJsonStep ( node1 , node2 )
38+ }
1939}
2040
2141/**
@@ -27,3 +47,12 @@ predicate queryTaintedBy(
2747) {
2848 exists ( QueryInjectionFlowConfig conf | conf .hasFlowPath ( source , sink ) and sink .getNode ( ) = query )
2949}
50+
51+ predicate mongoJsonStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
52+ exists ( MethodAccess ma |
53+ ma .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "com.mongodb.util" , "JSON" ) and
54+ ma .getMethod ( ) .hasName ( "parse" ) and
55+ ma .getArgument ( 0 ) = node1 .asExpr ( ) and
56+ ma = node2 .asExpr ( )
57+ )
58+ }
0 commit comments