File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 11import { getMidnightWithTimezoneOffset , getUTCMidnight } from '../utils/dates' ;
22import { groupBy } from '../utils/grouper' ;
3+ import safe from 'safe-regex' ;
34
45const Factory = require ( './modelFactory' ) ;
56const mongo = require ( '../mongo' ) ;
@@ -164,6 +165,13 @@ class EventsFactory extends Factory {
164165 throw new Error ( 'Search parameter must be a string' ) ;
165166 }
166167
168+ /**
169+ * Check if pattern is safe RegExp
170+ */
171+ if ( ! safe ( search ) ) {
172+ throw new Error ( 'Invalid regular expression pattern' ) ;
173+ }
174+
167175 const escapedSearch = search . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
168176
169177 limit = this . validateLimit ( limit ) ;
@@ -207,6 +215,12 @@ class EventsFactory extends Factory {
207215 $options : 'i' ,
208216 } ,
209217 } ,
218+ {
219+ 'event.payload.context' : {
220+ $regex : escapedSearch ,
221+ $options : 'i' ,
222+ } ,
223+ } ,
210224 ] ,
211225 }
212226 : { } ;
You can’t perform that action at this time.
0 commit comments