HTTP Security: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 37: Line 37:
| valign="top" |
| valign="top" |
* [https://content-security-policy.com/ Content Security Policy Reference]
* [https://content-security-policy.com/ Content Security Policy Reference]
* [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy Content-Security-Policy]
* [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src CSP » <code>default-src</code>]
* [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src CSP » <code>default-src</code>]
* [https://www.validbot.com/header/Permissions-Policy.html Permissions-Policy]
* [https://www.validbot.com/header/Permissions-Policy.html Permissions-Policy]

Revision as of 08:57, 6 February 2024

@Component
@WebFilter(urlPatterns = {"/*"})
public class ResponseHeaderWebFilter implements Filter {

    @Override
    public void doFilter(
            ServletRequest request,
            ServletResponse response, FilterChain chain
    ) throws IOException, ServletException {
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        httpServletResponse.setHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:;");
        httpServletResponse.setHeader("Strict-Transport-Security", "max-age=31536000 ; includeSubDomains ; preload");
        httpServletResponse.setHeader("Permissions-Policy", "geolocation 'self'; payment 'none'");
        httpServletResponse.setHeader("X-Content-Type-Options", "nosniff");
        httpServletResponse.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
        httpServletResponse.setHeader("X-Frame-Options", "DENY");
        chain.doFilter(request, response);
    }
}

Content Security Policy

Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:;
Content-Security-Policy: default-src 'self' cdn.chorke.org;

Permissions Policy

Permissions-Policy: camera=(), microphone=(), geolocation=()
Permissions-Policy: geolocation=("https://advertiser.example.com" "https://analytics.example.com")

References