Class: ActionDispatch::RemoteIp
- Inherits:
-
Object
- Object
- ActionDispatch::RemoteIp
- Defined in:
- actionpack/lib/action_dispatch/middleware/remote_ip.rb
Defined Under Namespace
Classes: GetIp, IpSpoofAttackError
Constant Summary
- TRUSTED_PROXIES =
IP addresses that are "trusted proxies" that can be stripped from the comma-delimited list in the X-Forwarded-For header. See also: en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
%r{ ^127\.0\.0\.1$ | # localhost ^(10 | # private IP 10.x.x.x 172\.(1[6-9]|2[0-9]|3[0-1]) | # private IP in the range 172.16.0.0 .. 172.31.255.255 192\.168 # private IP 192.168.x.x )\. }x
Instance Attribute Summary (collapse)
-
- (Object) check_ip
readonly
Returns the value of attribute check_ip.
-
- (Object) proxies
readonly
Returns the value of attribute proxies.
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (RemoteIp) initialize(app, check_ip_spoofing = true, custom_proxies = nil)
constructor
A new instance of RemoteIp.
Constructor Details
- (RemoteIp) initialize(app, check_ip_spoofing = true, custom_proxies = nil)
A new instance of RemoteIp
18 19 20 21 22 23 24 25 26 27 |
# File 'actionpack/lib/action_dispatch/middleware/remote_ip.rb', line 18 def initialize(app, check_ip_spoofing = true, custom_proxies = nil) @app = app @check_ip = check_ip_spoofing if custom_proxies custom_regexp = Regexp.new(custom_proxies) @proxies = Regexp.union(TRUSTED_PROXIES, custom_regexp) else @proxies = TRUSTED_PROXIES end end |
Instance Attribute Details
- (Object) check_ip (readonly)
Returns the value of attribute check_ip
16 17 18 |
# File 'actionpack/lib/action_dispatch/middleware/remote_ip.rb', line 16 def check_ip @check_ip end |
- (Object) proxies (readonly)
Returns the value of attribute proxies
16 17 18 |
# File 'actionpack/lib/action_dispatch/middleware/remote_ip.rb', line 16 def proxies @proxies end |
Instance Method Details
- (Object) call(env)
29 30 31 32 |
# File 'actionpack/lib/action_dispatch/middleware/remote_ip.rb', line 29 def call(env) env["action_dispatch.remote_ip"] = GetIp.new(env, self) @app.call(env) end |