Skip to content

Node.js based forum software built for the modern web

fix(socket.io): add topics:read privilege check to loadPostTools

Julian Lam060fb12876f7
diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js
index 99a09580bd..e51494f7fa 100644
--- a/src/socket.io/posts/tools.js
+++ b/src/socket.io/posts/tools.js
@@ -19,6 +19,9 @@ module.exports = function (SocketPosts) {
throw new Error('[[error:invalid-data]]');
}
const cid = await posts.getCidByPid(data.pid);
+ if (!await privileges.posts.can('topics:read', data.pid, socket.uid)) {
+ throw new Error('[[error:no-privileges]]');
+ }
const results = await utils.promiseParallel({
posts: posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid', 'ip', 'flagId', 'url']),
isAdmin: user.isAdministrator(socket.uid),
diff --git a/test/posts.js b/test/posts.js
index dcf2430364..bd0a68343a 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -300,6 +300,14 @@ describe('Post\'s', () => {
done();
});
});
+
+ it('should not allow guests to load post tools without topics:read privilege', async () => {
+ await privileges.categories.rescind(['groups:topics:read'], cid, 'guests');
+ await assert.rejects(socketPosts.loadPostTools({ uid: 0 }, { pid: postData.pid }), {
+ message: '[[error:no-privileges]]',
+ });
+ await privileges.categories.give(['groups:topics:read'], cid, 'guests');
+ });
});
describe('delete/restore/purge', () => {