Skip to content

Commit 2aa5068

Browse files
authored
Added more detail for samesite attribute
1 parent e8661bf commit 2aa5068

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

4-frames-and-windows/06-clickjacking/article.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,39 @@ The demo:
191191

192192
## Samesite cookie attribute
193193

194-
The `samesite` cookie attribute can also prevent clickjacking attacks. The purpose of the attribute is to prevent cookies from being sent to a website when the user doesn't intend to visit the website. It mainly prevents cross-site request forgery attacks, but also helps with clickjacking. When a cookie has the `samesite` attribute, whether the value is `strict` or `lax`, cookies are not sent to a website when it is loaded inside an iframe. A clickjacking attempt would fail because the user is not considered logged into, for example, Facebook, so they can't "Like" anything through the iframe.
194+
The `samesite` cookie attribute can also prevent clickjacking attacks. The purpose of the attribute is to prevent cookies from being sent to a website when the user doesn't intend to visit the website. It is designed to prevent cross-site request forgery attacks, but also helps with clickjacking because a hijacked click usually results in an unintended request to a different site. When a cookie has the `samesite` attribute, whether the value is `strict` or `lax`, cookies are not sent to a website when it is loaded inside an iframe.
195195

196-
The samesite attribute will not have an effect when cookies are not used. This may allow websites to easily show public, unauthenticated pages in iframes on unaffiliated websites. However, this may also allow clickjacking attacks to work in a few limited cases. An anonymous polling website that prevents duplicate voting by checking IP addresses, for example, would still be vulnerable to clickjacking because it does not authenticate users using cookies.
196+
The `samesite` attribute can be set using HTTP response headers or JavaScript. Via HTTP, it looks like:
197+
198+
`Set-Cookie: demoCookie=demoValue; samesite=lax`
199+
200+
or
201+
202+
`Set-Cookie: demoCookie=demoValue; samesite=strict`
203+
204+
In JavaScript, it is:
205+
206+
```html
207+
document.cookie = "demoCookie=demoValue; SameSite=Lax";
208+
document.cookie = "demoCookie=demoValue; SameSite=Strict";
209+
```
210+
211+
When the value is `lax`, these types of requests are blocked:
212+
- Form POST submit (<form method="POST" action="...">)
213+
- iframe (<iframe src="..."></iframe>)
214+
- AJAX ($.get("..."))
215+
- Image (<img src="...">)
216+
- Script (<script src="..."></script>)
217+
- Stylesheet (<link rel="stylesheet" type="text/css" href="...">)
218+
219+
When the value is `strict`, these types of requests are also blocked, in addition to those under `lax`:
220+
- Clicking a link (<a href="..."></a>)
221+
- Prerender (<link rel="prerender" href=".."/>)
222+
- Form GET submit (<form method="GET" action="...">)
223+
224+
In this case, we are concerned with iframe requests. A clickjacking attempt would fail because the user is not considered logged into, for example, Facebook, so they can't "Like" anything through the iframe.
225+
226+
The `samesite` attribute will not have an effect when cookies are not used. This may allow websites to easily show public, unauthenticated pages in iframes on unaffiliated websites. However, this may also allow clickjacking attacks to work in a few limited cases. An anonymous polling website that prevents duplicate voting by checking IP addresses, for example, would still be vulnerable to clickjacking because it does not authenticate users using cookies.
197227

198228
## Summary
199229

0 commit comments

Comments
 (0)