Node.js based forum software built for the modern web
fix(topics): add source category privilege check to crossposts and fix system uid
Julian Lam7e6e9b949a1e
diff --git a/src/posts/queue.js b/src/posts/queue.jsindex 585a9d09d7..0817f024e1 100644--- a/src/posts/queue.js+++ b/src/posts/queue.js@@ -421,7 +421,7 @@ module.exports = function (Posts) {}async function createCrosspost(data) {- await topics.crossposts.add(data.tid, data.crosspostCid, 'system');+ await topics.crossposts.add(data.tid, data.crosspostCid, 0);return { tid: data.tid };}diff --git a/src/topics/crossposts.js b/src/topics/crossposts.jsindex 238a8947a6..600e26239a 100644--- a/src/topics/crossposts.js+++ b/src/topics/crossposts.js@@ -59,14 +59,15 @@ Crossposts.add = async function (tid, cid, uid) {if (!utils.isNumber(cid)) {await activitypub.actors.assert(cid);}- const [exists, allowed] = await Promise.all([+ const [exists, destAllowed, sourceAllowed] = await Promise.all([categories.exists(cid),uid === 0 || privileges.categories.can('topics:crosspost', cid, uid),+ uid === 0 || privileges.topics.can('topics:read', tid, uid),]);if (!exists) {throw new Error('[[error:invalid-cid]]');}- if (!allowed) {+ if (!destAllowed || !sourceAllowed) {throw new Error('[[error:not-allowed]]');}if (uid < 0) {diff --git a/test/topics/crossposts.js b/test/topics/crossposts.jsindex b340200380..3454060437 100644--- a/test/topics/crossposts.js+++ b/test/topics/crossposts.js@@ -100,6 +100,15 @@ describe('Crossposting (& related logic)', () => {await privileges.categories.give(['groups:topics:crosspost'], cid2, 'registered-users');});+ it('should not allow a crosspost if user lacks topics:read on source category', async () => {+ await privileges.categories.rescind(['groups:topics:read'], cid1, 'registered-users');+ await assert.rejects(+ topics.crossposts.add(tid, cid2, uid),+ { message: '[[error:not-allowed]]' }+ );+ await privileges.categories.give(['groups:topics:read'], cid1, 'registered-users');+ });+it('should successfully crosspost to another cid', async () => {const crossposts = await topics.crossposts.add(tid, cid2, uid);