public class GrailsSecurityHeadersFilter extends OncePerRequestFilter
Applies baseline browser hardening response headers.
Headers are written immediately before the response commits (or when the filter chain returns, whichever comes first) and only when nothing further down the chain has already set them, so a controller, an interceptor, another filter or Spring Security's header writers running inside this filter win over the Grails defaults. A filter that runs outside this one and, like most of Spring Security's header writers, only fills headers that are still absent finds the Grails value already in place; see GrailsSecurityHeadersAutoConfiguration for the ordering.
When grails.security.headers.defaults is auto and the request is
detected as having come through a reverse proxy, the built-in default values are
suppressed and only headers the application configured explicitly are applied, for
deployments where the proxy owns these headers and the application cannot see what it
adds. See GrailsSecurityHeadersProperties.Defaults for the controlling
setting.
When GrailsSecurityHeadersProperties.isEnabled is false the filter
passes every request through untouched. The auto-configuration does not register the
filter at all in that case; the check here covers filters an application constructs
itself.
| Fields inherited from class | Fields |
|---|---|
class OncePerRequestFilter |
ALREADY_FILTERED_SUFFIX |
| Constructor and description |
|---|
GrailsSecurityHeadersFilter(GrailsSecurityHeadersProperties properties) |
GrailsSecurityHeadersFilter(GrailsSecurityHeadersProperties properties, boolean reverseProxyConfigured)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
protected boolean |
shouldNotFilterErrorDispatch() |
| Methods inherited from class | Name |
|---|---|
class OncePerRequestFilter |
afterPropertiesSet, destroy, doFilter, equals, getClass, getEnvironment, getFilterConfig, hashCode, init, notify, notifyAll, setBeanName, setEnvironment, setServletContext, toString, wait, wait, wait |
properties - the header configurationreverseProxyConfigured - whether the deployment is known to sit behind a reverse
proxy from configuration alone (for example a forwarded-headers strategy or an active
cloud platform), independent of any per-request signal