Skip to content

ContentSecurityPolicyConfig: Add Report-To Header #18783

@bahuma20

Description

@bahuma20

Expected Behavior

Add configuration option for the Report-to HTTP-header to the CspSecurityPolicyConfig.

Example how this could look like:

public SecurityFilterChain securityFilterChain(HttpSecurity http) {
  return http.headers(headers -> 
    headers.contentSecurityPolicy(csp ->
      csp
        .reportOnly()
        .reportingEndpoints("csp-report-endpoint=\"https://example.com/csp-reports\"")
        .policyDirectives("default-src 'self'; report-to csp-report-endpoint")
    )
  ).build();
}

Current Behavior
To get the same thing to work right now, the code looks like this:

public SecurityFilterChain securityFilterChain(HttpSecurity http) {
  return http.headers(headers -> headers
    .contentSecurityPolicy(csp ->csp
      .reportOnly()
      .policyDirectives("default-src 'self'; report-to csp-report-endpoint")
    )
    .addHeaderWriter((request, response) -> response.setHeader("Reporting-Endpoints", "csp-report-endpoint=\"https://example.com/csp-reports\""))
  ).build();
}

This is unnecessary complex.

Context
The Reporting-Endpoints HTTP-header and report-to directive is the sucessor to the report-uri directive which is deprecated.

So everyone implementing a CSP with reporting should set the Reporting-Endpoints HTTP-header.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP#violation_reporting for details.

Alternative Suggestion: Full-blown API that allows building the policy and headers declaratively, with support for configuration via properties. (So instead of just specifying a string with a policy, you would use a typed Java api which declares the directives to add, what values those directives have, and where to report to. There could also be support for nonces)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions