1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Add support for Feature-Policy security header

This commit is contained in:
Vedran Pavic
2018-08-15 22:05:10 +02:00
committed by Rob Winch
parent 9c478257d4
commit c6ea447cc0
9 changed files with 368 additions and 5 deletions
@@ -241,6 +241,7 @@ This allows HTTPS websites to resist impersonation by attackers using mis-issued
** `Content-Security-Policy` or `Content-Security-Policy-Report-Only` - Can be set using the <<nsa-content-security-policy,content-security-policy>> element.
https://www.w3.org/TR/CSP2/[Content Security Policy (CSP)] is a mechanism that web applications can leverage to mitigate content injection vulnerabilities, such as cross-site scripting (XSS).
** `Referrer-Policy` - Can be set using the <<nsa-referrer-policy,referrer-policy>> element, https://www.w3.org/TR/referrer-policy/[Referrer-Policy] is a mechanism that web applications can leverage to manage the referrer field, which contains the last page the user was on.
** `Feature-Policy` - Can be set using the <<nsa-feature-policy,feature-policy>> element, https://wicg.github.io/feature-policy/[Feature-Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
[[nsa-headers-attributes]]
===== <headers> Attributes
@@ -272,6 +273,7 @@ The default is false (the headers are enabled).
* <<nsa-cache-control,cache-control>>
* <<nsa-content-security-policy,content-security-policy>>
* <<nsa-content-type-options,content-type-options>>
* <<nsa-feature-policy,feature-policy>>
* <<nsa-frame-options,frame-options>>
* <<nsa-header,header>>
* <<nsa-hpkp,hpkp>>
@@ -459,6 +461,24 @@ Default "no-referrer".
[[nsa-feature-policy]]
==== <feature-policy>
When enabled adds the https://wicg.github.io/feature-policy/[Feature Policy] header to the response.
[[nsa-feature-policy-attributes]]
===== <feature-policy> Attributes
[[nsa-feature-policy-policy-directives]]
* **policy-directives**
The security policy directive(s) for the Feature-Policy header.
[[nsa-feature-policy-parents]]
===== Parent Elements of <feature-policy>
* <<nsa-headers,headers>>
[[nsa-frame-options]]
==== <frame-options>
When enabled adds the http://tools.ietf.org/html/draft-ietf-websec-x-frame-options[X-Frame-Options header] to the response, this allows newer browsers to do some security checks and prevent http://en.wikipedia.org/wiki/Clickjacking[clickjacking] attacks.
@@ -714,6 +714,56 @@ protected void configure(HttpSecurity http) throws Exception {
----
[[headers-feature]]
==== Feature Policy
https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
[source]
----
Feature-Policy: geolocation 'self'
----
With Feature Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site.
These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.
[[headers-feature-configure]]
===== Configuring Feature Policy
Spring Security *_doesn't add_* Feature Policy header by default.
You can enable the Feature-Policy header using XML configuration with the <<nsa-feature-policy,<feature-policy>>> element as shown below:
[source,xml]
----
<http>
<!-- ... -->
<headers>
<feature-policy policy-directives="geolocation 'self'" />
</headers>
</http>
----
Similarly, you can enable the Feature Policy header using Java configuration as shown below:
[source,java]
----
@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers()
.featurePolicy("geolocation 'self'");
}
}
----
[[headers-custom]]
=== Custom Headers
Spring Security has mechanisms to make it convenient to add the more common security headers to your application.