fix: dont allow searching by email/ip if not privileged

This commit is contained in:
Barış Soner Uşaklı
2020-07-04 16:43:44 -04:00
parent fef04fcf6b
commit ac6b571ed5
3 changed files with 10 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ define('forum/chats/search', ['components'], function (components) {
socket.emit('user.search', {
query: username,
searchBy: 'username',
paginate: false,
}, function (err, data) {
if (err) {
return app.alertError(err.message);

View File

@@ -30,10 +30,14 @@ usersController.index = async function (req, res, next) {
}
};
usersController.search = async function (req, res, next) {
const allowed = await privileges.global.can('search:users', req.uid);
if (!allowed) {
return next(new Error('[[error:no-privileges]]'));
usersController.search = async function (req, res) {
const [allowed, isPrivileged] = await Promise.all([
privileges.global.can('search:users', req.uid),
user.isPrivileged(req.uid),
]);
if (!allowed || ((req.query.searchBy === 'ip' || req.query.searchBy === 'email' || req.query.bannedOnly === 'true' || req.query.flaggedOnly === 'true') && !isPrivileged)) {
throw new Error('[[error:no-privileges]]');
}
const [searchData, isAdminOrGlobalMod] = await Promise.all([
user.search({

View File

@@ -14,7 +14,7 @@ module.exports = function (SocketUser) {
user.isPrivileged(socket.uid),
]);
if (!allowed || ((data.searchBy === 'ip' || data.bannedOnly || data.flaggedOnly) && !isPrivileged)) {
if (!allowed || ((data.searchBy === 'ip' || data.searchBy === 'email' || data.bannedOnly || data.flaggedOnly) && !isPrivileged)) {
throw new Error('[[error:no-privileges]]');
}
const result = await user.search({