Skip to content

Commit d382ba7

Browse files
authored
Merge pull request #320 from davegregg/master
Grammar and readability edits in Clickjacking and Ninja Code
2 parents 7fa42ad + 910ab98 commit d382ba7

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

1-js/03-code-quality/04-ninja-code/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ While choosing a name try to use the most abstract word. Like `obj`, `data`, `va
8080

8181
Give them a try. A young ninja may wonder -- do such names make the code worse? Actually, yes!
8282

83-
From one hand, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all!
83+
Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all!
8484

8585
Indeed, the value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store? There's just no way to figure out without a good meditation!
8686

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ The idea is very simple.
1212

1313
Here's how clickjacking was done with Facebook:
1414

15-
1. A visitor is lured to the evil page. No matter how.
16-
2. The page has a harmlessly-looking link on it (like "get rich now" or "click here, very funny" and so on).
15+
1. A visitor is lured to the evil page. It doesn't matter how.
16+
2. The page has a harmless-looking link on it (like "get rich now" or "click here, very funny").
1717
3. Over that link the evil page positions a transparent `<iframe>` with `src` from facebook.com, in such a way that the "Like" button is right above that link. Usually that's done with `z-index`.
18-
4. Clicking on that link, the visitor in fact presses that button.
18+
4. In attempting to click the link, the visitor in fact clicks the button.
1919

2020
## The demo
2121

22-
Here's how the evil page looks like. To make things clear, the `<iframe>` is half-transparent (in real evil pages it's fully transparent):
22+
Here's how the evil page looks. To make things clear, the `<iframe>` is half-transparent (in real evil pages it's fully transparent):
2323

2424
```html run height=120 no-beautify
2525
<style>
@@ -53,7 +53,7 @@ The full demo of the attack:
5353

5454
Here we have a half-transparent `<iframe src="facebook.html">`, and in the example we can see it hovering over the button. A click on the button actually clicks on the iframe, but that's not visible to the user, because the iframe is transparent.
5555

56-
As a result if the visitor is authorized on facebook ("remember me" is usually turned on), then it adds a "Like". On Twitter that would be a "Follow" button.
56+
As a result, if the visitor is authorized on Facebook ("remember me" is usually turned on), then it adds a "Like". On Twitter that would be a "Follow" button.
5757

5858
Here's the same example, but closer to reality, with `opacity:0` for `<iframe>`:
5959

