|
29 | 29 | # But we're going to try a more generous 3 per second over |
30 | 30 | # 1 minute instead. |
31 | 31 | # |
32 | | -# May 1 2024: Limiting much more extensively to 30 req per minute -- one per every two seconds |
33 | | -# averaging over a minute -- after bot attacks costing us money from s3. |
34 | 32 | Rack::Attack.throttle('req/ip', limit: 180, period: 1.minutes) do |req| |
35 | 33 | # On heroku, we may be delivering assets via rack, I think. |
36 | 34 | # We also try to exempt our "api" responses from rate limit, although |
|
44 | 42 | ) |
45 | 43 | end |
46 | 44 |
|
47 | | -# But we're also going to TRACK at half that limit, for ease |
48 | | -# of understanding what's going on in our logs |
49 | | -Rack::Attack.track("req/ip_track", limit: 90, period: 1.minute) do |req| |
50 | | - req.ip unless req.path.start_with?('/assets') |
51 | | -end |
52 | | - |
53 | 45 | # And we want to log rack-attack track and throttle notifications. But we get |
54 | 46 | # a notification every time an IP has exceeded the limit -- that's far too |
55 | 47 | # many to log every time, could be many per second when it's exceeding limits. |
|
73 | 65 | rack_env = rack_request.env |
74 | 66 | match_name = rack_env["rack.attack.matched"] |
75 | 67 |
|
76 | | - # only log here for our `req/` throttles and tracks above, not our other ones such as bot detect |
77 | | - next unless match_name.start_with?("req/") |
| 68 | + # only log here for our `req/` throttle above, not our other ones such as bot detect |
| 69 | + next unless match_name == "req/ip" |
78 | 70 |
|
79 | 71 | match_data = rack_env["rack.attack.match_data"] |
80 | 72 | match_data_formatted = match_data.slice(:count, :limit, :period).map { |k, v| "#{k}=#{v}"}.join(" ") |
|
0 commit comments