fix: throttle contact search endpoint to prevent abuse (#8919)

Throttle contact_search endpoint to prevent abuse/maintain db perf
ref: https://discord.com/channels/897869226579222540/899920096972111883/1206919316402999326
This commit is contained in:
Vishnu Narayanan 2024-02-13 18:48:11 +05:30 committed by GitHub
parent 1ce5cbe275
commit 96b781b7fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -148,6 +148,12 @@ class Rack::Attack
match_data[:account_id] if match_data.present?
end
## Prevent abuse of contact search api
throttle('/api/v1/accounts/:account_id/contacts/search', limit: 5, period: 1.minute) do |req|
match_data = %r{/api/v1/accounts/(?<account_id>\d+)/contacts/search}.match(req.path)
match_data[:account_id] if match_data.present?
end
## ----------------------------------------------- ##
end