Skip to content

Commit 6f0f9ba

Browse files
committed
fix rack-attack broken logic
1 parent 9547700 commit 6f0f9ba

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

config/initializers/rack_attack.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
class Rack::Attack
2-
# 10 requests per 10 seconds for a single ip
3-
throttle('req/ip', limit: 10, period: 10) do |req|
4-
req.ip
5-
end
6-
72
# response with 429
83
self.throttled_response = ->(env) {
94
retry_after = (env['rack.attack.match_data'] || {})[:period]
@@ -13,9 +8,14 @@ class Rack::Attack
138
[{error: "Throttle limit reached. Retry later."}.to_json]
149
]
1510
}
11+
end
12+
13+
# 10 requests per 10 seconds for a single ip
14+
Rack::Attack::throttle('req/ip', limit: 10, period: 10) do |req|
15+
req.ip
16+
end
1617

17-
# whitelist localhost
18-
safelist('allow-localhost') do |req|
19-
'127.0.0.1' == req.ip || '::1' == req.ip
20-
end
18+
# whitelist localhost
19+
Rack::Attack::safelist('allow-localhost') do |req|
20+
'127.0.0.1' == req.ip || '::1' == req.ip
2121
end

0 commit comments

Comments
 (0)