Skip to content

Commit cd4e426

Browse files
authored
Merge pull request #503 from codex-team/chore-add-safe-regex-in-search
2 parents 21a0f15 + 64dcd48 commit cd4e426

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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)