x-frame-optionstuckey-urlrewrite-filter

URL Rewrite Missing X-Frame-Options in Header


I'm using Tomcat 8 and Tuckey urlrewrite to remove ".jsp" from my web page URLs. Its working fine but I noticed the X-Frame-Options in the response header are not present when urlrewrite redirects from a page. mysite.com/Home translates to mysite.com/Home.jsp but the X-Frame options are not set. They are set for all the pages that I exclude from urlrewirte such as mysite.com/picture.png. Any guidance would be appreciated.

Web.xml

  <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
  </filter>

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

<filter>
    <filter-name>httpHeaderSecurity</filter-name>
    <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
    <init-param>
        <param-name>antiClickJackingOption</param-name>
        <param-value>SAMEORIGIN</param-value>
    </init-param>
    <init-param>
      <param-name>antiClickJackingEnabled</param-name>
      <param-value>true</param-value>
    </init-param>
</filter>



urlrewrite.xml:


<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE urlrewrite
    PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
    "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">

<urlrewrite>
    <rule match-type="regex">
        <condition type="request-url" operator="notequal">jsp$</condition>
        <condition type="request-url" operator="notequal">html$</condition>
        <condition type="request-url" operator="notequal">pdf$</condition>
        <condition type="request-url" operator="notequal">txt$</condition>
        <condition type="request-url" operator="notequal">apk$</condition>
        <condition type="request-url" operator="notequal">app$</condition>
        <condition type="request-url" operator="notequal">zip$</condition>

        <condition type="request-url" operator="notequal">avi$</condition>
        <condition type="request-url" operator="notequal">flv$</condition>
        <condition type="request-url" operator="notequal">mp4$</condition>
        <condition type="request-url" operator="notequal">mov$</condition>
        <condition type="request-url" operator="notequal">wmv$</condition>
        <condition type="request-url" operator="notequal">mp3$</condition>
        <condition type="request-url" operator="notequal">wav$</condition>
        <condition type="request-url" operator="notequal">jpg$</condition>
        <condition type="request-url" operator="notequal">png$</condition>

        <condition type="request-url" operator="notequal">/media/.*</condition>
        <condition type="request-url" operator="notequal">/css/.*</condition>
        <condition type="request-url" operator="notequal">/img/.*</condition>
        <condition type="request-url" operator="notequal">/js/.*</condition>

        <!-- negative look foward and back expresion to foward match pages that do not end in .jsp -->
        <from>/.+(?:(?!jsp).).$</from>
        <to type="forward">%{request-uri}.jsp</to>
    </rule>
</urlrewrite>

Solution

  • So this turns out not to be a problem with URL Rewrite but a missing for the httpSecurityHeader filter that contained the x-frame-options. After adding the mapping "/*" every file now has the antiClickJacking options set. Below is the web.xml settings that make that happen.

    <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <init-param>
            <param-name>antiClickJackingOption</param-name>
            <param-value>SAMEORIGIN</param-value>
        </init-param>
        <init-param>
          <param-name>antiClickJackingEnabled</param-name>
          <param-value>true</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>