Skip to content

Node.js based forum software built for the modern web

fix(topics): require topics:read on source category for owner topic moves

Julian Lam42d6706eb375
diff --git a/src/api/topics.js b/src/api/topics.js
index a970697e83..f610149522 100644
--- a/src/api/topics.js
+++ b/src/api/topics.js
@@ -327,7 +327,11 @@ topicsAPI.move = async (caller, { tid, cid }) => {
const isModOfSourceAndDestination = isModOfDestination && isModOfTopicCid[index];
if (!isAdmin && !isModOfSourceAndDestination) {
const isOwnerOfTopic = parseInt(topicData.uid, 10) === parseInt(caller.uid, 10);
- if (!isOwnerOfTopic || !canCreateAndReadDestination || topicData.locked || topicData.deleted) {
+ const canReadSource = await privileges.topics.can('topics:read', tid, caller.uid);
+ if (
+ !isOwnerOfTopic || !canCreateAndReadDestination ||
+ !canReadSource || topicData.locked || topicData.deleted
+ ) {
throw new Error('[[error:no-privileges]]');
}
if (maxOwnerPosts > 0 && topicData.postcount > maxOwnerPosts) {
diff --git a/test/topics/tools.js b/test/topics/tools.js
index cb4ccb5ab2..981e11a62b 100644
--- a/test/topics/tools.js
+++ b/test/topics/tools.js
@@ -141,6 +141,46 @@ describe('Topic tools', () => {
{ message: '[[error:no-privileges]]' }
);
});
+
+ it('should disallow topic moving if owner lost topics:read on source category', async () => {
+ const { cid: restrictedCid } = await categories.create({ name: utils.generateUUID().slice(0, 8) });
+ const { cid: destCid } = await categories.create({ name: utils.generateUUID().slice(0, 8) });
+ const uid1 = await user.create({ username: utils.generateUUID().slice(0, 8) });
+ const { topicData } = await topics.post({
+ uid: uid1,
+ cid: restrictedCid,
+ title: utils.generateUUID(),
+ content: utils.generateUUID(),
+ });
+
+ // Owner can move before read is revoked
+ await api.topics.move({ uid: uid1 }, {
+ cid: destCid,
+ tid: topicData.tid,
+ });
+ assert.strictEqual(String(await topics.getTopicField(topicData.tid, 'cid')), String(destCid));
+
+ // Move back to restricted category
+ await api.topics.move({ uid: uid1 }, {
+ cid: restrictedCid,
+ tid: topicData.tid,
+ });
+
+ // Revoke topics:read from source category for registered-users
+ await privileges.categories.rescind(['groups:topics:read'], restrictedCid, 'registered-users');
+
+ // Owner should no longer be able to move the topic out
+ await assert.rejects(
+ api.topics.move({ uid: uid1 }, {
+ cid: destCid,
+ tid: topicData.tid,
+ }),
+ { message: '[[error:no-privileges]]' }
+ );
+
+ // Restore privilege for test isolation
+ await privileges.categories.give(['groups:topics:read'], restrictedCid, 'registered-users');
+ });
});
describe('with remote categories', () => {