Skip to content

Commit 3399b04

Browse files
authored
Merge pull request #504 from codex-team/master
Update prod
2 parents 182aa62 + cd4e426 commit 3399b04

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/models/eventsFactory.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getMidnightWithTimezoneOffset, getUTCMidnight } from '../utils/dates';
22
import { groupBy } from '../utils/grouper';
3+
import safe from 'safe-regex';
34

45
const Factory = require('./modelFactory');
56
const 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
: {};

0 commit comments

Comments
 (0)