forked from aneagoie/security-client-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (27 loc) · 958 Bytes
/
script.js
File metadata and controls
28 lines (27 loc) · 958 Bytes
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
// try inputting this: <script>alert('hi')</script>
// Now, try inputting this: <img src="/" onerror = "alert(1);">
// Scripts injected into the DOM via script tags in innerHTML
// are not run at the time they are injected (inline scripts
// are run at the time the original page is parsed). On the
// other hand, images injected into the DOM are loaded at that
// time, and if the loading fails, then the onerror event
//handler is called.
const userInputInHTML = (input) => {
const p = document.getElementById("pleaseNo")
// Bad
p.innerHTML = input;
// Better
// var textnode = document.createTextNode(input);
// p.appendChild(textnode);
}
const sendToServer = () => {
const input = document.querySelector('#userinput').value;
userInputInHTML(input)
fetch('http://localhost:3000/secret', {
method: 'POST',
body: JSON.stringify({userInput: input}),
headers: new Headers({
'Content-Type': 'application/json'
})
})
}