[#534] Made federation push sender be determined basing on content instead of referer header. Updated tests.

This commit is contained in:
Ivan Tashkinov 2019-01-29 13:12:28 +03:00
commit 92753b0cd9
15 changed files with 68 additions and 80 deletions

View file

@ -1,16 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.SetRequesterReachablePlug do
import Plug.Conn
def init(_), do: []
def call(%Plug.Conn{} = conn, _) do
with [referer] <- get_req_header(conn, "referer"),
do: Pleroma.Instances.set_reachable(referer)
conn
end
end

View file

@ -3,8 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxy do
@keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since) ++
~w(if-none-match if-range range referer)
@keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range)
@resp_cache_headers ~w(etag date last-modified cache-control)
@keep_resp_headers @resp_cache_headers ++
~w(content-type content-disposition content-encoding content-range accept-ranges vary)

View file

@ -784,8 +784,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
[
{"Content-Type", "application/activity+json"},
{"signature", signature},
{"digest", digest},
{"referer", Pleroma.Web.Endpoint.url()}
{"digest", digest}
]
) do
Instances.set_reachable(inbox)

View file

@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
action_fallback(:errors)
plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay])
plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:inbox])
plug(:set_requester_reachable when action in [:inbox])
plug(:relay_active? when action in [:relay])
def relay_active?(conn, _) do
@ -291,4 +291,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|> put_status(500)
|> json("error")
end
defp set_requester_reachable(%Plug.Conn{} = conn, _) do
with actor <- conn.params["actor"],
true <- is_binary(actor) do
Pleroma.Instances.set_reachable(actor)
end
conn
end
end

View file

@ -48,6 +48,9 @@ defmodule Pleroma.Web.OStatus do
def handle_incoming(xml_string) do
with doc when doc != :error <- parse_document(xml_string) do
with {:ok, actor_user} <- find_make_or_update_user(doc),
do: Pleroma.Instances.set_reachable(actor_user.ap_id)
entries = :xmerl_xpath.string('//entry', doc)
activities =

View file

@ -14,7 +14,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do
alias Pleroma.Web.ActivityPub.ActivityPub
plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming])
plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:salmon_incoming])
action_fallback(:errors)

View file

@ -172,10 +172,7 @@ defmodule Pleroma.Web.Salmon do
poster.(
url,
feed,
[
{"Content-Type", "application/magic-envelope+xml"},
{"referer", Pleroma.Web.Endpoint.url()}
]
[{"Content-Type", "application/magic-envelope+xml"}]
) do
Instances.set_reachable(url)
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)

View file

@ -278,8 +278,7 @@ defmodule Pleroma.Web.Websub do
xml,
[
{"Content-Type", "application/atom+xml"},
{"X-Hub-Signature", "sha1=#{signature}"},
{"referer", Pleroma.Web.Endpoint.url()}
{"X-Hub-Signature", "sha1=#{signature}"}
]
) do
Instances.set_reachable(callback)

View file

@ -20,8 +20,6 @@ defmodule Pleroma.Web.Websub.WebsubController do
]
)
plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:websub_incoming])
def websub_subscription_request(conn, %{"nickname" => nickname} = params) do
user = User.get_cached_by_nickname(nickname)