I am trying to block access to my REST development - applying Tomcat - from outside of my laptop. The solution I have found promising, is to introduce a valve for Tomcat:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d \.\d \.\d |::1"/>
It works on Linux: The intention is, that localhost:8080
accesses the local Tomcat installation with the expected, while any access <my-laptop-IP>:8080
from anywhere on the intranet will be denied.
Unfortunately this works fine on my Buster laptop (a Linux VirtualBox guest) but neither on my Win10 guest installation nor on a native Win10 laptop: That valve on Windows blocks localhost:8080
access to Tomcat as well, although I think, the allow
attribute shall allow it. (Means my REST developent is blocked on Win10 with that valve.)
My question is: Why does the above valve behaves not as expected on Win10 installations?
p.s. I tested with tomcat-9 and tomcat-10.
CodePudding user response:
On most modern OS localhost
resolves to the IPv6 address ::1
first and then to the IPv6 address 127.0.0.1
.
Depending on the connector you are using the IPv6 address for localhost
may appear in the abbreviated form ::1
or the full form 0:0:0:0:0:0:0:1
, therefore your regular expression should allow both representations:
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d \.\d \.\d |::1|0:0:0:0:0:0:0:1"/>