From e35f3eef56f4779ba56170652472f835aedc5fd2 Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 06:13:55 -0500 Subject: [PATCH 1/3] Semi-Kill #9531 --- packages/backend/src/remote/activitypub/models/note.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index afb3af6cb..e5f3853bd 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -115,6 +115,16 @@ export async function createNote( logger.info(`Creating the Note: ${note.id}`); + // Skip if note is made before 2007 (1yr before Fedi was created) + if (note.published) { + const DateChecker = new Date(note.published) + if (DateChecker.getFullYear() < 2007) { + logger.warn('Note somehow made before Activitypub was created; discarding'); + return null; + } + } + + // Fetch author const actor = (await resolvePerson( getOneApId(note.attributedTo), From f9fc1d7137ac1258fc730df5049eaf9da07911cb Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 06:26:05 -0500 Subject: [PATCH 2/3] Discard if 3 days in the future --- packages/backend/src/remote/activitypub/models/note.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index e5f3853bd..ee9ccf52a 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -116,12 +116,19 @@ export async function createNote( logger.info(`Creating the Note: ${note.id}`); // Skip if note is made before 2007 (1yr before Fedi was created) + // OR skip if note is made 3 days in advance if (note.published) { const DateChecker = new Date(note.published) + const FutureCheck = new Date() + FutureCheck.setDate(FutureCheck.getDate() + 3) // Allow some wiggle room for misconfigured hosts if (DateChecker.getFullYear() < 2007) { logger.warn('Note somehow made before Activitypub was created; discarding'); return null; } + if (DateChecker < FutureCheck) { + logger.warn('Note somehow made after today; discarding') + return null; + } } From cd6a1d09f5e807ed319046d81bb7edc53f53fa11 Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 07:18:56 -0500 Subject: [PATCH 3/3] Fix bad math --- packages/backend/src/remote/activitypub/models/note.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 3c438aa2f..e643e24c9 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -135,7 +135,7 @@ export async function createNote( logger.warn('Note somehow made before Activitypub was created; discarding'); return null; } - if (DateChecker < FutureCheck) { + if (DateChecker > FutureCheck) { logger.warn('Note somehow made after today; discarding') return null; }