From 64e16e6a4be83e9328d62101cc21d10cf07e38fb Mon Sep 17 00:00:00 2001 From: Sean King Date: Sat, 16 Jul 2022 23:44:37 -0600 Subject: [PATCH 1/3] Document way to do notice compatibility routes with Nginx reverse-proxy instead --- installation/pleroma.nginx | 13 +++++ lib/pleroma/web/router.ex | 5 -- .../web/static_fe/static_fe_controller.ex | 9 ---- .../web/o_status/o_status_controller_test.exs | 50 ------------------- .../web/plugs/frontend_static_plug_test.exs | 2 - 5 files changed, 13 insertions(+), 66 deletions(-) diff --git a/installation/pleroma.nginx b/installation/pleroma.nginx index 9890cb2b1..8aed2daea 100644 --- a/installation/pleroma.nginx +++ b/installation/pleroma.nginx @@ -81,6 +81,19 @@ server { proxy_pass http://phoenix; } + # Uncomment this if you want notice compatibility routes for frontends like Soapbox. + # location ~ /@.+/([^/]+) { + # proxy_pass http://phoenix/notice/$1; + # } + # + # location ~ /@.+/posts/([^/]+) { + # proxy_pass http://phoenix/notice/$1; + # } + # + # location ~ /.+/status/([^/]+) { + # proxy_pass http://phoenix/notice/$1; + # } + location ~ ^/(media|proxy) { proxy_cache pleroma_media_cache; slice 1m; diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7bbc20275..ac3de8af3 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -678,11 +678,6 @@ defmodule Pleroma.Web.Router do get("/activities/:uuid", OStatus.OStatusController, :activity) get("/notice/:id", OStatus.OStatusController, :notice) - # Notice compatibility routes for other frontends - get("/@:nickname/:id", OStatus.OStatusController, :notice) - get("/@:nickname/posts/:id", OStatus.OStatusController, :notice) - get("/:nickname/status/:id", OStatus.OStatusController, :notice) - # Mastodon compatibility routes get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object) get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity) diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index b20a3689c..97c41c6f9 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -167,15 +167,6 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do defp assign_id(%{path_info: ["notice", notice_id]} = conn, _opts), do: assign(conn, :notice_id, notice_id) - defp assign_id(%{path_info: ["@" <> _nickname, notice_id]} = conn, _opts), - do: assign(conn, :notice_id, notice_id) - - defp assign_id(%{path_info: ["@" <> _nickname, "posts", notice_id]} = conn, _opts), - do: assign(conn, :notice_id, notice_id) - - defp assign_id(%{path_info: [_nickname, "status", notice_id]} = conn, _opts), - do: assign(conn, :notice_id, notice_id) - defp assign_id(%{path_info: ["users", user_id]} = conn, _opts), do: assign(conn, :username_or_id, user_id) diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 5abbcfbdc..36e581f5e 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -343,54 +343,4 @@ test "does not require authentication on non-federating instances", %{ |> response(200) end end - - describe "notice compatibility routes" do - test "Soapbox FE", %{conn: conn} do - user = insert(:user) - note_activity = insert(:note_activity, user: user) - - resp = - conn - |> put_req_header("accept", "text/html") - |> get("/@#{user.nickname}/posts/#{note_activity.id}") - |> response(200) - - expected = - "" - - assert resp =~ expected - end - - test "Mastodon", %{conn: conn} do - user = insert(:user) - note_activity = insert(:note_activity, user: user) - - resp = - conn - |> put_req_header("accept", "text/html") - |> get("/@#{user.nickname}/#{note_activity.id}") - |> response(200) - - expected = - "" - - assert resp =~ expected - end - - test "Twitter", %{conn: conn} do - user = insert(:user) - note_activity = insert(:note_activity, user: user) - - resp = - conn - |> put_req_header("accept", "text/html") - |> get("/#{user.nickname}/status/#{note_activity.id}") - |> response(200) - - expected = - "" - - assert resp =~ expected - end - end end diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs index a91e24c49..ab31c5f22 100644 --- a/test/pleroma/web/plugs/frontend_static_plug_test.exs +++ b/test/pleroma/web/plugs/frontend_static_plug_test.exs @@ -86,8 +86,6 @@ test "api routes are detected correctly" do "objects", "activities", "notice", - "@:nickname", - ":nickname", "users", "tags", "mailer", From 2c7eed122e909f392e3d41efe43fc2b0b99fe842 Mon Sep 17 00:00:00 2001 From: Sean King Date: Sun, 17 Jul 2022 12:50:01 -0600 Subject: [PATCH 2/3] Don't accept forward slash character for nicknames --- installation/pleroma.nginx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation/pleroma.nginx b/installation/pleroma.nginx index 8aed2daea..d53852984 100644 --- a/installation/pleroma.nginx +++ b/installation/pleroma.nginx @@ -82,15 +82,15 @@ server { } # Uncomment this if you want notice compatibility routes for frontends like Soapbox. - # location ~ /@.+/([^/]+) { + # location ~ /@([^/]+)/([^/]+) { # proxy_pass http://phoenix/notice/$1; # } # - # location ~ /@.+/posts/([^/]+) { + # location ~ /@([^/]+)/posts/([^/]+) { # proxy_pass http://phoenix/notice/$1; # } # - # location ~ /.+/status/([^/]+) { + # location ~ /([^/]+)/status/([^/]+) { # proxy_pass http://phoenix/notice/$1; # } From 3da1b2548dd5793fcf08050470252b9574991295 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 18 Jul 2022 21:30:57 -0600 Subject: [PATCH 3/3] Actually fix with forward slashes being restricted inside nickname --- installation/pleroma.nginx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation/pleroma.nginx b/installation/pleroma.nginx index d53852984..273cfb390 100644 --- a/installation/pleroma.nginx +++ b/installation/pleroma.nginx @@ -82,15 +82,15 @@ server { } # Uncomment this if you want notice compatibility routes for frontends like Soapbox. - # location ~ /@([^/]+)/([^/]+) { + # location ~ ^/@[^/]+/([^/]+)$ { # proxy_pass http://phoenix/notice/$1; # } # - # location ~ /@([^/]+)/posts/([^/]+) { + # location ~ ^/@[^/]+/posts/([^/]+)$ { # proxy_pass http://phoenix/notice/$1; # } # - # location ~ /([^/]+)/status/([^/]+) { + # location ~ ^/[^/]+/status/([^/]+)$ { # proxy_pass http://phoenix/notice/$1; # }