diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-02-02 11:55:57 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-02-02 19:55:57 +0100 |
commit | 7b969436a0939f7091954fe8a6441476dded7d0e (patch) | |
tree | 092bd13c8809c74c67a5b3576fb3ae2c8539bffa /app/services/activitypub | |
parent | 63da32468cf5f5145deb51c93019009a6ef7f8db (diff) |
Fix compacted JSON-LD possibly causing compatibility issues on forwarding
Diffstat (limited to 'app/services/activitypub')
-rw-r--r-- | app/services/activitypub/process_collection_service.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index 5f3d63bb3..eb008c40a 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -5,13 +5,27 @@ class ActivityPub::ProcessCollectionService < BaseService def call(body, account, **options) @account = account - @json = Oj.load(body, mode: :strict) + @json = original_json = Oj.load(body, mode: :strict) @options = options - @json = compact(@json) if @json['signature'].is_a?(Hash) + begin + @json = compact(@json) if @json['signature'].is_a?(Hash) + rescue JSON::LD::JsonLdError => e + Rails.logger.debug "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" + @json = original_json.without('signature') + end return if !supported_context? || (different_actor? && verify_account!.nil?) || suspended_actor? || @account.local? + if @json['signature'].present? + # We have verified the signature, but in the compaction step above, might + # have introduced incompatibilities with other servers that do not + # normalize the JSON-LD documents (for instance, previous Mastodon + # versions), so skip redistribution if we can't get a safe document. + patch_for_forwarding!(original_json, @json) + @json.delete('signature') unless safe_for_forwarding?(original_json, @json) + end + case @json['type'] when 'Collection', 'CollectionPage' process_items @json['items'] |