Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/models/eventsFactory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getMidnightWithTimezoneOffset, getUTCMidnight } from '../utils/dates';
import { groupBy } from '../utils/grouper';
import safe from 'safe-regex';

const Factory = require('./modelFactory');
const mongo = require('../mongo');
Expand Down Expand Up @@ -164,6 +165,13 @@ class EventsFactory extends Factory {
throw new Error('Search parameter must be a string');
}

/**
* Check if pattern is safe RegExp
*/
if (!safe(search)) {
throw new Error('Invalid regular expression pattern');
}

const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

limit = this.validateLimit(limit);
Expand Down Expand Up @@ -207,6 +215,12 @@ class EventsFactory extends Factory {
$options: 'i',
},
},
{
'event.payload.context': {
$regex: escapedSearch,
$options: 'i',
},
},
],
}
: {};
Expand Down
Loading