Skip to content

Node.js based forum software built for the modern web

fix: do not federate crossposts to private targets

Sebastian Albrecht3a6b81fbdc47
diff --git a/src/activitypub/out.js b/src/activitypub/out.js
index 2872686cbb..e39ebdded5 100644
--- a/src/activitypub/out.js
+++ b/src/activitypub/out.js
@@ -334,8 +334,11 @@ Out.announce.topic = enabledCheck(async (tid, uid, overrideCid) => {
return;
}
- const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);
- if (!allowed) {
+ const [sourceAllowed, targetAllowed] = await Promise.all([
+ privileges.posts.can('topics:read', pid, activitypub._constants.uid),
+ overrideCid ? privileges.categories.can('topics:read', overrideCid, activitypub._constants.uid) : true,
+ ]);
+ if (!sourceAllowed || !targetAllowed) {
activitypub.helpers.log(`[activitypub/api] Not federating announce of pid ${pid} to the fediverse due to privileges.`);
return;
}
@@ -617,4 +620,4 @@ Out.undo.announce = enabledCheck(async (type, id, tid) => {
object: pid,
},
});
-});
\ No newline at end of file
+});
diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.js
index 88e0a92b34..671de65fa0 100644
--- a/src/controllers/write/topics.js
+++ b/src/controllers/write/topics.js
@@ -229,7 +229,7 @@ Topics.getCrossposts = async (req, res) => {
Topics.crosspost = async (req, res) => {
const { cid } = req.body;
const crossposts = await topics.crossposts.add(req.params.tid, cid, req.uid);
- await activitypub.out.announce.topic(req.params.tid, req.uid);
+ await activitypub.out.announce.topic(req.params.tid, req.uid, cid);
helpers.formatApiResponse(200, res, { crossposts });
};
diff --git a/test/topics/crossposts.js b/test/topics/crossposts.js
index d7a17a02cf..12eba228ac 100644
--- a/test/topics/crossposts.js
+++ b/test/topics/crossposts.js
@@ -635,6 +635,24 @@ describe('Crossposting (& related logic)', () => {
assert(actual.payload.cc.includes(authorUrl));
assert(actual.targets.includes(authorUrl));
});
+
+ it('should not send an Announce when crossposted to a non-federated category', async () => {
+ const username = utils.generateUUID().slice(0, 8);
+ const crossposter = await user.create({ username, password: '123456' });
+ const login = await helpers.loginUser(username, '123456');
+ activitypub._sent.clear();
+
+ const crosspostCid = (await categories.create({ name: utils.generateUUID().slice(0, 8) })).cid;
+ await privileges.categories.rescind(['groups:topics:read'], crosspostCid, 'fediverse');
+ const result = await helpers.request('post', `/api/v3/topics/${tid}/crossposts`, {
+ jar: login.jar,
+ csrf_token: login.csrf_token,
+ body: { cid: crosspostCid },
+ });
+
+ assert.strictEqual(result.response.statusCode, 200);
+ assert.strictEqual(activitypub._sent.size, 0);
+ });
});
describe('world canonical category (cid -1)', () => {
@@ -682,4 +700,4 @@ describe('Crossposting (& related logic)', () => {
});
});
});
-});
\ No newline at end of file
+});