I want to add below headers in the response header in Spring MVC :
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
I have written below code in MvcConfig file which extends WebMvcConfigurerAdapter.
@Bean
public Filter securityHeadersFilter() {
return new OncePerRequestFilter(){
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
filterChain.doFilter(request, response);
response.setHeader("X-XSS-Protection", "1; mode=block");
response.setHeader("X-Content-Type-Options", "nosniff");
}
};
}
now, when I hit request, and see the response header on Browser, these two headers doesn't come. I nowhere registered the filter with urlPattern. Is this the problem or I missed some other thing? if urlpattern configuration is the problem then plz tell me how and where to configure it.
Anyway, My ultimate goal is to get above two security headers in Response header.