mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 18:02:59 +01:00
cd9b2ab2f7
* Fix #2672 - Connect signed PuSH subscription requests to instance domain Resolves #2739 * Fix return of locate_subscription * Fix tests
73 lines
1.6 KiB
Ruby
73 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::PushController < Api::BaseController
|
|
include SignatureVerification
|
|
|
|
def update
|
|
response, status = process_push_request
|
|
render plain: response, status: status
|
|
end
|
|
|
|
private
|
|
|
|
def process_push_request
|
|
case hub_mode
|
|
when 'subscribe'
|
|
Pubsubhubbub::SubscribeService.new.call(account_from_topic, hub_callback, hub_secret, hub_lease_seconds, verified_domain)
|
|
when 'unsubscribe'
|
|
Pubsubhubbub::UnsubscribeService.new.call(account_from_topic, hub_callback)
|
|
else
|
|
["Unknown mode: #{hub_mode}", 422]
|
|
end
|
|
end
|
|
|
|
def hub_mode
|
|
params['hub.mode']
|
|
end
|
|
|
|
def hub_topic
|
|
params['hub.topic']
|
|
end
|
|
|
|
def hub_callback
|
|
params['hub.callback']
|
|
end
|
|
|
|
def hub_lease_seconds
|
|
params['hub.lease_seconds']
|
|
end
|
|
|
|
def hub_secret
|
|
params['hub.secret']
|
|
end
|
|
|
|
def account_from_topic
|
|
if hub_topic.present? && local_domain? && account_feed_path?
|
|
Account.find_local(hub_topic_params[:username])
|
|
end
|
|
end
|
|
|
|
def hub_topic_params
|
|
@_hub_topic_params ||= Rails.application.routes.recognize_path(hub_topic_uri.path)
|
|
end
|
|
|
|
def hub_topic_uri
|
|
@_hub_topic_uri ||= Addressable::URI.parse(hub_topic).normalize
|
|
end
|
|
|
|
def local_domain?
|
|
TagManager.instance.web_domain?(hub_topic_domain)
|
|
end
|
|
|
|
def verified_domain
|
|
return signed_request_account.domain if signed_request_account
|
|
end
|
|
|
|
def hub_topic_domain
|
|
hub_topic_uri.host + (hub_topic_uri.port ? ":#{hub_topic_uri.port}" : '')
|
|
end
|
|
|
|
def account_feed_path?
|
|
hub_topic_params[:controller] == 'accounts' && hub_topic_params[:action] == 'show' && hub_topic_params[:format] == 'atom'
|
|
end
|
|
end
|