[backend/core] Prevent creation of pure renote replies

This commit is contained in:
Laura Hausmann 2025-02-19 16:37:11 +01:00
parent 70349c25c0
commit df3e56f422
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 27 additions and 0 deletions

View file

@ -437,6 +437,17 @@ public class StatusController(
}; };
newText = quoteUri != null ? parsed.SkipLast(1).Serialize() : parsed.Serialize(); 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 }) if (request is { Sensitive: true, MediaIds.Count: > 0 })

View file

@ -241,6 +241,18 @@ public class NoteService(
var combinedAltText = data.Attachments?.Select(p => p.Comment).Where(c => c != null); var combinedAltText = data.Attachments?.Select(p => p.Comment).Where(c => c != null);
policySvc.CallRewriteHooks(data, IRewritePolicy.HookLocationEnum.PostLogic); 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 noteId = IdHelpers.GenerateSnowflakeId(data.CreatedAt);
var threadId = data.Reply?.ThreadId ?? noteId; var threadId = data.Reply?.ThreadId ?? noteId;
@ -754,6 +766,10 @@ public class NoteService(
note.RepliesCollection = data.ASNote.Replies?.Id; note.RepliesCollection = data.ASNote.Replies?.Id;
policySvc.CallRewriteHooks(data, IRewritePolicy.HookLocationEnum.PostLogic); 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(); await db.SaveChangesAsync();
eventSvc.RaiseNoteUpdated(this, note); eventSvc.RaiseNoteUpdated(this, note);