diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-07-14 11:58:41 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-07-14 11:58:41 +0300 |
commit | 9b225db7d86289fb9d9c51f62e6ec29f6c07f60d (patch) | |
tree | d69a32b483f39e0b02419ce45b8a6b578666172a /lib | |
parent | cf3f8cb72a46f0c8c798d4022cff442fae4ab401 (diff) | |
download | pleroma-9b225db7d86289fb9d9c51f62e6ec29f6c07f60d.tar.gz |
[#1940] Applied rate limit for requests with bad `admin_token`. Added doc warnings on `admin_token` setting.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/plugs/admin_secret_authentication_plug.ex | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/pleroma/plugs/admin_secret_authentication_plug.ex b/lib/pleroma/plugs/admin_secret_authentication_plug.ex index ff0328d4a..2e54df47a 100644 --- a/lib/pleroma/plugs/admin_secret_authentication_plug.ex +++ b/lib/pleroma/plugs/admin_secret_authentication_plug.ex @@ -5,15 +5,19 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do import Plug.Conn - alias Pleroma.User alias Pleroma.Plugs.OAuthScopesPlug + alias Pleroma.Plugs.RateLimiter + alias Pleroma.User def init(options) do options end def secret_token do - Pleroma.Config.get(:admin_token) + case Pleroma.Config.get(:admin_token) do + blank when blank in [nil, ""] -> nil + token -> token + end end def call(%{assigns: %{user: %User{}}} = conn, _), do: conn @@ -30,7 +34,7 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do if admin_token == secret_token() do assign_admin_user(conn) else - conn + handle_bad_token(conn) end end @@ -38,8 +42,9 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do token = secret_token() case get_req_header(conn, "x-admin-token") do + blank when blank in [[], [""]] -> conn [^token] -> assign_admin_user(conn) - _ -> conn + _ -> handle_bad_token(conn) end end @@ -48,4 +53,8 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do |> assign(:user, %User{is_admin: true}) |> OAuthScopesPlug.skip_plug() end + + defp handle_bad_token(conn) do + RateLimiter.call(conn, name: :authentication) + end end |