Skip to content

Commit 899ae4f

Browse files
committed
fixes
1 parent f018012 commit 899ae4f

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

Diff for: 3-frames-and-windows/06-clickjacking/article.md

+20-38
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ Here's the same example, but closer to reality, with `opacity:0` for `<iframe>`:
5757

5858
[codetabs src="clickjacking" height=160]
5959

60-
All we need to attack -- is to position the `<iframe>` on the evil page in such a way that the button is right over the link. That's usually possible with CSS.
60+
All we need to attack -- is to position the `<iframe>` on the evil page in such a way that the button is right over the link. So that when a user clicks the link, they actually click the button. That's usually doable with CSS.
6161

6262
```smart header="Clickjacking is for clicks, not for keyboard"
63-
The attack only affects mouse actions.
63+
The attack only affects mouse actions (or similar, like taps on mobile).
6464
65-
Technically, if we have a text field to hack, then we can position an iframe in such a way that text fields overlap each other. So when a visitor tries to focus on the input they see on the page, they actually focus on the input inside the iframe.
65+
Keyboard input is much difficult to redirect. Technically, if we have a text field to hack, then we can position an iframe in such a way that text fields overlap each other. So when a visitor tries to focus on the input they see on the page, they actually focus on the input inside the iframe.
6666
6767
But then there's a problem. Everything that the visitor types will be hidden, because the iframe is not visible.
6868
@@ -87,19 +87,19 @@ This not a reliable defence, because there are many ways to hack around it. Let'
8787

8888
### Blocking top-navigation
8989

90-
We can block the transition caused by changing `top.location` in the [beforeunload](info:onload-ondomcontentloaded#window.onbeforeunload) event.
90+
We can block the transition caused by changing `top.location` in [beforeunload](info:onload-ondomcontentloaded#window.onbeforeunload) event handler.
9191

92-
The top page (belonging to the hacker) sets a handler to it, and when the `iframe` tries to change `top.location` the visitor gets a message asking them whether they want to leave.
92+
The top page (enclosing one, belonging to the hacker) sets a preventing handler to it, like this:
9393

94-
Like this:
9594
```js
9695
window.onbeforeunload = function() {
97-
window.onbeforeunload = null;
98-
return "Want to leave without learning all the secrets (he-he)?";
96+
return false;
9997
};
10098
```
10199

102-
In most cases the visitor would answer negatively because they don't know about the iframe - all they can see is the top page, leading them to think there is no reason to leave. So `top.location` won't change!
100+
When the `iframe` tries to change `top.location`, the visitor gets a message asking them whether they want to leave.
101+
102+
In most cases the visitor would answer negatively because they don't know about the iframe - all they can see is the top page, there's no reason to leave. So `top.location` won't change!
103103

104104
In action:
105105

@@ -123,7 +123,7 @@ There are other ways to work around that simple protection too.
123123

124124
The server-side header `X-Frame-Options` can permit or forbid displaying the page inside a frame.
125125

126-
It must be sent *by the server*: the browser will ignore it if found in a `<meta>` tag. So, `<meta http-equiv="X-Frame-Options"...>` won't do anything.
126+
It must be sent exactly as HTTP-header: the browser will ignore it if found in HTML `<meta>` tag. So, `<meta http-equiv="X-Frame-Options"...>` won't do anything.
127127

128128
The header may have 3 values:
129129

@@ -156,7 +156,7 @@ Depending on your browser, the `iframe` above is either empty or alerting you th
156156

157157
The `X-Frame-Options` header has a side-effect. Other sites won't be able to show our page in a frame, even if they have good reasons to do so.
158158

159-
So there are other solutions... For instance, we can "cover" the page with a `<div>` with `height: 100%; width: 100%;`, so that it intercepts all clicks. That `<div>` should disappear if `window == top` or if we figure out that we don't need the protection.
159+
So there are other solutions... For instance, we can "cover" the page with a `<div>` with styles `height: 100%; width: 100%;`, so that it will intercept all clicks. That `<div>` is to be removed if `window == top` or if we figure out that we don't need the protection.
160160

161161
Something like this:
162162

@@ -191,43 +191,25 @@ 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 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.
195-
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
194+
The `samesite` cookie attribute can also prevent clickjacking attacks.
201195

202-
`Set-Cookie: demoCookie=demoValue; samesite=strict`
196+
A cookie with such attribute is only sent to a website if it's opened directly, not via a frame, or otherwise. More information in the chapter <info:cookie#samesite>.
203197

204-
In JavaScript, it is:
198+
If the site, such as Facebook, had `samesite` attribute on its authentication cookie, like this:
205199

206-
```html
207-
document.cookie = "demoCookie=demoValue; SameSite=Lax";
208-
document.cookie = "demoCookie=demoValue; SameSite=Strict";
200+
```
201+
Set-Cookie: authorization=secret; samesite
209202
```
210203

211-
When the value is `lax`, these types of requests are blocked:
212-
- Form POST submit (&lt;form method="POST" action="..."&gt;)
213-
- iframe (&lt;iframe src="..."&gt;&lt;/iframe&gt;)
214-
- AJAX ($.get("..."))
215-
- Image (&lt;img src="..."&gt;)
216-
- Script (&lt;script src="..."&gt;&lt;/script&gt;)
217-
- Stylesheet (&lt;link rel="stylesheet" type="text/css" href="..."&gt;)
218-
219-
When the value is `strict`, these types of requests are also blocked, in addition to those under `lax`:
220-
- Clicking a link (&lt;a href="..."&gt;&lt;/a&gt;)
221-
- Prerender (&lt;link rel="prerender" href=".."/&gt;)
222-
- Form GET submit (&lt;form method="GET" action="..."&gt;)
204+
...Then such cookie wouldn't be sent when Facebook is open in iframe from another site. So the attack would fail.
223205

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.
206+
The `samesite` cookie attribute will not have an effect when cookies are not used. This may allow other websites to easily show our public, unauthenticated pages in iframes.
225207

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.
208+
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.
227209

228210
## Summary
229211

230-
Clickjacking is a way to "trick" users into clicking on a malicious site without even knowing what's happening. That's dangerous if there are important click-activated actions.
212+
Clickjacking is a way to "trick" users into clicking on a victim site without even knowing what's happening. That's dangerous if there are important click-activated actions.
231213

232214
A hacker can post a link to their evil page in a message, or lure visitors to their page by some other means. There are many variations.
233215

Diff for: 6-data-storage/01-cookie/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ document.cookie = "user=John; secure";
181181

182182
## samesite
183183

184-
That's another security option, to protect from so-called XSRF (cross-site request forgery) attacks.
184+
That's another security attribute `somesite`. It's designed to protect from so-called XSRF (cross-site request forgery) attacks.
185185

186-
To understand when it's useful, let's introduce the following attack scenario.
186+
To understand how it works and when it's useful, let's take a look at XSRF attacks.
187187

188188
### XSRF attack
189189

0 commit comments

Comments
 (0)