From df3e56f4223262aa9ca2a20607a973aa0013227a Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 19 Feb 2025 16:37:11 +0100 Subject: [PATCH] [backend/core] Prevent creation of pure renote replies --- .../Controllers/Mastodon/StatusController.cs | 11 +++++++++++ Iceshrimp.Backend/Core/Services/NoteService.cs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs index b00373e3..5411fb86 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs @@ -437,6 +437,17 @@ public class StatusController( }; newText = quoteUri != null ? parsed.SkipLast(1).Serialize() : parsed.Serialize(); + + if ( + newText.AsSpan().Trim().Length == 0 + && request.Cw?.AsSpan().Trim().Length is null or 0 + && request.Poll is null or { Options.Count: 0 } + && attachments?.Count is null or 0 + ) + { + quoteUri = null; + newText = null; + } } if (request is { Sensitive: true, MediaIds.Count: > 0 }) diff --git a/Iceshrimp.Backend/Core/Services/NoteService.cs b/Iceshrimp.Backend/Core/Services/NoteService.cs index 6f4f63fa..842d0df6 100644 --- a/Iceshrimp.Backend/Core/Services/NoteService.cs +++ b/Iceshrimp.Backend/Core/Services/NoteService.cs @@ -241,6 +241,18 @@ public class NoteService( var combinedAltText = data.Attachments?.Select(p => p.Comment).Where(c => c != null); policySvc.CallRewriteHooks(data, IRewritePolicy.HookLocationEnum.PostLogic); + if ( + (data.Renote != null || data.RenoteUri != null) + && (data.Reply != null || data.ReplyUri != null) + && data.ParsedText is not { Length: > 0 } + && data.Cw == null + && data.Poll == null + && data.Attachments is not { Count: > 0 } + ) + { + throw GracefulException.UnprocessableEntity("Refusing to create a pure renote reply"); + } + var noteId = IdHelpers.GenerateSnowflakeId(data.CreatedAt); var threadId = data.Reply?.ThreadId ?? noteId; @@ -754,6 +766,10 @@ public class NoteService( note.RepliesCollection = data.ASNote.Replies?.Id; policySvc.CallRewriteHooks(data, IRewritePolicy.HookLocationEnum.PostLogic); + + if (note.IsPureRenote && (note.ReplyId != null || note.ReplyUri != null)) + throw GracefulException.UnprocessableEntity("Refusing to update note to a pure renote reply"); + await db.SaveChangesAsync(); eventSvc.RaiseNoteUpdated(this, note);