Skip to content

Node.js based forum software built for the modern web

fix(activitypub): handle sourceContent for queued AP posts

Julian Lam9e6831fc0be8
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index e806443f37..828bd74a20 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -266,6 +266,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
if (mainResult.severity === 3) {
activitypub.helpers.log(`[activitypub/notes.assert] Queuing main post (${mainPid}) due to blocklist severity 3`);
+ if (utils.isNumber(mainPid) || (await posts.exists([mainPid]))[0]) {
+ activitypub.helpers.log(`[activitypub/notes.assert] Rejecting to-be-queued main post (${mainPid}): pid is local or already exists`);
+ return null;
+ }
+
await posts.addToQueue({
uid: authorId,
cid: options.cid || cid,
@@ -277,6 +282,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
generatedTitle,
_activitypub: mainPost._activitypub,
});
+
// Drop the rest of the chain — replies without OP don't make sense
return { tid: null, queued: 1 };
}
@@ -343,6 +349,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
if (postResult.severity === 3) {
activitypub.helpers.log(`[activitypub/notes.assert] Queuing reply (${post.pid}) due to blocklist severity 3`);
+ if (utils.isNumber(post.pid) || await posts.exists(post.pid)) {
+ activitypub.helpers.log(`[activitypub/notes.assert] Rejecting to-be-queued reply (${post.pid}): pid or tid is local or already exists`);
+ return;
+ }
+
await posts.addToQueue({
uid: post.uid,
tid,
diff --git a/src/posts/queue.js b/src/posts/queue.js
index b4459b9f6e..106b7cddc7 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -46,6 +46,7 @@ module.exports = function (Posts) {
postData.user.displayname = postData.user.username;
postData.user.fullname = postData.user.username;
}
+ postData.data.content = postData.data.sourceContent || postData.data.content;
postData.data.rawContent = validator.escape(String(postData.data.content));
postData.data.title = validator.escape(String(postData.data.title || ''));
}
@@ -219,7 +220,7 @@ module.exports = function (Posts) {
'[[notifications:post-awaiting-review]]' :
'[[notifications:topic-awaiting-review]]',
bodyLong: type === 'reply' ?
- await plugins.hooks.fire('filter:parse.raw', data.content) :
+ await plugins.hooks.fire('filter:parse.raw', data.sourceContent || data.content) :
validator.escape(String(data.title)),
bodyEmail: bodyEmail,
path: `/post-queue/${id}`,
@@ -237,7 +238,7 @@ module.exports = function (Posts) {
async function parseBodyEmail(cid, type, data) {
const url = nconf.get('url');
const [content, category, userData] = await Promise.all([
- plugins.hooks.fire('filter:parse.raw', data.content),
+ plugins.hooks.fire('filter:parse.raw', data.sourceContent || data.content),
categories.getCategoryFields(cid, ['name', 'slug']),
user.getUserFields(data.uid, ['uid', 'username']),
]);