From 08ced32e4d26509bc6a4756645f1d89eb522c7d8 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 16 Apr 2024 18:15:05 +0200 Subject: [PATCH] [backend/federation] Enforce VerifiedFetch in ResolveNoteAsync instead of in calling methods (ISH-262) --- .../Core/Federation/ActivityPub/ActivityHandlerService.cs | 2 +- Iceshrimp.Backend/Core/Services/NoteService.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs index 0bef0d3f..73ce3574 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs @@ -264,7 +264,7 @@ public class ActivityHandlerService( if (announce.Object is not ASNote note) throw GracefulException.UnprocessableEntity("Invalid or unsupported announce object"); - var dbNote = await noteSvc.ResolveNoteAsync(note.Id, note.VerifiedFetch ? note : null); + var dbNote = await noteSvc.ResolveNoteAsync(note.Id, note); await noteSvc.CreateNoteAsync(resolvedActor, announce.GetVisibility(activity.Actor), renote: dbNote); return; } diff --git a/Iceshrimp.Backend/Core/Services/NoteService.cs b/Iceshrimp.Backend/Core/Services/NoteService.cs index f9d0c874..1f3b994f 100644 --- a/Iceshrimp.Backend/Core/Services/NoteService.cs +++ b/Iceshrimp.Backend/Core/Services/NoteService.cs @@ -1027,6 +1027,9 @@ public class NoteService( if (note != null) return note; + if (!fetchedNote?.VerifiedFetch ?? false) + fetchedNote = null; + fetchedNote ??= user != null ? await fetchSvc.FetchNoteAsync(uri, user) : await fetchSvc.FetchNoteAsync(uri); if (fetchedNote == null) @@ -1303,7 +1306,7 @@ public class NoteService( public async Task ReactToNoteAsync(ASNote note, User actor, string name) { - var dbNote = await ResolveNoteAsync(note.Id, note.VerifiedFetch ? note : null); + var dbNote = await ResolveNoteAsync(note.Id, note); if (dbNote == null) throw GracefulException.UnprocessableEntity("Failed to resolve reaction target"); @@ -1347,7 +1350,7 @@ public class NoteService( public async Task RemoveReactionFromNoteAsync(ASNote note, User actor, string name) { - var dbNote = await ResolveNoteAsync(note.Id, note.VerifiedFetch ? note : null); + var dbNote = await ResolveNoteAsync(note.Id, note); if (dbNote == null) return; await RemoveReactionFromNoteAsync(dbNote, actor, name); }