This section describes the configuration for Apache Tomcat to prevent clickjacking at the server level by setting the X-Frame-Options header through the global web.xml. Setting values ensure that all applications that are deployed (such as Titan) inherit the defined security behavior automatically.
To secure Tomcat against clickjacking using the global filter, complete the following steps.
- Stop the Tomcat instance.
- Navigate to Tomcat installation directory.
- In Tomcat installation directory, navigate to conf directory.
- Open web.xml using a text editor.
- In the text editor, scroll down before the </web-app> closing tag.
- Add the following filter configuration.
<filter> <filter-name>ClickjackingFilter</filter-name> <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class> <init-param> <param-name>antiClickJackingEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>antiClickJackingOption</param-name> <param-value>DENY</param-value> <!-- Options: SAMEORIGIN, ALLOW-FROM --> </init-param> </filter> <filter-mapping> <filter-name>ClickjackingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>The options associated with filter are:
- DENY: No page is displayed in a frame. This is the most secured option.
- SAMEORIGIN: Allows Titan to be accessed within current domain. This option prevents Titan from being embedded in an <iframe> or <frame> on any domain other than itself.
- ALLOW-FROM https://example.com: This option allows the page from the specified domain.
- Restart Tomcat.