]> cat aescling's git repositories - mastodon.git/commitdiff
Fix suspended users being able to access APIs that don't require a user (#18524)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 26 May 2022 20:04:05 +0000 (22:04 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Fri, 27 May 2022 03:55:21 +0000 (23:55 -0400)
app/controllers/activitypub/base_controller.rb
app/controllers/api/base_controller.rb

index 196d85a32643e3ef94edab875067fb6a6975bf50..b8a7e0ab96ee3ad20b68b409ad6c38bf51bf4d90 100644 (file)
@@ -2,6 +2,7 @@
 
 class ActivityPub::BaseController < Api::BaseController
   skip_before_action :require_authenticated_user!
+  skip_before_action :require_not_suspended!
   skip_around_action :set_locale
 
   private
index d96285b440479af50330eab92e9d273ef4dfbcf4..2e393fbb6f4d0fdcfe3be8cbe72d922753dc7010 100644 (file)
@@ -11,6 +11,7 @@ class Api::BaseController < ApplicationController
   skip_before_action :require_functional!, unless: :whitelist_mode?
 
   before_action :require_authenticated_user!, if: :disallow_unauthenticated_api_access?
+  before_action :require_not_suspended!
   before_action :set_cache_headers
 
   protect_from_forgery with: :null_session
@@ -97,6 +98,10 @@ class Api::BaseController < ApplicationController
     render json: { error: 'This method requires an authenticated user' }, status: 401 unless current_user
   end
 
+  def require_not_suspended!
+    render json: { error: 'Your login is currently disabled' }, status: 403 if current_user&.account&.suspended?
+  end
+
   def require_user!
     if !current_user
       render json: { error: 'This method requires an authenticated user' }, status: 422