1class CloudFrontRemoteIp < ActionDispatch::RemoteIp |
|
2 HTTP_X_AMZ_CF_ID = 'HTTP_X_AMZ_CF_ID'.freeze |
|
3 REMOTE_IP = 'action_dispatch.remote_ip'.freeze |
|
|
5 def call(env) |
6 env[REMOTE_IP] = CloudFrontGetIp.new(env, self) |
|
7 @app.call(env) |
|
8 end |
|
10 class CloudFrontGetIp < GetIp |
|
11 protected
|
|
13 def filter_proxies(ips) |
|
14 # If the request is coming from CloudFront we |
|
15 # can safely remove the rightmost ip address |
|
16 # filtering out the VPC ip address |
|
17 if @env.key?(HTTP_X_AMZ_CF_ID) |
|
18 super(ips)[1..-1] |
|
19 else |
|
20 super(ips) |
|
21 end |
|
22 end |
|
23 end |
|
24end |