From 0e9b8be18ab0c3d2b0fe24eaee1cfe0e711a52cd Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 27 May 2019 21:57:49 +0200 Subject: Improve rate limiting (#10860) * Rate limit based on remote address IP, not on potential reverse proxy * Limit rate of unauthenticated API requests further * Rate-limit paging requests to one every 3 seconds --- config/initializers/rack_attack.rb | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'config') diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index ae3eede66..e6c9f9bd4 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -13,6 +13,10 @@ class Rack::Attack ) end + def remote_ip + @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s + end + def authenticated_user_id authenticated_token&.resource_owner_id end @@ -28,6 +32,10 @@ class Rack::Attack def web_request? !api_request? end + + def paging_request? + params['page'].present? || params['min_id'].present? || params['max_id'].present? || params['since_id'].present? + end end PROTECTED_PATHS = %w( @@ -42,15 +50,15 @@ class Rack::Attack # (blocklist & throttles are skipped) Rack::Attack.safelist('allow from localhost') do |req| # Requests are allowed if the return value is truthy - req.ip == '127.0.0.1' || req.ip == '::1' + req.remote_ip == '127.0.0.1' || req.remote_ip == '::1' end throttle('throttle_authenticated_api', limit: 300, period: 5.minutes) do |req| req.authenticated_user_id if req.api_request? end - throttle('throttle_unauthenticated_api', limit: 7_500, period: 5.minutes) do |req| - req.ip if req.api_request? + throttle('throttle_unauthenticated_api', limit: 300, period: 5.minutes) do |req| + req.remote_ip if req.api_request? && !req.authenticated? end throttle('throttle_api_media', limit: 30, period: 30.minutes) do |req| @@ -58,11 +66,20 @@ class Rack::Attack end throttle('throttle_media_proxy', limit: 30, period: 30.minutes) do |req| - req.ip if req.path.start_with?('/media_proxy') + req.remote_ip if req.path.start_with?('/media_proxy') end throttle('throttle_api_sign_up', limit: 5, period: 30.minutes) do |req| - req.ip if req.post? && req.path == '/api/v1/accounts' + req.remote_ip if req.post? && req.path == '/api/v1/accounts' + end + + # Throttle paging, as it is mainly used for public pages and AP collections + throttle('throttle_authenticated_paging', limit: 300, period: 15.minutes) do |req| + req.authenticated_user_id if req.paging_request? + end + + throttle('throttle_unauthenticated_paging', limit: 300, period: 15.minutes) do |req| + req.remote_ip if req.paging_request? && !req.authenticated? end API_DELETE_REBLOG_REGEX = /\A\/api\/v1\/statuses\/[\d]+\/unreblog/.freeze @@ -73,7 +90,7 @@ class Rack::Attack end throttle('protected_paths', limit: 25, period: 5.minutes) do |req| - req.ip if req.post? && req.path =~ PROTECTED_PATHS_REGEX + req.remote_ip if req.post? && req.path =~ PROTECTED_PATHS_REGEX end self.throttled_response = lambda do |env| -- cgit From e2c0d055389ab128bf372c7b3168bff81818d2b2 Mon Sep 17 00:00:00 2001 From: Alix Rossi Date: Tue, 28 May 2019 03:21:30 +0200 Subject: Update simple_form.co.yml (#10862) --- config/locales/simple_form.co.yml | 2 ++ 1 file changed, 2 insertions(+) (limited to 'config') diff --git a/config/locales/simple_form.co.yml b/config/locales/simple_form.co.yml index 3a521e85e..c4529093b 100644 --- a/config/locales/simple_form.co.yml +++ b/config/locales/simple_form.co.yml @@ -26,6 +26,7 @@ co: password: Ci volenu almenu 8 caratteri phrase: Sarà trovu senza primura di e maiuscule o di l'avertimenti scopes: L'API à quelle l'applicazione averà accessu. S'è voi selezziunate un parametru d'altu livellu, un c'hè micca bisognu di selezziunà quell'individuali. + setting_advanced_layout: L'interfaccia avanzata cunsiste in parechje culonne persunalizabile setting_aggregate_reblogs: Ùn mustrà micca e nove spartere per i statuti chì sò stati spartuti da pocu (tocca solu e spartere più ricente) setting_default_language: A lingua di i vostri statuti pò esse induvinata autumaticamente, mà ùn marchja micca sempre bè setting_display_media_default: Piattà i media marcati cum'è sensibili @@ -90,6 +91,7 @@ co: otp_attempt: Codice d’identificazione à dui fattori password: Chjave d’accessu phrase: Parolla-chjave o frasa + setting_advanced_layout: Attivà l'interfaccia web avanzata setting_aggregate_reblogs: Gruppà e spartere indè e linee setting_auto_play_gif: Lettura autumatica di i GIF animati setting_boost_modal: Mustrà una cunfirmazione per sparte un statutu -- cgit From afb17b7045f7b76c60af11f58e2d326ee64d70ba Mon Sep 17 00:00:00 2001 From: mayaeh Date: Tue, 28 May 2019 12:42:04 +0900 Subject: Fix undefined method error. (#10867) --- config/initializers/rack_attack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index e6c9f9bd4..f3594c0ba 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -58,7 +58,7 @@ class Rack::Attack end throttle('throttle_unauthenticated_api', limit: 300, period: 5.minutes) do |req| - req.remote_ip if req.api_request? && !req.authenticated? + req.remote_ip if req.api_request? && req.unauthenticated? end throttle('throttle_api_media', limit: 30, period: 30.minutes) do |req| -- cgit From b793722d7d7df856466331729d523c807273b003 Mon Sep 17 00:00:00 2001 From: Hinaloe Date: Tue, 28 May 2019 21:31:51 +0900 Subject: Fix undefined method error (#10868) --- config/initializers/rack_attack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index f3594c0ba..24ba16ae3 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -79,7 +79,7 @@ class Rack::Attack end throttle('throttle_unauthenticated_paging', limit: 300, period: 15.minutes) do |req| - req.remote_ip if req.paging_request? && !req.authenticated? + req.remote_ip if req.paging_request? && req.unauthenticated? end API_DELETE_REBLOG_REGEX = /\A\/api\/v1\/statuses\/[\d]+\/unreblog/.freeze -- cgit