aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/http/headers/set-cookie/samesite/index.html
blob: 2a54dc379a7da98f13f3398914e7c14b2321ccea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: SameSite cookies
slug: Web/HTTP/Headers/Set-Cookie/SameSite
tags:
  - Cookies
  - HTTP
  - Reference
  - samesite
translation_of: Web/HTTP/Headers/Set-Cookie/SameSite
---
<div>{{HTTPSidebar}}</div>

<p><span class="seoSummary">{{HTTPHeader("Set-Cookie")}} HTTP レスポンスヘッダーの <strong><code>SameSite</code></strong> 属性を使用すると、Cookie をファーストパーティまたは同じサイトのコンテキストに制限するかどうかを宣言できます。</span></p>

<h2 id="値"></h2>

<p><code>SameSite</code> 属性は3つの値をとります。</p>

<h3 id="Lax"><code>Lax</code></h3>

<p>Cookie はトップレベルナビゲーションで送信することが許可されており、サードパーティの Web サイトによって開始された GET リクエストとともに送信されます。これは、モダンブラウザのデフォルト値です。</p>

<h3 id="Strict"><code>Strict</code></h3>

<p>Cookie はファーストパーティのコンテキストでのみ送信され、サードパーティの Web サイトによって開始されたリクエストと一緒に送信されることはありません。</p>

<h3 id="None"><code>None</code></h3>

<p>Cookie はすべてのコンテキストで送信されます。つまり、クロスオリジンの送信が許可されます。</p>

<p><code>None</code> はデフォルト値でしたが、最近のブラウザバージョンでは、<code>Lax</code> をデフォルト値にして、クロスサイトリクエストフォージェリ ({{Glossary("CSRF")}}) 攻撃のクラスに対して適度に堅牢な防御を提供しました。</p>

<p><code>None</code> では、最新バージョンのブラウザで <a href="#Secure"><code>Secure</code></a> 属性が必要です。詳細については、以下を参照してください。</p>

<h2 id="一般的な警告の修正">一般的な警告の修正</h2>

<h3 id="SameSiteNone_requires_Secure"><code>SameSite=None</code> requires <code>Secure</code></h3>

<p>次の警告がコンソールに表示される場合があります。</p>

<blockquote>
<p>Some cookies are misusing the “sameSite“ attribute, so it won’t work as expected.<br>
 Cookie “<em>myCookie</em>” rejected because it has the “sameSite=none” attribute but is missing the “secure” attribute.</p>
</blockquote>

<p><code>SameSite=None</code> を要求するが <code>Secure</code> とマークされていない Cookie は拒否されるため、警告が表示されます。</p>

<pre class="example-bad notranslate">Set-Cookie: flavor=choco; SameSite=None</pre>

<p>これを修正するには、<code>SameSite=None</code> Cookie に <code>Secure</code> 属性を追加する必要があります。</p>

<pre class="example-good notranslate">Set-Cookie: flavor=choco; SameSite=None; <strong>Secure</strong></pre>

<p><a href="#Secure"><code>Secure</code></a> Cookie は、HTTPS プロトコルを介した暗号化されたリクエストでのみサーバーに送信されます。安全でないサイト (<code>http:</code>) は <code>Secure</code> ディレクティブで Cookie を設定できないことに注意してください。</p>

<h3 id="Cookies_without_SameSite_default_to_SameSiteLax">Cookies without <code>SameSite</code> default to <code>SameSite=Lax</code></h3>

<p>モダンブラウザの最近のバージョンでは、デフォルトで <code>SameSite</code> がより安全に Cookie に提供されているため、次のメッセージがコンソールに表示される場合があります。</p>

<blockquote>
<p>Some cookies are misusing the “sameSite“ attribute, so it won’t work as expected.<br>
 Cookie “<em>myCookie</em>” has “sameSite” policy set to “lax” because it is missing a “sameSite” attribute, and “sameSite=lax” is the default value for this attribute.</p>
</blockquote>

<p>Cookie の <code>SameSite</code> ポリシーが明示的に指定されていないため、警告が表示されます。</p>

<pre class="example-bad notranslate">Set-Cookie: flavor=choco</pre>

<p>モダンブラウザを使用して <code>SameSite=Lax</code> を自動的に適用することもできますが、明示的に指定して、Cookie に適用される <code>SameSite</code> ポリシーの意図を明確に伝える必要があります。すべてのブラウザのデフォルトがまだ <code>Lax</code> であるわけではないため、これによりブラウザ全体のエクスペリエンスも向上します。</p>

<pre class="example-good notranslate">Set-Cookie: flavor=choco; <strong>SameSite=Lax</strong></pre>

<h2 id="例"><strong>例:</strong></h2>

<pre class="notranslate">RewriteEngine on
RewriteBase "/"
RewriteCond "%{HTTP_HOST}"       "^example\.org$" [NC]
RewriteRule "^(.*)"              "https://www.example.org/index.html" [R=301,L,QSA]
RewriteRule "^(.*)\.ht$"         "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:01:https://www.example.org:30/:SameSite=None:Secure]
RewriteRule "^(.*)\.htm$"        "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:02:https://www.example.org:30/:SameSite=None:Secure]
RewriteRule "^(.*)\.html$"       "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:03:https://www.example.org:30/:SameSite=None:Secure]
[...]
RewriteRule "^admin/(.*)\.html$" "admin/index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:09:https://www.example.org:30/:SameSite=Strict:Secure]
</pre>

<h2 id="仕様">仕様</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">タイトル</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{RFC("6265", "Set-Cookie", "4.1")}}</td>
   <td>HTTP 状態管理メカニズム</td>
  </tr>
  <tr>
   <td><a href="https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-05">draft-ietf-httpbis-rfc6265bis-05</a></td>
   <td>Cookie プレフィックス、同一サイト Cookie、および厳格なセキュア Cookie</td>
  </tr>
 </tbody>
</table>

<h2 id="ブラウザの互換性">ブラウザの互換性</h2>

<p>{{Compat("http.headers.Set-Cookie", 5)}}</p>

<h2 id="あわせて参照">あわせて参照</h2>

<ul>
 <li><a href="/ja/docs/Web/HTTP/Cookies">HTTP cookies</a></li>
 <li>{{HTTPHeader("Cookie")}}</li>
 <li>{{domxref("Document.cookie")}}</li>
</ul>