SecureHeaders GatewayFilter ファクトリ
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-headerstrict-transport-securityframe-optionscontent-type-optionsreferrer-policycontent-security-policydownload-optionspermitted-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 開発者が Web サイトで利用できるブラウザー機能を管理できるセキュリティヘッダーです。環境に合わせて設定するには、権限 - ポリシー [Mozilla] とディレクティブ [Mozilla] を参照してください。
spring:
cloud:
gateway:
filter:
secure-headers:
enable: permissions-policy
permissions-policy : geolocation=(self "https://example.com")上記の例 [Mozilla] では、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=()
| Chrome の権限ポリシー機能リストは、DevTool 統合 (英語) で確認できます。 |
環境に合わせてヘッダー値を構成するときは、ブラウザーコンソールで構文エラーがないか必ず確認してください。