0

我将我的 tomcat (v8) 配置为全局使用严格的传输安全 (HSTS) 并防止点击劫持(在/opt/tomcat/conf/web.xml中):

<filter>
    <filter-name>httpHeaderSecurity</filter-name>
    <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
    <async-supported>true</async-supported>
</filter>

<filter-mapping>
    <filter-name>httpHeaderSecurity</filter-name>
    <url-pattern>/*</url-pattern>
    <url-pattern>*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

我也可以看到,它正在工作。如果我查看我的一个 webapps 的标题,它们包含:

Strict-Transport-Security: max-age=0
X-Frame-Options: DENY

但是:在分析我的 Apache Isis 项目的标头时,我发现缺少 X-Frame-Options 和 Strict-Transport-Security。我的猜测是,Isis 项目的 web.xml 中的一个过滤器存在问题,它覆盖了全局设置。我试图注释掉其中的一些,但要么应用程序无法正常工作,要么应用程序正在工作,但标题仍然不存在......

我的项目 web.xml 是

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>...</display-name>

    <welcome-file-list>
        <welcome-file>about/index.html</welcome-file>
    </welcome-file-list>

    <!-- shiro security configuration -->
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>ShiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>ShiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--
    determines which additional configuration files to search for
     -->
    <context-param>
        <param-name>isis.viewers</param-name>
        <param-value>wicket,restfulobjects</param-value>
    </context-param>

    <!--
    -
    - config specific to the wicket-viewer
    -
    -->
    <filter>
        <filter-name>WicketFilter</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>domainapp.webapp.MyApplication</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>WicketFilter</filter-name>
        <url-pattern>/wicket/*</url-pattern>
    </filter-mapping>

    <context-param>
        <param-name>configuration</param-name>
        <param-value>deployment</param-value>
    </context-param>

</web-app>

我的项目 web.xml 的哪个部分可能导致 tomcat 不使用默认启用的 HSTS 和我的 ISIS 项目的点击劫持预防?

4

1 回答 1

0

感谢 ASF-ISIS-Slack-Channel 上的 Andy Huber 提示,我得以解决我的问题。

Andys 提示过滤器优先级由 web.xml 文件中的出现顺序定义。所以我在项目web.xml的开头添加了安全相关的过滤器。

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>...</display-name>

    <welcome-file-list>
        <welcome-file>about/index.html</welcome-file>
    </welcome-file-list>

    <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
        <url-pattern>*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secured</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <!-- shiro security configuration -->
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>

   ...
</web-app>

遗憾的是,我仍然不知道与 ISIS 相关的过滤器的哪一部分导致了最初的问题。但只要我的 tomcat 安全性有所提高,我就可以忍受;-)

于 2020-08-19T13:02:22.430 回答