Browse Source

Fix `Update` importing old previously-unknown activities and treating them as recent ones (#36848)

pull/1371/head
Claire 5 months ago committed by Misty De Meo
parent
commit
5b4362de4d
No known key found for this signature in database
GPG Key ID: 76CF846A2F674B2C
  1. 12
      app/lib/activitypub/activity/update.rb
  2. 6
      spec/lib/activitypub/activity_spec.rb

12
app/lib/activitypub/activity/update.rb

@ -1,6 +1,9 @@
# frozen_string_literal: true
class ActivityPub::Activity::Update < ActivityPub::Activity
# Updates to unknown objects older than that are ignored
OBJECT_AGE_THRESHOLD = 1.day
def perform
@account.schedule_refresh_if_stale!
@ -26,6 +29,9 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
@status = Status.find_by(uri: object_uri, account_id: @account.id)
# Ignore updates for old unknown objects, since those are updates we are not interested in
return if @status.nil? && object_too_old?
# We may be getting `Create` and `Update` out of order
@status ||= ActivityPub::Activity::Create.new(@json, @account, **@options).perform
@ -33,4 +39,10 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
end
def object_too_old?
@object['published'].present? && @object['published'].to_datetime < OBJECT_AGE_THRESHOLD.ago
rescue Date::Error
false
end
end

6
spec/lib/activitypub/activity_spec.rb

@ -34,6 +34,8 @@ RSpec.describe ActivityPub::Activity do
}
end
let(:publication_date) { 1.hour.ago.utc }
let(:create_json) do
{
'@context': [
@ -52,7 +54,7 @@ RSpec.describe ActivityPub::Activity do
'https://www.w3.org/ns/activitystreams#Public',
],
content: 'foo',
published: '2025-05-24T11:03:10Z',
published: publication_date.iso8601,
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
},
}.deep_stringify_keys
@ -77,7 +79,7 @@ RSpec.describe ActivityPub::Activity do
'https://www.w3.org/ns/activitystreams#Public',
],
content: 'foo',
published: '2025-05-24T11:03:10Z',
published: publication_date.iso8601,
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
quoteAuthorization: approval_uri,
},

Loading…
Cancel
Save