Merge remote-tracking branch 'remotes/upstream/develop' into 1260-rate-limited-auth...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sun, 6 Oct 2019 06:30:49 +0000 (09:30 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sun, 6 Oct 2019 06:30:49 +0000 (09:30 +0300)
# Conflicts:
# CHANGELOG.md

CHANGELOG.md
config/config.exs
config/description.exs
lib/pleroma/web/mongooseim/mongoose_im_controller.ex
lib/pleroma/web/oauth/oauth_controller.ex

index db505591b703264ffef0dd1da291316d6634a46a..b7178889fe97a6d362e7822fd3e9ca3c087b077c 100644 (file)
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Pleroma API: `POST /api/v1/pleroma/scrobble` to scrobble a media item
 - Mastodon API: Add `upload_limit`, `avatar_upload_limit`, `background_upload_limit`, and `banner_upload_limit` to `/api/v1/instance`
 - Mastodon API: Add `pleroma.unread_conversation_count` to the Account entity
+- Authentication: Added rate limit for password-authorized actions / login existence checks
 
 ### Changed
 - **Breaking:** Elixir >=1.8 is now required (was >= 1.7)
index ddbfb246a32db789d33caecaeab04fc820b896e9..cf94f1a19062733d5d9a5b2414194e5131042d11 100644 (file)
@@ -588,7 +588,7 @@ config :pleroma, :env, Mix.env()
 config :http_signatures,
   adapter: Pleroma.Signature
 
-config :pleroma, :rate_limit, nil
+config :pleroma, :rate_limit, authentication: {60_000, 15}
 
 config :pleroma, Pleroma.ActivityExpiration, enabled: true
 
index 4547ea36839e5d04ff6a017f209ecba47adce4cd..b007cf69ca9a83097525d5da56012d8dd11f084d 100644 (file)
@@ -2290,7 +2290,8 @@ config :pleroma, :config_description, [
     group: :pleroma,
     key: :rate_limit,
     type: :group,
-    description: "Rate limit settings. This is an advanced feature and disabled by default.",
+    description:
+      "Rate limit settings. This is an advanced feature enabled only for :authentication by default.",
     children: [
       %{
         key: :search,
@@ -2329,6 +2330,12 @@ config :pleroma, :config_description, [
         description:
           "for fav / unfav or reblog / unreblog actions on the same status by the same user",
         suggestions: [{1000, 10}, [{10_000, 10}, {10_000, 50}]]
+      },
+      %{
+        key: :authentication,
+        type: [:tuple, {:list, :tuple}],
+        description: "for authentication create / password check / user existence check requests",
+        suggestions: [{60_000, 15}]
       }
     ]
   },
index b786a521b2c4018d41eeaae0bf18a0d44a09b543..6ed181cffb78e43db51ba626837e482a086b10f0 100644 (file)
@@ -4,10 +4,15 @@
 
 defmodule Pleroma.Web.MongooseIM.MongooseIMController do
   use Pleroma.Web, :controller
+
   alias Comeonin.Pbkdf2
+  alias Pleroma.Plugs.RateLimiter
   alias Pleroma.Repo
   alias Pleroma.User
 
+  plug(RateLimiter, :authentication when action in [:user_exists, :check_password])
+  plug(RateLimiter, {:authentication, params: ["user"]} when action == :check_password)
+
   def user_exists(conn, %{"user" => username}) do
     with %User{} <- Repo.get_by(User, nickname: username, local: true) do
       conn
index 1cd7294e74925ec4cacf3ce56278194c91147af8..91b1f87cc98b7c68e10c011242ac7e42f76a7291 100644 (file)
@@ -24,6 +24,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
 
   plug(:fetch_session)
   plug(:fetch_flash)
+  plug(Pleroma.Plugs.RateLimiter, :authentication when action == :create_authorization)
 
   action_fallback(Pleroma.Web.OAuth.FallbackController)