SecureHeaders GatewayFilter 工厂
SecureHeaders GatewayFilter Factory
SecureHeaders GatewayFilter 工厂根据这篇博客文章的建议,向响应中添加了一系列头部信息。
以下标头(显示其默认值)已添加:
-
X-Xss-Protection:1 (mode=block) -
Strict-Transport-Security (max-age=631138519) -
X-Frame-Options (DENY) -
X-Content-Type-Options (nosniff) -
Referrer-Policy (no-referrer) -
Content-Security-Policy (default-src 'self' https:; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'; script-src https:; style-src 'self' https: 'unsafe-inline') -
X-Download-Options (noopen) -
X-Permitted-Cross-Domain-Policies (none)
要更改默认值,请在 spring.cloud.gateway.filter.secure-headers 命名空间中设置相应的属性。以下属性可用:
-
xss-protection-header -
strict-transport-security -
frame-options -
content-type-options -
referrer-policy -
content-security-policy -
download-options -
permitted-cross-domain-policies
要禁用默认值,请使用逗号分隔的值设置 spring.cloud.gateway.filter.secure-headers.disable 属性。以下示例展示了如何操作:
spring:
cloud:
gateway:
filter:
secure-headers:
disable: x-frame-options,strict-transport-security
要将 SecureHeaders 过滤器应用于特定路由,请将该过滤器添加到该路由的过滤器列表中。您可以使用参数自定义路由过滤器。路由配置会覆盖此路由的全局默认配置。
- id: secureheaders_route
uri: http://example.org
predicates:
- Path=/**
filters:
- name: SecureHeaders
args:
disable: x-frame-options
需要用小写的完整名称来禁用安全标头。
更多选项
您可以选择在响应中添加 Permissions-Policy 标头。权限策略(Permissions Policy)是一种安全标头,允许 Web 开发者管理网站可以利用哪些浏览器功能。请参阅 Permissions-Policy 和 Directives 来为您的环境进行配置。
spring:
cloud:
gateway:
filter:
secure-headers:
enable: permissions-policy
permissions-policy : geolocation=(self "https://example.com")
在上述示例中,Geolocation API 在所有浏览上下文中被禁用,除了其自身来源以及来源为 "https://example.com" 的上下文。Permissions-Policy 可以为每个路由单独配置。
- id: secureheaders_route
uri: http://anotherexample.org
predicates:
- Path=/**
filters:
- name: SecureHeaders
args:
disable: x-frame-options
enable: permissions-policy
permissions-policy : geolocation=("https://anotherexample.org")
当你启用 Permissions-Policy 且未显式配置任何指令时,将应用默认值。具体来说,此默认值会禁用大量标准化和实验性功能。此行为可能不适用于你的特定环境或使用场景。
Permissions-Policy 启用且无显式配置时的默认值:
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=()
你可以通过 DevTool 集成 查看 Chrome 的 Permissions Policy 功能列表。
配置环境头信息时,请务必检查浏览器控制台是否存在语法错误。