Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2975-Suggestion-Add-Permissions-Policy-as-configurable-option-to-Sec… #3353

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,55 @@ The following properties are available:
To disable the default values set the `spring.cloud.gateway.filter.secure-headers.disable` property with comma-separated values.
The following example shows how to do so:

[source]
.application.yml
[source,yaml]
----
spring.cloud.gateway.filter.secure-headers.disable=x-frame-options,strict-transport-security
spring:
cloud:
gateway:
filter:
secure-headers:
disable: x-frame-options,strict-transport-security
----

NOTE: The lowercase full name of the secure header needs to be used to disable it..
NOTE: The lowercase full name of the secure header needs to be used to disable it.

== Further options

You may opt in to add the `Permissions-Policy` header to the response. Permissions Policy is a security header
that allows web developers to manage which browser features a website can utilize. Please see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy[Permissions-Policy] and
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#directives[Directives] to configure it
for your environment.

.application.yml
[source,yaml]
----
spring:
cloud:
gateway:
filter:
secure-headers:
enable: permissions-policy
permissions-policy : geolocation=(self "https://example.com")
----

In the above https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy/geolocation[example]
the Geolocation API is disabled within all browsing contexts except for its own origin and those whose origin is "https://example.com".

WARNING: When you enable Permissions-Policy and do not explicitly configure any directives, a default value will be applied.
Specifically, this default value disables a wide range of standardized and experimental features.
This behavior might not be appropriate for your specific environment or use case.

Permissions-Policy default value when enabled and no explicit configuration:

`Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(),
display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(),
fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(),
payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(),
web-share=(), xr-spatial-tracking=()`


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].

When you configure the header value for your environment, make sure to check the browser console for syntax errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
test:
hostport: httpbin.org:80
# hostport: localhost:5000
uri: http://${test.hostport}
#uri: lb://httpbin


spring:
cloud:
gateway:
filter:
secure-headers:
disable: x-frame-options,strict-transport-security
enable: permissions-policy
permissions-policy : geolocation=("https://example.com")
default-filters:
#- PrefixPath=/httpbin
#- AddResponseHeader=X-Response-Default-Foo, Default-Bar

routes:
# =====================================
# to run server
# $ wscat --listen 9000
# to run client
# $ wscat --connect ws://localhost:8080/echo
- id: websocket_test
uri: ws://localhost:9000
order: 9000
predicates:
- Path=/echo
# =====================================
- id: default_path_to_httpbin
uri: ${test.uri}
order: 10000
predicates:
- Path=/**
filters:
- name: SecureHeaders

logging:
level:
org.springframework.cloud.gateway: TRACE
org.springframework.http.server.reactive: DEBUG
org.springframework.web.reactive: DEBUG
reactor.ipc.netty: DEBUG
reactor.netty: DEBUG

management.endpoints.web.exposure.include: '*'


Loading