SameSite=<samesite-value> 省略可
クロスサイトリクエストでクッキーを送信するかどうかを制御し、クロスサイトリクエストフォージェリ攻撃 (CSRF)
に対するある程度の防御を提供します。使用可能な属性値は以下の通りです。
Strict
ブラウザーが同一サイトのリクエストに対してのみクッキーを送信する
ことを意味します。つまり、クッキーを設定したのと同じサイトから発信されるリクエストのことです。リクエストが異なるドメインやスキームから発信された場合(同じドメインであっても)、 SameSite=Strict 属性のクッキーは送信されません
。Lax
画像やフレームを読み込むリクエストのようなクロスサイトリクエストではクッキーを送信しませんが、ユーザーが外部サイトから元のサイトに移動するとき(例えば、リンクをたどるとき)には送信されることを意味します。 これは SameSite 属性が指定されていない場合の既定の動作です。
None
ブラウザーがクロスサイトと同一サイトの両方のリクエストでクッキーを送信することを意味します。 この値を設定する際には、 Secure 属性も設定する必要があります。 SameSite=None; Secure のようにします。
The Strict value will prevent the cookie from being sent by the browser to the target site in all cross-site browsing context, even when following a regular link. For example, if a GitHub-like website uses the Strict value, a logged-in GitHub user who tries to follow a link to a private GitHub project posted on a corporate discussion forum or email, the user will not be able to access the project because GitHub will not receive a session cookie. Since a bank website would not allow any transactional pages to be linked from external sites, so the Strict flag would be most appropriate for banks.
If a website wants to maintain a user's logged-in session after the user arrives from an external link, SameSite's default Lax value provides a reasonable balance between security and usability. If the GitHub scenario above uses a Lax value instead, the session cookie would be allowed when following a regular link from an external website while blocking it in CSRF-prone request methods such as POST. Only cross-site-requests that are allowed in Lax mode have top-level navigations and use safe HTTP methods.
For more details on the SameSite values, check the following section from the rfc.
Example of cookies using this attribute:
Set-Cookie: JSESSIONID=xxxxx; SameSite=Strict Set-Cookie: JSESSIONID=xxxxx; SameSite=Lax
All desktop browsers and almost all mobile browsers now support the SameSite attribute. To track the browsers implementing it and know how the attribute is used, refer to the following service. Note that Chrome has announced that they will mark cookies as SameSite=Lax by default from Chrome 80 (due in February 2020), and Firefox and Edge are both planning to follow suit. Additionally, the Secure flag will be required for cookies that are marked as SameSite=None.
It is important to note that this attribute should be implemented as an additional layer defense in depth concept. This attribute protects the user through the browsers supporting it, and it contains as well 2 ways to bypass it as mentioned in the following section. This attribute should not replace a CSRF Token. Instead, it should co-exist with that token to protect the user in a more robust way.
-
Strict 値を指定すると、通常のリンクをたどった場合でも、すべてのクロスサイト・ブラウジングのコンテキストでブラウザからターゲットサイトにクッキーが送信されなくなります
-
ウェブサイトが、ユーザーが外部リンクからアクセスした後もログインセッションを維持したいのであれば、SameSiteのデフォルト値であるLaxがセキュリティとユーザビリティの妥当なバランスを提供します。
If a cookie is set with the SameSite=None attribute, this effectively disables SameSite restrictions altogether, regardless of the browser.
- same-siteの効果をブラウザ関係なく効果を消す