aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-12-07 17:49:53 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-12-07 17:49:53 +0300
commit1770602747ae95d95d12c5601f99ced8699e8947 (patch)
tree7c7a910a65e1d72791c3a9a4a988ad1a377ebd82 /lib/pleroma
parent40e1817f707c3c2ef253009c7363cd81b11322a6 (diff)
downloadpleroma-1770602747ae95d95d12c5601f99ced8699e8947.tar.gz
[#1427] Extra check that admin OAuth scope is used by admin. Adjusted tests.
Diffstat (limited to 'lib/pleroma')
-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