diff --git a/src/user/data.js b/src/user/data.js index 3ad1db6433..571482be0b 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -3,7 +3,6 @@ var async = require('async'); var validator = require('validator'); var nconf = require('nconf'); -var winston = require('winston'); var _ = require('lodash'); var db = require('../database'); @@ -85,17 +84,11 @@ module.exports = function (User) { plugins.fireHook('filter:user.whitelistFields', { uids: uids, whitelist: fieldWhitelist.slice() }, next); }, function (results, next) { - if (fields.length) { - const whitelistSet = new Set(results.whitelist); - fields = fields.filter(function (field) { - var isFieldWhitelisted = field && whitelistSet.has(field); - if (!isFieldWhitelisted) { - winston.verbose('[user/getUsersFields] ' + field + ' removed because it is not whitelisted, see `filter:user.whitelistFields`'); - } - return isFieldWhitelisted; - }); - } else { + if (!fields.length) { fields = results.whitelist; + } else { + // Never allow password retrieval via this method + fields = fields.filter(value => value !== 'password'); } db.getObjectsFields(uidsToUserKeys(uniqueUids), fields, next); diff --git a/test/user.js b/test/user.js index 857f909a5a..77fd9428a2 100644 --- a/test/user.js +++ b/test/user.js @@ -578,6 +578,14 @@ describe('User', function () { }); }); + it('should not return password even if explicitly requested', function (done) { + User.getUserFields(testUid, ['password'], function (err, payload) { + assert.ifError(err); + assert(!payload.hasOwnProperty('password')); + done(); + }); + }); + it('should return private data if field is whitelisted', function (done) { function filterMethod(data, callback) { data.whitelist.push('another_secret');