From 6fe48e1cee4e9f2ee52d21b314e6f577b22b799d Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 11 Feb 2026 16:47:24 +0100 Subject: [PATCH] Process actor public keys when they are in a separate document without the ActivityStreams context (#37826) --- app/helpers/json_ld_helper.rb | 4 ++++ app/services/activitypub/fetch_remote_key_service.rb | 2 +- spec/services/activitypub/fetch_remote_key_service_spec.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/helpers/json_ld_helper.rb b/app/helpers/json_ld_helper.rb index 675d8b873..f33525dd7 100644 --- a/app/helpers/json_ld_helper.rb +++ b/app/helpers/json_ld_helper.rb @@ -70,6 +70,10 @@ module JsonLdHelper !json.nil? && equals_or_includes?(json['@context'], ActivityPub::TagManager::CONTEXT) end + def supported_security_context?(json) + !json.nil? && equals_or_includes?(json['@context'], 'https://w3id.org/security/v1') + end + def unsupported_uri_scheme?(uri) uri.nil? || !uri.start_with?('http://', 'https://') end diff --git a/app/services/activitypub/fetch_remote_key_service.rb b/app/services/activitypub/fetch_remote_key_service.rb index e96b5ad3b..b6d9cfa73 100644 --- a/app/services/activitypub/fetch_remote_key_service.rb +++ b/app/services/activitypub/fetch_remote_key_service.rb @@ -12,7 +12,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService @json = fetch_resource(uri, false) raise Error, "Unable to fetch key JSON at #{uri}" if @json.nil? - raise Error, "Unsupported JSON-LD context for document #{uri}" unless supported_context?(@json) + raise Error, "Unsupported JSON-LD context for document #{uri}" unless supported_context?(@json) || (supported_security_context?(@json) && @json['owner'].present? && !actor_type?) raise Error, "Unexpected object type for key #{uri}" unless expected_type? return find_actor(@json['id'], @json, suppress_errors) if actor_type? diff --git a/spec/services/activitypub/fetch_remote_key_service_spec.rb b/spec/services/activitypub/fetch_remote_key_service_spec.rb index 847a15410..ddd1a8067 100644 --- a/spec/services/activitypub/fetch_remote_key_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_key_service_spec.rb @@ -71,7 +71,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do let(:public_key_id) { 'https://example.com/alice-public-key.json' } before do - stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) end it 'returns the expected account' do