[#471] Prevented rendering of inactive local accounts.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 27 Dec 2018 12:46:18 +0000 (15:46 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 27 Dec 2018 12:46:18 +0000 (15:46 +0300)
lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/twitter_api/views/user_view.ex

index 1f930479d7aa718b948e8f5eed931b6d7db1cc3f..b8a7a3fae706716a5b20a74b70003bbd03948786 100644 (file)
@@ -47,6 +47,8 @@ defmodule Pleroma.User do
       !Pleroma.Config.get([:instance, :account_activation_required])
   end
 
+  def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user)
+
   def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info)
 
   def avatar_url(user) do
index aaaae20358b0a9d17e75ca2e1d36a8213381b47c..ba72e3a1098cdb01b75a568dfc008d1f549b006c 100644 (file)
@@ -11,10 +11,30 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   alias Pleroma.HTML
 
   def render("accounts.json", %{users: users} = opts) do
-    render_many(users, AccountView, "account.json", opts)
+    users
+    |> render_many(AccountView, "account.json", opts)
+    |> Enum.filter(&Enum.any?/1)
   end
 
   def render("account.json", %{user: user} = opts) do
+    for_user = opts[:for]
+
+    allow_render =
+      User.remote_or_auth_active?(user) ||
+        (for_user && (for_user.id == user.id || User.superuser?(for_user)))
+
+    if allow_render do
+      render("valid_account.json", opts)
+    else
+      render("invalid_account.json", opts)
+    end
+  end
+
+  def render("invalid_account.json", _opts) do
+    %{}
+  end
+
+  def render("valid_account.json", %{user: user} = opts) do
     image = User.avatar_url(user) |> MediaProxy.url()
     header = User.banner_url(user) |> MediaProxy.url()
     user_info = User.user_info(user)
index 6e489624f4c721a61a45673ad03bda94014527f7..41825f8f66e38ec6b336b6dd0bffcf5d200a58eb 100644 (file)
@@ -15,18 +15,39 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
   end
 
   def render("index.json", %{users: users, for: user}) do
-    render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
+    users
+    |> render_many(Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
+    |> Enum.filter(&Enum.any?/1)
   end
 
   def render("user.json", %{user: user = %User{}} = assigns) do
+    for_user = assigns[:for]
+
+    allow_render =
+      User.remote_or_auth_active?(user) ||
+        (for_user && (for_user.id == user.id || User.superuser?(for_user)))
+
+    if allow_render do
+      render("valid_user.json", assigns)
+    else
+      render("invalid_user.json", assigns)
+    end
+  end
+
+  def render("invalid_user.json", _assigns) do
+    %{}
+  end
+
+  def render("valid_user.json", %{user: user = %User{}} = assigns) do
+    for_user = assigns[:for]
     image = User.avatar_url(user) |> MediaProxy.url()
 
     {following, follows_you, statusnet_blocking} =
-      if assigns[:for] do
+      if for_user do
         {
-          User.following?(assigns[:for], user),
-          User.following?(user, assigns[:for]),
-          User.blocks?(assigns[:for], user)
+          User.following?(for_user, user),
+          User.following?(user, for_user),
+          User.blocks?(for_user, user)
         }
       else
         {false, false, false}
@@ -51,7 +72,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
     data = %{
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
       "description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
-      "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(assigns[:for])),
+      "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)),
       "favourites_count" => 0,
       "followers_count" => user_info[:follower_count],
       "following" => following,