Skip to content

Commit 85ab7d9

Browse files
#2975-Suggestion-Add-Permissions-Policy-as-configurable-option-to-SecureHeaders-GatewayFilter
- added Permissions-Policy header as an opt-in header & default value - updated documentation with Permissions-Policy and resources - updated tests to include Permissions-Policy - SecurityHeaders and Permissions-Policy may be configured globally / per route - updated structure of public methods and class members to match previous version structure Fixes gh-2975 Signed-off-by: Jörg Richter <[email protected]>
1 parent 4e0cc2e commit 85ab7d9

File tree

6 files changed

+659
-154
lines changed

6 files changed

+659
-154
lines changed

docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/secureheaders-factory.adoc

+80-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,87 @@ The following properties are available:
2929
To disable the default values set the `spring.cloud.gateway.filter.secure-headers.disable` property with comma-separated values.
3030
The following example shows how to do so:
3131

32-
[source]
32+
.application.yml
33+
[source,yaml]
3334
----
34-
spring.cloud.gateway.filter.secure-headers.disable=x-frame-options,strict-transport-security
35+
spring:
36+
cloud:
37+
gateway:
38+
filter:
39+
secure-headers:
40+
disable: x-frame-options,strict-transport-security
3541
----
3642

37-
NOTE: The lowercase full name of the secure header needs to be used to disable it..
43+
To apply the `SecureHeaders` filter to a specific route, add the filter to the list of filters of that route.
44+
You can customize the route filter using arguments. Route configuration overrides the global default configuration for this route.
3845

46+
.application.yml
47+
[source,yaml]
48+
----
49+
- id: secureheaders_route
50+
uri: http://example.org
51+
predicates:
52+
- Path=/**
53+
filters:
54+
- name: SecureHeaders
55+
args:
56+
disable: x-frame-options
57+
----
58+
59+
NOTE: The lowercase full name of the secure header needs to be used to disable it.
60+
61+
== Further options
62+
63+
You may opt in to add the `Permissions-Policy` header to the response. Permissions Policy is a security header
64+
that allows web developers to manage which browser features a website can utilize. Please see
65+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy[Permissions-Policy] and
66+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#directives[Directives] to configure it
67+
for your environment.
68+
69+
.application.yml
70+
[source,yaml]
71+
----
72+
spring:
73+
cloud:
74+
gateway:
75+
filter:
76+
secure-headers:
77+
enable: permissions-policy
78+
permissions-policy : geolocation=(self "https://example.com")
79+
----
80+
81+
In the above https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy/geolocation[example]
82+
the Geolocation API is disabled within all browsing contexts except for its own origin and those whose origin is "https://example.com".
83+
The Permissions-Policy may be configured separately for each route.
84+
85+
.application.yml
86+
[source,yaml]
87+
----
88+
- id: secureheaders_route
89+
uri: http://anotherexample.org
90+
predicates:
91+
- Path=/**
92+
filters:
93+
- name: SecureHeaders
94+
args:
95+
disable: x-frame-options
96+
enable: permissions-policy
97+
permissions-policy : geolocation=("https://anotherexample.org")
98+
----
99+
100+
WARNING: When you enable Permissions-Policy and do not explicitly configure any directives, a default value will be applied.
101+
Specifically, this default value disables a wide range of standardized and experimental features.
102+
This behavior might not be appropriate for your specific environment or use case.
103+
104+
Permissions-Policy default value when enabled and no explicit configuration:
105+
106+
`Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(),
107+
display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(),
108+
fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(),
109+
payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(),
110+
web-share=(), xr-spatial-tracking=()`
111+
112+
113+
NOTE: You can check the Permissions Policy feature list for Chrome with https://developer.chrome.com/docs/privacy-security/permissions-policy#chrome_devtools_integration[DevTool Integration].
114+
115+
When you configure the header value for your environment, make sure to check the browser console for syntax errors.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
test:
2+
hostport: httpbin.org:80
3+
# hostport: localhost:5000
4+
uri: http://${test.hostport}
5+
#uri: lb://httpbin
6+
7+
8+
spring:
9+
cloud:
10+
gateway:
11+
filter:
12+
default-filters:
13+
#- PrefixPath=/httpbin
14+
#- AddResponseHeader=X-Response-Default-Foo, Default-Bar
15+
16+
routes:
17+
# =====================================
18+
# to run server
19+
# $ wscat --listen 9000
20+
# to run client
21+
# $ wscat --connect ws://localhost:8080/echo
22+
- id: websocket_test
23+
uri: ws://localhost:9000
24+
order: 9000
25+
predicates:
26+
- Path=/echo
27+
# =====================================
28+
- id: default_path_to_httpbin_secureheaders
29+
uri: ${test.uri}
30+
order: 10000
31+
predicates:
32+
- Path=/**
33+
filters:
34+
- name: SecureHeaders
35+
args:
36+
disable: x-frame-options
37+
enable: permissions-policy
38+
permissions-policy : geolocation=("https://example.net")
39+
40+
logging:
41+
level:
42+
org.springframework.cloud.gateway: TRACE
43+
org.springframework.http.server.reactive: DEBUG
44+
org.springframework.web.reactive: DEBUG
45+
reactor.ipc.netty: DEBUG
46+
reactor.netty: DEBUG
47+
48+
management.endpoints.web.exposure.include: '*'
49+
50+

0 commit comments

Comments
 (0)