Skip to content

Commit 48b7b8e

Browse files
committed
Merge branch 'chore-add-safe-regex-in-search' into stage
2 parents d9cac56 + 64dcd48 commit 48b7b8e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/models/eventsFactory.js

Lines changed: 8 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);

0 commit comments

Comments
 (0)