舞台裏

Qiita が表でこっちが裏。こっそりやっていく。

20.1.8 Referrer Policy

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

Referer ポリシーは Web アプリケーションがユーザーが最後にアクセスしていたページを含んだ referer フィールドを管理するようできるメカニズムです。

Spring Security’s approach is to use Referrer Policy header, which provides different policies:

Spring Security のアプローチは、異なるポリシーを提供する Referer Policy ヘッダーを使うというものです。

Referrer-Policy: same-origin

The Referrer-Policy response header instructs the browser to let the destination knows the source where the user was previously.

レスポンスヘッダの Referer-Policy はユーザが以前いた場所を知らせるようブラウザに指示します。

Configuring Referrer Policy

Spring Security doesn’t add Referrer Policy header by default.

Spring Security はデフォルトでは Referer Policy ヘッダーを追加しません。

You can enable the Referrer-Policy header using XML configuration with the <referrer-policy> element as shown below:

あなたは、 XML 設定では <referer-policy> タグを次のように使用することで Referer-Policy ヘッダーを有効にできます。

<http>
    <!-- ... -->

    <headers>
        <referrer-policy policy="same-origin" />
    </headers>
</http>

Similarly, you can enable the Referrer Policy header using Java configuration as shown below:

同様に、あなたは Java Configuration で次のようにして Referer-Policy を有効にできます。

@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    // ...
    .headers()
        .referrerPolicy(ReferrerPolicy.SAME_ORIGIN);
}
}