diff --git a/app/lib/request.rb b/app/lib/request.rb index c476e7785bdab30f5d93efb6ae5399f2527fd987..43c59c962c86c4fd2819374ad28abccde74afe10 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -104,10 +104,16 @@ class Request def set_common_headers! @headers[REQUEST_TARGET] = "#{@verb} #{@url.path}" - @headers['User-Agent'] = Mastodon::Version.user_agent + @headers['User-Agent'] = smuggling? ? Mastodon::Version.pseudo_user_agent : Mastodon::Version.user_agent @headers['Host'] = @url.host @headers['Date'] = Time.now.utc.httpdate @headers['Accept-Encoding'] = 'gzip' if @verb != :head + @headers['Referer'] = "https://#{@url.host}" if smuggling? + end + + def smuggling? + should = @url.host.end_with?('mstdn.jp') + return !!should end def set_digest! diff --git a/config/initializers/http_client_proxy.rb b/config/initializers/http_client_proxy.rb index 9d7b16e69c87a671b53cf57440e0b5cfcaceeadd..8b5ba050629d32757fe53ed8724d0255bc2a0d43 100644 --- a/config/initializers/http_client_proxy.rb +++ b/config/initializers/http_client_proxy.rb @@ -18,7 +18,7 @@ module Goldfinger to_hidden = /\.(onion|i2p)(:\d+)?$/.match(uri) raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && to_hidden opts = { ssl: !to_hidden, headers: {} }.merge(Rails.configuration.x.http_client_proxy).merge(opts) - opts[:headers]['User-Agent'] ||= Mastodon::Version.user_agent + opts[:headers]['User-Agent'] ||= uri.match?(/mstdn\.jp/) ? Mastodon::Version.pseudo_user_agent : Mastodon::Version.user_agent Goldfinger::Client.new(uri, opts).finger end end diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index f3ead6d8d96d6a2e8d4b9fe902b03cee74f0798b..eba1db6e5935efbd1d8a6905f8be02a66ad294ee 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -56,5 +56,9 @@ module Mastodon def user_agent @user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Version}; +http#{Rails.configuration.x.use_https ? 's' : ''}://#{Rails.configuration.x.web_domain}/)" end + + def pseudo_user_agent + @pseudo_user_agent ||= 'Misskey/11.37.1 (https://misskey.noellabo.jp)' + end end end