@@ -68,30 +68,30 @@ Technically, if we have a text field to hack, then we can position an iframe in
6868
6969
But then there's a problem. Everything that the visitor types will be hidden, because the iframe is not visible.
7070
71-
So that would look really odd to the user, and he will stop.
71+
People will usually stop typing when they can't see their new characters printing on the screen.
7272
```
7373

7474
## Old-school defences (weak)
7575

76-
The oldest defence method is the piece of JavaScript that forbids to open the page in a frame (so-called "framebusting").
76+
The oldest defence is a bit of JavaScript which forbids opening the page in a frame (so-called "framebusting").
7777

78-
Like this:
78+
That looks like this:
7979

8080
```js
8181
if (top != window) {
8282
top.location = window.location;
8383
}
8484
```
8585

86-
That is: if the window finds out that it's not on the top, then it automatically makes itself the top.
86+
That is: if the window finds out that it's not on top, then it automatically makes itself the top.
8787

88-
As of now, that's not reliable, because there are many ways to hack around it. Let's cover a few.
88+
This not a reliable defence, because there are many ways to hack around it. Let's cover a few.
8989

9090
### Blocking top-navigation
9191

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

94-
The top page (that belongs to the hacker) sets a handler to it, and when the `iframe` tries to change `top.location` the visitor gets a message asking him whether he wants to leave.
94+
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 him whether he wants to leave.
9595

9696
Like this:
9797
```js
@@ -101,7 +101,7 @@ window.onbeforeunload = function() {
101101
};
102102
```
103103

104-
In most cases the visitor would answer negatively, because he doesn't know about the iframe, all he can see is the top page, there's no reason to leave. And so the `top.location` won't change!
104+
In most cases the visitor would answer negatively, because he doesn't know about the iframe, all he can see is the top page, leading him to think there is no reason to leave. So `top.location` won't change!
105105

106106
In action:
107107

@@ -111,7 +111,7 @@ In action:
111111

112112
One of the things restricted by the `sandbox` attribute is navigation. A sandboxed iframe may not change `top.location`.
113113

114-
So we can add the iframe with `sandbox="allow-scripts allow-forms"`. That would relax the restrictions allowing scripts and forms. But we don't put `allow-top-navigation` in the value so that the navigation is still forbidden. And the change of `top.location` won't work.
114+
So we can add the iframe with `sandbox="allow-scripts allow-forms"`. That would relax the restrictions, permitting scripts and forms. But we omit `allow-top-navigation` so that changing `top.location` is forbidden.
115115

116116
Here's the code:
117117

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

124124
## X-Frame-Options
125125

126-
Server-side header `X-Frame-Options` can allow or forbid showing the page inside a frame.
126+
The server-side header `X-Frame-Options` can permit or forbid displaying the page inside a frame.
127127

128-
It must be sent by the server: browser ignore it if found in `<meta>` tags. So `<meta http-equiv="X-Frame-Options"...>` won't do anything.
128+
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.
129129

130130
The header may have 3 values:
131131

132132

133133
`DENY`
134-
: Never ever show the page inside an iframe.
134+
: Never ever show the page inside a frame.
135135

136136
`SAMEORIGIN`
137-
: Allow to show inside an iframe if the parent document comes from the same origin.
137+
: Allow inside a frame if the parent document comes from the same origin.
138138

139139
`ALLOW-FROM domain`
140-
: Allows to show inside an iframe if the parent document is from the given domain.
140+
: Allow inside a frame if the parent document is from the given domain.
141141

142142
For instance, Twitter uses `X-Frame-Options: SAMEORIGIN`. Here's the result:
143143

@@ -147,15 +147,15 @@ For instance, Twitter uses `X-Frame-Options: SAMEORIGIN`. Here's the result:
147147

148148
<iframe src="https://twitter.com"></iframe>
149149

150-
Depending on the browser, `iframe` above is either empty or it has a message telling that "the browser can't show it".
150+
Depending on your browser, the `iframe` above is either empty or alerting you that the browser won't permit that page to be navigating in this way.
151151

152152
## Showing with disabled functionality
153153

154-
The protecting `X-Frame-Options` header has a side-effect. Other sites can't show our page in an `iframe`, even if they have "legal" reasons to do so.
154+
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.
155155

156-
So there are other solutions. For instance, we can "cover" the page with a `<div>` with `height:100%;width:100%`, so that it handles all clicks. That `<div>` should disappear if `window == top` or we figure out that we don't need protection.
156+
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.
157157

158-
Like this:
158+
Something like this:
159159

160160
```html
161161
<style>
@@ -188,13 +188,13 @@ The demo:
188188

189189
## Summary
190190

191-
Clickjacking is a way to "trick" users into a clicking on a victim site without even knowing what happens. That's dangerous if there are important click-activated actions.
191+
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.
192192

193-
A hacker can post a link to his evil page in a message or lure visitors to his page by other means. There are many variants.
193+
A hacker can post a link to his evil page in a message, or lure visitors to his page by some other means. There are many variations.
194194

195-
From one side -- the attack is "not deep": all a hacker can do is one click. But from another side, if the hacker knows that after the click another control appears, then it may use cunning messages to make the user to click on it as well.
195+
From one perspective -- the attack is "not deep": all a hacker is doing is intercepting a single click. But from another perspective, if the hacker knows that after the click another control will appear, then he may use cunning messages to coerce the user into clicking on them as well.
196196

197-
The attack is quite dangerous, because when we engineer the UI we usually don't think that a hacker can click on behalf of the visitor. So vulnerabilities can be found in totally unexpected places.
197+
The attack is quite dangerous, because when we engineer the UI we usually don't anticipate that a hacker may click on behalf of the visitor. So vulnerabilities can be found in totally unexpected places.
198198

199-
- It's recommended to use `X-Frame-Options: SAMEORIGIN` on pages that are totally not meant to be shown inside iframes (or just for the whole site).
200-
- Use a covering `<div>` if we want to allow our pages to be shown in iframes, and still stay safe.
199+
- It is recommended to use `X-Frame-Options: SAMEORIGIN` on pages (or whole websites) which are not intended to be viewed inside frames.
200+
- Use a covering `<div>` if we want to allow our pages to be shown in iframes, but still stay safe.

0 commit comments

Comments
 (0)