Reputation:
As I found it can be easily set in Apache server: x-frame-options=allow in httpd-conf file
but how about tomcat? I am working with a version 7.0.57
Upvotes: 7
Views: 41524
Reputation: 731
after tomcat 7.0.63
<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>
</filter>
For filter-mapping part I have added.
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Upvotes: 5
Reputation: 6197
In Tomcat you need to use filters for that:
First, implement your own Filter
. Something like this:
public class XFrameHeaderFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException {
((HttpServletResponse) resp).setHeader("x-frame-options", "allow");
chain.doFilter(req, resp);
}
}
Second, make this filter a part of your web.xml:
<filter>
<filter-name>x-frame-header</filter-name>
<filter-class>XFrameHeaderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>x-frame-header</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Upvotes: 9