Skip to content

Commit 7fda61c

Browse files
committed
[F] Add ability to define request header to use as rate limiting key
Addresses an issue where proxies using non-standard forwarding headers were being rate limited on the proxy's IP
1 parent 841dd77 commit 7fda61c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

api/config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Dotenv
2828
class Railtie < Rails::Railtie
2929
def load
3030
Dotenv.load(
31+
root.join("./.env"),
3132
root.join("../.env.local"),
3233
root.join("../.env.#{Rails.env}"),
3334
root.join("../.env")

api/config/initializers/rack_attack.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939

4040
Rack::Attack.throttle throttler.ip_key, **throttler.options do |request|
4141
next unless request.env["manifold_env.throttled_category"] == throttler.category
42-
request.env["action_dispatch.remote_ip"]&.calculate_ip || request.ip
42+
43+
ENV["PROXY_CLIENT_IP_HEADER"].split(/,\s*/).map do |header|
44+
request.get_header(header)
45+
end.push(request.env["action_dispatch.remote_ip"].to_s, request.ip)
46+
.compact_blank
47+
.first
4348
end
4449
end
4550

docker/local.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ API_CABLE_PORT=13120
1111

1212
CLIENT_URL=http://localhost:13100
1313

14-
CLIENT_BROWSER_API_URL=https://web.manifold.orb.local
14+
CLIENT_BROWSER_API_URL=http://localhost:13110
1515
CLIENT_BROWSER_API_CABLE_URL=http://localhost:13120
16-
CLIENT_SERVER_API_URL=https://web.manifold.orb.local
16+
CLIENT_SERVER_API_URL=http://localhost:13110
1717

1818
CLIENT_SERVER_PROXIES=true
1919

0 commit comments

Comments
 (0)