package org.t246osslab.easybuggy.core.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Filter for security
 */
@WebFilter(urlPatterns = { "/*" })
public class SecurityFilter implements Filter {

    /**
     * Default constructor.
     */
    public SecurityFilter() {
        // Do nothing
    }

    /**
     * Call {@link #doFilter(HttpServletRequest, HttpServletResponse, FilterChain)}.
     * 
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
            ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        String target = request.getRequestURI();

        /* Prevent clickjacking if target is not /admins/clickjacking/... */
        if (!target.startsWith("/admins/clickjacking")) {
            response.addHeader("X-FRAME-OPTIONS", "DENY");
        }
        chain.doFilter(req, res);
    }

    @Override
    public void destroy() {
        // Do nothing
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // Do nothing
    }
}

@@ -1226,17 +1226,17 @@
 kjacking
-/
+ 
 ... */%0A 
@@ -1288,24 +1288,24 @@
 acking%22)) %7B%0A
-
             
@@ -1361,16 +1361,307 @@
       %7D%0A
+        /* Prevent Content-Type sniffing */%0A        response.addHeader(%22X-Content-Type-Options%22, %22nosniff%22);%0A        %0A        /* Prevent XSS if target is not /xss ... */%0A        if (!target.startsWith(%22/xss%22)) %7B%0A            response.addHeader(%22X-XSS-Protection%22, %221; mode=block%22);%0A        %7D%0A
         

Add secure headers to responses