Node.js based forum software built for the modern web
fix: match registration queue entries against unnormalised IPs (#14837)
palmoni5b8d9cf9d1ee0
diff --git a/src/user/approval.js b/src/user/approval.jsindex c677ab9b87..61d18fcb4b 100644--- a/src/user/approval.js+++ b/src/user/approval.js@@ -171,10 +171,9 @@ module.exports = function (User) {return user;});await Promise.all(users.map(async (user) => {+ await getIPMatchedUsers(user);// temporary: see http://www.stopforumspam.com/forum/viewtopic.php?id=6392- // need to keep this for getIPMatchedUsersuser.ip = user.ip.replace('::ffff:', '');- await getIPMatchedUsers(user);user.customActions = user.customActions || [];/*// then spam prevention plugins, using the "filter:user.getRegistrationQueue" hook can be like:@@ -192,7 +191,11 @@ module.exports = function (User) {};async function getIPMatchedUsers(user) {- const uids = await User.getUidsFromSet(`ip:${user.ip}:uid`, 0, -1);+ const ips = user.ip.startsWith('::ffff:') ? [user.ip, user.ip.slice('::ffff:'.length)] : [user.ip];+ const uidSets = await Promise.all(+ ips.map(ip => User.getUidsFromSet(`ip:${ip}:uid`, 0, -1))+ );+ const uids = Array.from(new Set(uidSets.flat()));user.ipMatch = await User.getUsersFields(uids, ['uid', 'username', 'picture']);}diff --git a/test/user.js b/test/user.jsindex 4bf6c733c3..931494b022 100644--- a/test/user.js+++ b/test/user.js@@ -2049,6 +2049,23 @@ describe('User', () => {const users = await db.getSortedSetRange('registration:queue', 0, -1);assert.equal(users[0], 'invalidname');});++ it('should match queued users against IPv4-mapped IPv6 addresses', async () => {+ const matchUid = await User.create({ username: 'ipmatchtarget' });+ await User.logIP(matchUid, '::ffff:10.0.0.7');+ await User.addToApprovalQueue({+ username: 'ipmatchqueued',+ email: '[email protected]',+ password: '123456',+ ip: '::ffff:10.0.0.7',+ });++ const users = await User.getRegistrationQueue(0, -1);+ const queued = users.find(u => u.username === 'ipmatchqueued');+ assert(queued);+ assert.equal(queued.ip, '10.0.0.7');+ assert(queued.ipMatch.map(u => u.uid).includes(matchUid));+ });});describe('invites', () => {