tomcat远程地址筛选器不工作-tomcat 9.0.x

bjp0bcyl  于 2021-10-10  发布在  Java
关注(0)|答案(2)|浏览(300)

我正试图限制我的一些应用程序端点用于公共internet。为此,我尝试了tomcat的远程地址过滤器。我将过滤器添加到应用程序的web.xml中 (D:\apache-tomcat-9.0.22\webapps\myApp\WEB-INF) . 但它根本不起作用。我两个都试过了 <param-name>allow</param-name> <param-name>deny</param-name> 和我的团队成员的特定ip地址,但仍然是我们都可以访问的。每次更改时,我都会重新启动tomcat。

<filter>
    <filter-name>Remote Address Filter</filter-name>
    <filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
    <init-param>
      <param-name>deny</param-name> <!-- Tried to block my team mate's IP -->
      <param-value>10\.142\.16\.1</param-value>  <!-- My team mates IP address -->

      <!-- param-value>127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1</param-value -->

    </init-param>
 </filter>

 <filter-mapping>
    <filter-name>Remote Address Filter</filter-name>
    <url-pattern>/myApp/context/* </url-pattern>
 </filter-mapping>

我也试过了,就像在文档中一样 <param-value>127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1</param-value> 但我的队友和我自己仍然可以毫无问题地访问这些页面。
我的环境详细信息>>

I've used a standalone Tomcat. Servlet engine: [Apache Tomcat/9.0.22]
Running with Spring Boot v2.1.3.RELEASE, Spring v5.1.5.RELEASE

问题出在哪里?有没有办法确定 web.xml 变化真的反映了什么?

6rqinv9w

6rqinv9w1#

我发现了问题。问题在于url模式。我们不应该将应用程序上下文添加到url模式中。
现在可以使用以下设置。

<url-pattern>/actuator/health </url-pattern>
jmp7cifd

jmp7cifd2#

一种可能的解决方案是在application/meta inf/context.xml中添加限制。对于整个应用程序,这将导致403。您可以在tomcat的webapps\manager\meta-inf中看到实现。

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>

相关问题