Merge commit from fork

This commit is contained in:
Claire
2026-05-20 14:38:24 +02:00
committed by GitHub
parent ec2a99341c
commit 0786c1e57a
3 changed files with 17 additions and 0 deletions

View File

@@ -3,6 +3,8 @@
module JsonLdHelper
include ContextHelper
UNSUPPORTED_JSONLD_KEYWORDS = %w(@graph @included @reverse).freeze
def equals_or_includes?(haystack, needle)
haystack.is_a?(Array) ? haystack.include?(needle) : haystack == needle
end
@@ -110,6 +112,16 @@ module JsonLdHelper
compacted
end
def unsupported_jsonld_features?(json)
if json.is_a?(Hash)
json.any? { |key, value| UNSUPPORTED_JSONLD_KEYWORDS.include?(key) || unsupported_jsonld_features?(value) }
elsif json.is_a?(Array)
json.any? { |value| unsupported_jsonld_features?(value) }
else
false
end
end
# Patches a JSON-LD document to avoid compatibility issues on redistribution
#
# Since compacting a JSON-LD document against Mastodon's built-in vocabulary

View File

@@ -12,6 +12,7 @@ class ActivityPub::LinkedDataSignature
def verify_actor!
return unless @json['signature'].is_a?(Hash)
return if unsupported_jsonld_features?(@json)
type = @json['signature']['type']
creator_uri = @json['signature']['creator']

View File

@@ -13,6 +13,10 @@ class ActivityPub::ProcessCollectionService < BaseService
begin
@json = compact(@json) if @json['signature'].is_a?(Hash)
if unsupported_jsonld_features?(@json)
Rails.logger.debug { "JSON-LD document for #{value_or_id(@json['actor'])} contains unsupported JSON-LD features" }
@json = original_json.without('signature')
end
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')