forked from openware/barong
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rack-attack and some API usage limits
- Loading branch information
alinetskyi
authored and
Louis
committed
Oct 31, 2018
1 parent
a0df95d
commit 09844d2
Showing
5 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Rack::Attack | ||
|
||
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new | ||
|
||
phone_verif_limit = ENV.fetch('PHONE_VERIFICATION_RATE_LIMIT', 5) | ||
|
||
# Limit nubmer of calls from ip per second | ||
throttle('logins/ip',limit: 10, period: 1.seconds) do |req| | ||
req.ip | ||
end | ||
|
||
# Limit number of phone verification calls per number | ||
throttle('phone_verification/number', limit: phone_verif_limit , period: 24.hours) do |req| | ||
case req.path | ||
when '/phones/verification' | ||
req.body.string | ||
when '/phones' | ||
req.cookies['_barong_session'] | ||
end | ||
end | ||
|
||
# TODO: Limit by account id not by barong session | ||
|
||
end | ||
|