Skip to content

Commit

Permalink
Added sanitization function before using RegEx
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrea committed Jan 8, 2024
1 parent 48288c4 commit bd61419
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/controllers/v4/images/waifu.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import createError from 'http-errors';
import Waifus from '../../../models/schemas/Waifu.js';
import Stats from '../../../models/schemas/Stat.js';
Expand Down Expand Up @@ -37,11 +38,13 @@ const getWaifu = async (req, res, next) => {
*/

if (name) {
filter['names.en'] = { $regex: new RegExp(name, 'i') }; // Case-insensitive regex match for English name
const sanitizedName = _.escapeRegExp(name.trim());
filter['names.en'] = { $regex: new RegExp(sanitizedName, 'i') }; // Case-insensitive regex match for English name
}

if (anime) {
filter['from.name'] = { $regex: new RegExp(anime, 'i') }; // Case-insensitive regex match for anime name
const sanitizedAnime = _.escapeRegExp(anime.trim());
filter['from.name'] = { $regex: new RegExp(sanitizedAnime, 'i') }; // Case-insensitive regex match for anime name
}

/**
Expand Down

0 comments on commit bd61419

Please sign in to comment.