From 885b83e50999adeefc5fbfa0bf418ac6231707c5 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 7 Mar 2025 15:26:00 -0500 Subject: [PATCH] feat: if an incoming remote message is too long, don't create the room, but notify the local recipients instead closes #13174 --- public/language/en-GB/error.json | 1 + src/activitypub/notes.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.json index d511ef8300..3880a36d47 100644 --- a/public/language/en-GB/error.json +++ b/public/language/en-GB/error.json @@ -194,6 +194,7 @@ "cant-add-users-to-chat-room": "Can't add users to chat room.", "cant-remove-users-from-chat-room": "Can't remove users from chat room.", "chat-room-name-too-long": "Chat room name too long. Names can't be longer than %1 characters.", + "remote-chat-received-too-long": "You received a chat message from %1, but it was too long and was rejected.", "already-voting-for-this-post": "You have already voted for this post.", "reputation-system-disabled": "Reputation system is disabled.", diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 920fe69205..52c22c34e8 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -9,6 +9,7 @@ const meta = require('../meta'); const privileges = require('../privileges'); const categories = require('../categories'); const messaging = require('../messaging'); +const notifications = require('../notifications'); const user = require('../user'); const topics = require('../topics'); const posts = require('../posts'); @@ -288,6 +289,20 @@ Notes.assertPrivate = async (object) => { const payload = await activitypub.mocks.message(object); + try { + await messaging.checkContent(payload.content, false); + } catch (e) { + const { displayname, userslug } = await user.getUserFields(payload.uid, ['displayname', 'userslug']); + const notification = await notifications.create({ + bodyShort: `[[error:remote-chat-received-too-long, ${displayname}]]`, + path: `/user/${userslug}`, + nid: `error:chat:uid:${payload.uid}`, + from: payload.uid, + }); + notifications.push(notification, Array.from(recipients).filter(uid => utils.isNumber(uid))); + return null; + } + if (!roomId) { roomId = await messaging.newRoom(payload.uid, { uids: [...recipients] }); }