[backend/federation] Fix future publishedAt/updatedAt DateTime handling

This commit is contained in:
Laura Hausmann 2025-01-20 11:18:38 +01:00
parent 57645f017d
commit 77936b710d
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -964,11 +964,11 @@ public class NoteService(
return null;
}
if (note.PublishedAt is null or { Year: < 2007 } || note.PublishedAt > DateTime.Now + TimeSpan.FromMinutes(5))
if (note.PublishedAt is null or { Year: < 2007 } || note.PublishedAt > DateTime.UtcNow + TimeSpan.FromDays(3))
throw GracefulException.UnprocessableEntity("Note.PublishedAt is nonsensical");
if (note.PublishedAt > DateTime.Now)
note.PublishedAt = DateTime.Now;
if (note.PublishedAt > DateTime.UtcNow)
note.PublishedAt = DateTime.UtcNow;
if (replyUri != null)
{
@ -1087,13 +1087,13 @@ public class NoteService(
throw GracefulException.Forbidden("User is suspended");
if (dbNote.UpdatedAt != null && dbNote.UpdatedAt > updatedAt)
throw GracefulException.UnprocessableEntity("Note update is older than last known version");
if (updatedAt.Year < 2007 || updatedAt > DateTime.Now + TimeSpan.FromMinutes(5))
if (updatedAt.Year < 2007 || updatedAt > DateTime.UtcNow + TimeSpan.FromDays(3))
throw GracefulException.UnprocessableEntity("updatedAt is nonsensical");
if (actor.Host == null)
throw GracefulException.UnprocessableEntity("User.Host is null");
if (note.UpdatedAt > DateTime.Now)
note.UpdatedAt = DateTime.Now;
if (note.UpdatedAt > DateTime.UtcNow)
note.UpdatedAt = DateTime.UtcNow;
var mentionData = await ResolveNoteMentionsAsync(note);