Class: Karst::Web::Locality
- Inherits:
-
Object
- Object
- Karst::Web::Locality
- Defined in:
- lib/karst/web/locality.rb
Overview
Determines whether a Rack peer is local without consulting proxy headers. WSL's NAT makes a Windows browser appear as the Linux VM's default gateway, so that one address is accepted when the process is verifiably running in WSL. Other private-network peers remain untrusted.
Instance Method Summary collapse
-
#initialize(environment: ENV, osrelease_path: "/proc/sys/kernel/osrelease", route_path: "/proc/net/route") ⇒ Locality
constructor
A new instance of Locality.
- #local?(remote_address) ⇒ Boolean
Constructor Details
#initialize(environment: ENV, osrelease_path: "/proc/sys/kernel/osrelease", route_path: "/proc/net/route") ⇒ Locality
Returns a new instance of Locality.
15 16 17 18 19 |
# File 'lib/karst/web/locality.rb', line 15 def initialize(environment: ENV, osrelease_path: "/proc/sys/kernel/osrelease", route_path: "/proc/net/route") @environment = environment @osrelease_path = osrelease_path @route_path = route_path end |
Instance Method Details
#local?(remote_address) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/karst/web/locality.rb', line 21 def local?(remote_address) address = IPAddr.new(remote_address.to_s) loopback?(address) || wsl_gateway == address rescue IPAddr::Error false end |