Skip to content

Node.js based forum software built for the modern web

fix: add priv check to loading profile pictures

Barış Soner Uşaklı707bfe03c118
diff --git a/src/privileges/users.js b/src/privileges/users.js
index 0ae46fcbd5..e2f82dedcf 100644
--- a/src/privileges/users.js
+++ b/src/privileges/users.js
@@ -74,7 +74,9 @@ async function filterIsModerator(cid, uid, isModerator) {
}
privsUsers.canEdit = async function (callerUid, uid) {
- if (parseInt(callerUid, 10) === parseInt(uid, 10)) {
+ callerUid = String(callerUid);
+ uid = String(uid);
+ if (callerUid === uid) {
return true;
}
diff --git a/src/socket.io/user/picture.js b/src/socket.io/user/picture.js
index a6e23b98a7..8ac35ba0b9 100644
--- a/src/socket.io/user/picture.js
+++ b/src/socket.io/user/picture.js
@@ -5,6 +5,7 @@ const nconf = require('nconf');
const db = require('../../database');
const user = require('../../user');
const plugins = require('../../plugins');
+const privileges = require('../../privileges');
module.exports = function (SocketUser) {
SocketUser.removeUploadedPicture = async function (socket, data) {
@@ -26,6 +27,10 @@ module.exports = function (SocketUser) {
throw new Error('[[error:invalid-data]]');
}
+ if (!socket.uid || !await privileges.users.canEdit(socket.uid, data.uid)) {
+ throw new Error('[[error:no-privileges]]');
+ }
+
const [list, userObj, userPictures] = await Promise.all([
plugins.hooks.fire('filter:user.listPictures', {
uid: data.uid,
diff --git a/test/user.js b/test/user.js
index 618a57b469..2f649faa4a 100644
--- a/test/user.js
+++ b/test/user.js
@@ -1195,6 +1195,19 @@ describe('User', () => {
});
});
+ it('should fail to get profile pictures of another user without privileges', async () => {
+ const anotherUid = await User.create({ username: 'anotheruser', password: '123456' });
+ await assert.rejects(
+ socketUser.getProfilePictures({ uid: uid }, { uid: anotherUid }),
+ { message: '[[error:no-privileges]]' }
+ );
+
+ await assert.rejects(
+ socketUser.getProfilePictures({ uid: 0 }, { uid: anotherUid }),
+ { message: '[[error:no-privileges]]' }
+ );
+ });
+
it('should get default profile avatar', (done) => {
assert.strictEqual(User.getDefaultAvatar(), '');
meta.config.defaultAvatar = 'https://path/to/default/avatar';