-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
361 lines (315 loc) · 12.6 KB
/
index.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>noopener noreferrer Example</title>
<link rel="stylesheet" href="style.css">
<link rel="icon" href="https://github.com/skunkworksza/Media/blob/main/logo-skunkworks-trans%2040%20%C3%97%2040%20px.png?raw=true">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-okaidia.min.css">
<style>
body {
font-family: 'IBM Plex Sans', sans-serif;
margin: 0;
padding: 0;
background-color: rgb(244, 244, 244);
display: flex;
justify-content: center;
align-items: flex-start;
min-height: 100vh;
overflow-x: hidden;
}
.container {
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 900px;
width: 100%;
transition: transform 0.3s ease, box-shadow 0.3s ease;
padding: 20px;
margin: 20px;
box-sizing: border-box;
overflow: auto;
}
.container:hover {
transform: translateY(-5px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
.header {
background-color: #0f62fe;
color: white;
padding: 20px;
text-align: center;
position: relative;
}
.logo {
width: 150px;
margin-bottom: 20px;
}
.header::before,
.header::after {
content: '';
position: absolute;
top: 50%;
width: 50px;
height: 50px;
background: rgba(255, 255, 255, 0.1);
border-radius: 50%;
transform: translateY(-50%);
}
.header::before {
left: -25px;
}
.header::after {
right: -25px;
}
main {
padding: 20px;
}
.example-link {
display: inline-block;
margin: 10px 0;
padding: 10px 20px;
background-color: #e0e0e0;
color: black;
text-decoration: none;
border-radius: 4px;
transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}
.example-link:hover {
background-color: #c6c6c6;
color: #0f62fe;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.section {
padding: 20px;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 12px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
textarea {
width: 100%;
margin-top: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
font-family: 'IBM Plex Mono', monospace;
font-size: 14px;
}
textarea:focus {
border-color: #0f62fe;
box-shadow: 0 0 5px rgba(15, 98, 254, 0.5);
outline: none;
}
button {
background-color: #0f62fe;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease, transform 0.3s ease;
margin-top: 10px;
}
button:hover {
background-color: #0353e9;
transform: translateY(-2px);
}
button:active {
transform: translateY(1px);
}
#message.success {
background-color: #d4edda;
color: #155724;
}
#message.error {
background-color: #f8d7da;
color: #721c24;
}
@media (max-width: 600px) {
.header,
main {
padding: 15px;
}
.logo {
width: 100px;
}
.header::before,
.header::after {
display: none;
}
button {
width: 100%;
padding: 15px;
}
}
@media (max-width: 480px) {
.container {
width: 95%;
}
.header {
padding: 10px;
}
.logo {
width: 80px;
}
button {
padding: 12px;
}
}
</style>
</head>
<body>
<div class="container">
<header class="header">
<img src="https://github.com/skunkworksza/Media/blob/main/skunkworks-logo%20-%20Copy.png?raw=true" alt="Skunkworks Logo" class="logo">
<h1>Try it Yourself: Adding <code>rel="noopener noreferrer"</code></h1>
</header>
<main>
<section class="section">
<h2>Introduction</h2>
<p>Open the links below in new tabs and observe the behavior:</p>
<div class="grid-container">
<a href="example-without-noreferrer.html" target="_blank" class="example-link">Open Example without noreferrer</a>
<a href="example-with-noreferrer.html" target="_blank" rel="noopener noreferrer" class="example-link">Open Example with noreferrer</a>
</div>
</section>
<section class="section">
<h2>Why use <code>rel="noopener noreferrer"</code>?</h2>
<p>Using <code>rel="noopener noreferrer"</code> prevents the new page from being able to access the <code>window.opener</code> property and ensures it runs in a separate process. This is particularly important for security and performance reasons.</p>
</section>
<section class="section">
<h2>Understanding the Exploit</h2>
<p>When a link is opened with <code>target="_blank"</code> without using <code>rel="noopener noreferrer"</code>, the new page has access to the <code>window.opener</code> property, which refers to the original page. This can be exploited by malicious pages to manipulate the content or URL of the original page.</p>
<div class="grid-container">
<div>
<h3>Steps to Exploit <code>example-without-noreferrer.html</code></h3>
<ol>
<li>Open the <strong>Example without noreferrer</strong> link. A new tab will open <code>malicious.html</code>.</li>
<li>Observe that <code>malicious.html</code> attempts to manipulate the original page by redirecting it to <code>hacked.html</code> or changing its content to display a fake login form.</li>
<li>In a real-world scenario, this could be used to steal sensitive information by tricking users into entering their credentials on a phishing page that looks like a legitimate login form.</li>
</ol>
</div>
<div>
<h3>Mitigation with <code>example-with-noreferrer.html</code></h3>
<ol>
<li>Open the <strong>Example with noreferrer</strong> link. A new tab will open <code>malicious.html</code>.</li>
<li>Observe that <code>malicious.html</code> fails to manipulate the original page because the <code>window.opener</code> property is <code>null</code>.</li>
<li>By using <code>rel="noopener noreferrer"</code>, the original page is protected from any manipulation attempts by the new page, thus preventing potential phishing attacks.</li>
</ol>
</div>
</div>
</section>
<section class="section">
<h2>Explanation of <code>malicious.html</code></h2>
<p>
The <code>malicious.html</code> page has been styled to look like a legitimate Skunkworks Mail login page.
It includes a form that checks for specific credentials (username: <code>skunkworks</code>, password: <code>password123</code>).
If the correct credentials are entered, the user is redirected to <code>hacked.html</code>. Otherwise, an error message is displayed.
The page still attempts to manipulate the opener's content or URL to demonstrate the security risk.
</p>
</section>
<section class="section">
<h2>Credentials for Redirection</h2>
<table>
<tr>
<th>Username</th>
<td>skunkworks</td>
</tr>
<tr>
<th>Password</th>
<td>password123</td>
</tr>
</table>
<p>This setup should provide a clear and realistic demonstration of the security implications and how the <code>rel="noopener noreferrer"</code> attribute helps mitigate such risks.</p>
</section>
<section class="section">
<h2>Try It Yourself:</h2>
<textarea id="code" rows="10" cols="50" class="language-html"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html></textarea>
<br>
<button onclick="runCode()">Run Code</button>
<iframe id="output" style="width: 100%; height: 200px; border: 1px solid black;"></iframe>
<div id="message" style="display: none; padding: 10px; margin-top: 10px; border-radius: 4px;"></div>
</section>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script>
function runCode() {
var code = document.getElementById('code').value;
var iframe = document.getElementById('output');
try {
// Sanitize the code to prevent XSS attacks
code = sanitizeHTML(code);
// Clear the iframe
iframe.contentWindow.document.open();
iframe.contentWindow.document.write('');
iframe.contentWindow.document.close();
// Measure execution time
var startTime = performance.now();
// Write the sanitized code to the iframe
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(code);
iframe.contentWindow.document.close();
var endTime = performance.now();
var executionTime = (endTime - startTime).toFixed(2);
displayMessage(`Code executed in ${executionTime} ms`, 'success');
} catch (error) {
displayMessage(`Error: ${error.message}`, 'error');
}
}
function sanitizeHTML(str) {
var temp = document.createElement('div');
temp.textContent = str;
return temp.innerHTML;
}
function displayMessage(message, type) {
var messageBox = document.getElementById('message');
messageBox.textContent = message;
messageBox.className = type; // Assuming you have defined styles for .success and .error
messageBox.style.display = 'block';
setTimeout(() => {
messageBox.style.display = 'none';
}, 5000);
}
document.addEventListener('DOMContentLoaded', () => {
Prism.highlightAll();
});
</script>
</div>
</body>
</html>