Merge pull request from GHSA-3fjr-858r-92rw
* Fix insufficient origin validation * Bump version to 4.3.0-alpha.1
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
class ActivityPub::FetchRemoteAccountService < ActivityPub::FetchRemoteActorService
 | 
			
		||||
  # Does a WebFinger roundtrip on each call, unless `only_key` is true
 | 
			
		||||
  def call(uri, id: true, prefetched_body: nil, break_on_redirect: false, only_key: false, suppress_errors: true, request_id: nil)
 | 
			
		||||
  def call(uri, prefetched_body: nil, break_on_redirect: false, only_key: false, suppress_errors: true, request_id: nil)
 | 
			
		||||
    actor = super
 | 
			
		||||
    return actor if actor.nil? || actor.is_a?(Account)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,15 +10,15 @@ class ActivityPub::FetchRemoteActorService < BaseService
 | 
			
		||||
  SUPPORTED_TYPES = %w(Application Group Organization Person Service).freeze
 | 
			
		||||
 | 
			
		||||
  # Does a WebFinger roundtrip on each call, unless `only_key` is true
 | 
			
		||||
  def call(uri, id: true, prefetched_body: nil, break_on_redirect: false, only_key: false, suppress_errors: true, request_id: nil)
 | 
			
		||||
  def call(uri, prefetched_body: nil, break_on_redirect: false, only_key: false, suppress_errors: true, request_id: nil)
 | 
			
		||||
    return if domain_not_allowed?(uri)
 | 
			
		||||
    return ActivityPub::TagManager.instance.uri_to_actor(uri) if ActivityPub::TagManager.instance.local_uri?(uri)
 | 
			
		||||
 | 
			
		||||
    @json = begin
 | 
			
		||||
      if prefetched_body.nil?
 | 
			
		||||
        fetch_resource(uri, id)
 | 
			
		||||
        fetch_resource(uri, true)
 | 
			
		||||
      else
 | 
			
		||||
        body_to_json(prefetched_body, compare_id: id ? uri : nil)
 | 
			
		||||
        body_to_json(prefetched_body, compare_id: uri)
 | 
			
		||||
      end
 | 
			
		||||
    rescue Oj::ParseError
 | 
			
		||||
      raise Error, "Error parsing JSON-LD document #{uri}"
 | 
			
		||||
 
 | 
			
		||||
@@ -6,23 +6,10 @@ class ActivityPub::FetchRemoteKeyService < BaseService
 | 
			
		||||
  class Error < StandardError; end
 | 
			
		||||
 | 
			
		||||
  # Returns actor that owns the key
 | 
			
		||||
  def call(uri, id: true, prefetched_body: nil, suppress_errors: true)
 | 
			
		||||
  def call(uri, suppress_errors: true)
 | 
			
		||||
    raise Error, 'No key URI given' if uri.blank?
 | 
			
		||||
 | 
			
		||||
    if prefetched_body.nil?
 | 
			
		||||
      if id
 | 
			
		||||
        @json = fetch_resource_without_id_validation(uri)
 | 
			
		||||
        if actor_type?
 | 
			
		||||
          @json = fetch_resource(@json['id'], true)
 | 
			
		||||
        elsif uri != @json['id']
 | 
			
		||||
          raise Error, "Fetched URI #{uri} has wrong id #{@json['id']}"
 | 
			
		||||
        end
 | 
			
		||||
      else
 | 
			
		||||
        @json = fetch_resource(uri, id)
 | 
			
		||||
      end
 | 
			
		||||
    else
 | 
			
		||||
      @json = body_to_json(prefetched_body, compare_id: id ? uri : nil)
 | 
			
		||||
    end
 | 
			
		||||
    @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)
 | 
			
		||||
 
 | 
			
		||||
@@ -8,14 +8,14 @@ class ActivityPub::FetchRemoteStatusService < BaseService
 | 
			
		||||
  DISCOVERIES_PER_REQUEST = 1000
 | 
			
		||||
 | 
			
		||||
  # Should be called when uri has already been checked for locality
 | 
			
		||||
  def call(uri, id: true, prefetched_body: nil, on_behalf_of: nil, expected_actor_uri: nil, request_id: nil)
 | 
			
		||||
  def call(uri, prefetched_body: nil, on_behalf_of: nil, expected_actor_uri: nil, request_id: nil)
 | 
			
		||||
    return if domain_not_allowed?(uri)
 | 
			
		||||
 | 
			
		||||
    @request_id = request_id || "#{Time.now.utc.to_i}-status-#{uri}"
 | 
			
		||||
    @json = if prefetched_body.nil?
 | 
			
		||||
              fetch_resource(uri, id, on_behalf_of)
 | 
			
		||||
              fetch_resource(uri, true, on_behalf_of)
 | 
			
		||||
            else
 | 
			
		||||
              body_to_json(prefetched_body, compare_id: id ? uri : nil)
 | 
			
		||||
              body_to_json(prefetched_body, compare_id: uri)
 | 
			
		||||
            end
 | 
			
		||||
 | 
			
		||||
    return unless supported_context?
 | 
			
		||||
@@ -65,7 +65,7 @@ class ActivityPub::FetchRemoteStatusService < BaseService
 | 
			
		||||
 | 
			
		||||
  def account_from_uri(uri)
 | 
			
		||||
    actor = ActivityPub::TagManager.instance.uri_to_resource(uri, Account)
 | 
			
		||||
    actor = ActivityPub::FetchRemoteAccountService.new.call(uri, id: true, request_id: @request_id) if actor.nil? || actor.possibly_stale?
 | 
			
		||||
    actor = ActivityPub::FetchRemoteAccountService.new.call(uri, request_id: @request_id) if actor.nil? || actor.possibly_stale?
 | 
			
		||||
    actor
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -277,7 +277,7 @@ class ActivityPub::ProcessAccountService < BaseService
 | 
			
		||||
 | 
			
		||||
  def moved_account
 | 
			
		||||
    account   = ActivityPub::TagManager.instance.uri_to_resource(@json['movedTo'], Account)
 | 
			
		||||
    account ||= ActivityPub::FetchRemoteAccountService.new.call(@json['movedTo'], id: true, break_on_redirect: true, request_id: @options[:request_id])
 | 
			
		||||
    account ||= ActivityPub::FetchRemoteAccountService.new.call(@json['movedTo'], break_on_redirect: true, request_id: @options[:request_id])
 | 
			
		||||
    account
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user