about summary refs log tree commit diff
path: root/config/initializers
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-02-15 18:02:45 +0100
committerThibaut Girka <thib@sitedethib.com>2019-02-15 18:02:45 +0100
commit06cc04fd239896d294210b8bbaadb7c611aaffe5 (patch)
tree1868711bbe9ee79b25ff10a585457cfa0f9ac121 /config/initializers
parent2769b5446681898e8332cb505f499dac2a6e5717 (diff)
parent8ef50706a11e115e8b4aa31b30de93738bc7e754 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/rack_attack.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb
index 35302e37b..28201cc64 100644
--- a/config/initializers/rack_attack.rb
+++ b/config/initializers/rack_attack.rb
@@ -46,14 +46,14 @@ class Rack::Attack
   end
 
   throttle('throttle_authenticated_api', limit: 300, period: 5.minutes) do |req|
-    req.api_request? && req.authenticated_user_id
+    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?
   end
 
-  throttle('throttle_media', limit: 30, period: 30.minutes) do |req|
+  throttle('throttle_api_media', limit: 30, period: 30.minutes) do |req|
     req.authenticated_user_id if req.post? && req.path.start_with?('/api/v1/media')
   end
 
@@ -61,6 +61,13 @@ class Rack::Attack
     req.ip if req.post? && req.path == '/api/v1/accounts'
   end
 
+  API_DELETE_REBLOG_REGEX = /\A\/api\/v1\/statuses\/[\d]+\/unreblog/.freeze
+  API_DELETE_STATUS_REGEX = /\A\/api\/v1\/statuses\/[\d]+/.freeze
+
+  throttle('throttle_api_delete', limit: 30, period: 30.minutes) do |req|
+    req.authenticated_user_id if (req.post? && req.path =~ API_DELETE_REBLOG_REGEX) || (req.delete? && req.path =~ API_DELETE_STATUS_REGEX)
+  end
+
   throttle('protected_paths', limit: 25, period: 5.minutes) do |req|
     req.ip if req.post? && req.path =~ PROTECTED_PATHS_REGEX
   end