aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-10-11 22:34:28 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-10-11 22:34:28 +0300
commit89c595b772eaaa8809f5339d708d7dc22e51b662 (patch)
tree885a0de9778137c1af3355854a4a8deb8555516e /lib
parente1eb54d3899883b5af6a43687a2345543d69ad4a (diff)
downloadpleroma-89c595b772eaaa8809f5339d708d7dc22e51b662.tar.gz
[#3053] Removed target accessibility checks for OStatus endpoints delegating to RedirectController. Added tests.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/ostatus/ostatus_controller.ex13
-rw-r--r--lib/pleroma/web/router.ex38
2 files changed, 24 insertions, 27 deletions
diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex
index b4dc2a87f..e03ca8c0a 100644
--- a/lib/pleroma/web/ostatus/ostatus_controller.ex
+++ b/lib/pleroma/web/ostatus/ostatus_controller.ex
@@ -37,11 +37,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do
with id <- Endpoint.url() <> conn.request_path,
{_, %Activity{} = activity} <-
{:activity, Activity.get_create_by_object_ap_id_with_object(id)},
- {_, true} <- {:public?, Visibility.is_public?(activity)},
- {_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)} do
+ {_, true} <- {:public?, Visibility.is_public?(activity)} do
redirect(conn, to: "/notice/#{activity.id}")
else
- reason when reason in [{:public?, false}, {:visible?, false}, {:activity, nil}] ->
+ reason when reason in [{:public?, false}, {:activity, nil}] ->
{:error, :not_found}
e ->
@@ -57,11 +56,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do
def activity(conn, _params) do
with id <- Endpoint.url() <> conn.request_path,
{_, %Activity{} = activity} <- {:activity, Activity.normalize(id)},
- {_, true} <- {:public?, Visibility.is_public?(activity)},
- {_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)} do
+ {_, true} <- {:public?, Visibility.is_public?(activity)} do
redirect(conn, to: "/notice/#{activity.id}")
else
- reason when reason in [{:public?, false}, {:visible?, false}, {:activity, nil}] ->
+ reason when reason in [{:public?, false}, {:activity, nil}] ->
{:error, :not_found}
e ->
@@ -72,7 +70,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do
def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
{_, true} <- {:public?, Visibility.is_public?(activity)},
- {_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)},
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
cond do
format in ["json", "activity+json"] ->
@@ -100,7 +97,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
RedirectController.redirector(conn, nil)
end
else
- reason when reason in [{:public?, false}, {:visible?, false}, {:activity, nil}] ->
+ reason when reason in [{:public?, false}, {:activity, nil}] ->
conn
|> put_status(404)
|> RedirectController.redirector(nil, 404)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 97fcaafd5..ef56360ed 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -9,6 +9,18 @@ defmodule Pleroma.Web.Router do
plug(:accepts, ["html"])
end
+ pipeline :accepts_html_xml do
+ plug(:accepts, ["html", "xml", "rss", "atom"])
+ end
+
+ pipeline :accepts_html_json do
+ plug(:accepts, ["html", "activity+json", "json"])
+ end
+
+ pipeline :accepts_html_xml_json do
+ plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
+ end
+
pipeline :accepts_xml_rss_atom do
plug(:accepts, ["xml", "rss", "atom"])
end
@@ -574,24 +586,10 @@ defmodule Pleroma.Web.Router do
)
end
- pipeline :ostatus_html_json do
- plug(:accepts, ["html", "activity+json", "json"])
- plug(Pleroma.Plugs.StaticFEPlug)
- end
-
- pipeline :ostatus_html_xml do
- plug(:accepts, ["html", "xml", "rss", "atom"])
- plug(Pleroma.Plugs.StaticFEPlug)
- end
-
- pipeline :ostatus_html_xml_json do
- plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
- plug(Pleroma.Plugs.StaticFEPlug)
- end
-
scope "/", Pleroma.Web do
# Note: html format is supported only if static FE is enabled
- pipe_through(:ostatus_html_json)
+ # Note: http signature is only considered for json requests (no auth for non-json requests)
+ pipe_through([:accepts_html_json, :http_signature, Pleroma.Plugs.StaticFEPlug])
get("/objects/:uuid", OStatus.OStatusController, :object)
get("/activities/:uuid", OStatus.OStatusController, :activity)
@@ -604,15 +602,17 @@ defmodule Pleroma.Web.Router do
scope "/", Pleroma.Web do
# Note: html format is supported only if static FE is enabled
- pipe_through(:ostatus_html_xml_json)
+ # Note: http signature is only considered for json requests (no auth for non-json requests)
+ pipe_through([:accepts_html_xml_json, :http_signature, Pleroma.Plugs.StaticFEPlug])
- # Note: for json format responds with user profile (not user feed)
+ # Note: returns user _profile_ for json requests, redirects to user _feed_ for non-json ones
get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
end
scope "/", Pleroma.Web do
# Note: html format is supported only if static FE is enabled
- pipe_through(:ostatus_html_xml)
+ pipe_through([:accepts_html_xml, Pleroma.Plugs.StaticFEPlug])
+
get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
end