From 40fef8e632e4bc7fdd8fd6e663000dce0d191124 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 15 May 2025 21:01:49 +0200 Subject: [PATCH] api/masto/instance: use WebFinger domain for URI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Despite its name this property is not supposed to be a full URI, but just a bare domain witout protocol. Furthermore, it’s supposed to be the WebFinger domain used in userhandles and NOT the domain used for API and ActivityPub objects (which every caller will already know anyway). Not following this caused issues for Pachli and Tusky. Reported-by: nikclayton --- .../web/mastodon_api/views/instance_view.ex | 2 +- .../controllers/instance_controller_test.exs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index b5fc4df0e..2a5104edf 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do instance = Config.get(:instance) %{ - uri: Pleroma.Web.Endpoint.url(), + uri: Pleroma.Web.WebFinger.domain(), title: Keyword.get(instance, :name), description: Keyword.get(instance, :description), short_description: diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 61a9337f6..966ff86e3 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -18,9 +18,12 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail]) background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image]) + # if no WebFinger domain is configured (without protocol) + uri = Pleroma.Web.Endpoint.host() + # Note: not checking for "max_toot_chars" since it's optional assert %{ - "uri" => _, + "uri" => ^uri, "title" => _, "description" => _, "short_description" => _, @@ -55,6 +58,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do assert background == from_config_background end + test "get instance information prefers WebFinger domain for uri", %{conn: conn} do + webfinger_domain = "webfinger.example" + clear_config([Pleroma.Web.WebFinger, :domain], webfinger_domain) + conn = get(conn, "/api/v1/instance") + + assert result = json_response_and_validate_schema(conn, 200) + assert match?(%{"uri" => ^webfinger_domain}, result) + end + test "get instance stats", %{conn: conn} do user = insert(:user, %{local: true})