[backend/federation] Enforce VerifiedFetch in ResolveNoteAsync instead of in calling methods (ISH-262)

This commit is contained in:
Laura Hausmann 2024-04-16 18:15:05 +02:00
parent 469f02c5ac
commit 08ced32e4d
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 6 additions and 3 deletions

View file

@ -264,7 +264,7 @@ public class ActivityHandlerService(
if (announce.Object is not ASNote note) if (announce.Object is not ASNote note)
throw GracefulException.UnprocessableEntity("Invalid or unsupported announce object"); 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); await noteSvc.CreateNoteAsync(resolvedActor, announce.GetVisibility(activity.Actor), renote: dbNote);
return; return;
} }

View file

@ -1027,6 +1027,9 @@ public class NoteService(
if (note != null) return note; if (note != null) return note;
if (!fetchedNote?.VerifiedFetch ?? false)
fetchedNote = null;
fetchedNote ??= user != null ? await fetchSvc.FetchNoteAsync(uri, user) : await fetchSvc.FetchNoteAsync(uri); fetchedNote ??= user != null ? await fetchSvc.FetchNoteAsync(uri, user) : await fetchSvc.FetchNoteAsync(uri);
if (fetchedNote == null) if (fetchedNote == null)
@ -1303,7 +1306,7 @@ public class NoteService(
public async Task ReactToNoteAsync(ASNote note, User actor, string name) 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) if (dbNote == null)
throw GracefulException.UnprocessableEntity("Failed to resolve reaction target"); 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) 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; if (dbNote == null) return;
await RemoveReactionFromNoteAsync(dbNote, actor, name); await RemoveReactionFromNoteAsync(dbNote, actor, name);
} }