@@ -10,8 +10,8 @@ const agent = require('../../../plugins/agent')
1010
1111describe ( 'nosql injection detection in mongodb - whole feature' , ( ) => {
1212 // https://github.com/fiznool/express-mongo-sanitize/issues/200
13- withVersions ( 'mongodb ' , 'express' , '>4.18.0 <5.0.0' , expressVersion => {
14- withVersions ( 'mongodb ' , 'mongodb' , mongodbVersion => {
13+ withVersions ( 'express-mongo-sanitize ' , 'express' , '>4.18.0 <5.0.0' , expressVersion => {
14+ withVersions ( 'express-mongo-sanitize ' , 'mongodb' , mongodbVersion => {
1515 const mongodb = require ( `../../../../../../versions/mongodb@${ mongodbVersion } ` )
1616
1717 const satisfiesNodeVersionForMongo3and4 =
@@ -82,6 +82,94 @@ describe('nosql injection detection in mongodb - whole feature', () => {
8282 }
8383 } )
8484
85+ testThatRequestHasVulnerability ( {
86+ testDescription : 'should have NOSQL_MONGODB_INJECTION vulnerability in $or clause' ,
87+ fn : async ( req , res ) => {
88+ await collection . find ( {
89+ key : {
90+ $or : [ req . query . key , 'test' ]
91+ }
92+ } )
93+ res . end ( )
94+ } ,
95+ vulnerability : 'NOSQL_MONGODB_INJECTION' ,
96+ makeRequest : ( done , config ) => {
97+ axios . get ( `http://localhost:${ config . port } /?key=value` ) . catch ( done )
98+ } ,
99+ cb : function ( vulnerabilities ) {
100+ const vulnerability = vulnerabilities [ 0 ]
101+ let someRedacted = false
102+ vulnerability . evidence . valueParts . forEach ( valuePart => {
103+ if ( valuePart . redacted ) {
104+ someRedacted = true
105+ }
106+ } )
107+
108+ expect ( someRedacted ) . to . be . true
109+ }
110+ } )
111+
112+ testThatRequestHasNoVulnerability ( {
113+ testDescription : 'should not have NOSQL_MONGODB_INJECTION vulnerability using $eq' ,
114+ fn : async ( req , res ) => {
115+ await collection . find ( {
116+ key : {
117+ $eq : req . query . key
118+ }
119+ } )
120+ res . end ( )
121+ } ,
122+ vulnerability : 'NOSQL_MONGODB_INJECTION' ,
123+ makeRequest : ( done , config ) => {
124+ axios . get ( `http://localhost:${ config . port } /?key=value` ) . catch ( done )
125+ }
126+ } )
127+
128+ testThatRequestHasNoVulnerability ( {
129+ testDescription : 'should not have NOSQL_MONGODB_INJECTION vulnerability with modified tainted string' ,
130+ fn : async ( req , res ) => {
131+ const data = req . query . key
132+ // eslint-disable-next-line no-undef
133+ const modifiedData = _ddiast . plusOperator ( 'modified' + data , 'modified' , data )
134+
135+ await collection . find ( {
136+ key : modifiedData
137+ } )
138+
139+ res . end ( )
140+ } ,
141+ vulnerability : 'NOSQL_MONGODB_INJECTION' ,
142+ makeRequest : ( done , config ) => {
143+ axios . get ( `http://localhost:${ config . port } /?key=value` ) . catch ( done )
144+ }
145+ } )
146+
147+ testThatRequestHasNoVulnerability ( {
148+ testDescription : 'should not have NOSQL_MONGODB_INJECTION vulnerability in too deep property' ,
149+ fn : async ( req , res ) => {
150+ const deep = 11
151+ const obj = { }
152+ let next = obj
153+
154+ for ( let i = 0 ; i <= deep ; i ++ ) {
155+ if ( i === deep ) {
156+ next . key = req . query . key
157+ break
158+ }
159+
160+ next . key = { }
161+ next = next . key
162+ }
163+
164+ await collection . find ( obj )
165+ res . end ( )
166+ } ,
167+ vulnerability : 'NOSQL_MONGODB_INJECTION' ,
168+ makeRequest : ( done , config ) => {
169+ axios . get ( `http://localhost:${ config . port } /?key=value` ) . catch ( done )
170+ }
171+ } )
172+
85173 testThatRequestHasNoVulnerability ( {
86174 testDescription : 'should not have NOSQL_MONGODB_INJECTION vulnerability with path params' ,
87175 fn : function noop ( ) { } ,
0 commit comments