aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/user_is_admin_plug.ex24
-rw-r--r--lib/pleroma/user.ex3
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/pleroma/plugs/user_is_admin_plug.ex b/lib/pleroma/plugs/user_is_admin_plug.ex
index 4a0e43b00..582fb1f92 100644
--- a/lib/pleroma/plugs/user_is_admin_plug.ex
+++ b/lib/pleroma/plugs/user_is_admin_plug.ex
@@ -6,29 +6,37 @@ defmodule Pleroma.Plugs.UserIsAdminPlug do
import Pleroma.Web.TranslationHelpers
import Plug.Conn
+ alias Pleroma.User
alias Pleroma.Web.OAuth
def init(options) do
options
end
- def call(%Plug.Conn{assigns: assigns} = conn, _) do
+ def call(%{assigns: %{user: %User{is_admin: true}} = assigns} = conn, _) do
token = assigns[:token]
- user = assigns[:user]
cond do
+ not Pleroma.Config.enforce_oauth_admin_scope_usage?() ->
+ conn
+
token && OAuth.Scopes.contains_admin_scopes?(token.scopes) ->
# Note: checking for _any_ admin scope presence, not necessarily fitting requested action.
# Thus, controller must explicitly invoke OAuthScopesPlug to verify scope requirements.
conn
- user && user.is_admin && !Pleroma.Config.enforce_oauth_admin_scope_usage?() ->
- conn
-
true ->
- conn
- |> render_error(:forbidden, "User is not an admin or OAuth admin scope is not granted.")
- |> halt()
+ fail(conn)
end
end
+
+ def call(conn, _) do
+ fail(conn)
+ end
+
+ defp fail(conn) do
+ conn
+ |> render_error(:forbidden, "User is not an admin or OAuth admin scope is not granted.")
+ |> halt()
+ end
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 7b8222ce1..1006b5bf9 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1736,7 +1736,8 @@ defmodule Pleroma.User do
with {:ok, updated_user} <- update_and_set_cache(changeset) do
if user.is_admin && !updated_user.is_admin do
- # Tokens & authorizations containing any admin scopes must be revoked (revoking all)
+ # Tokens & authorizations containing any admin scopes must be revoked (revoking all).
+ # This is an extra safety measure (tokens' admin scopes won't be accepted for non-admins).
global_sign_out(user)
end