-
Notifications
You must be signed in to change notification settings - Fork 0
/
body.html
74 lines (61 loc) · 2 KB
/
body.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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="utf-8" />
<title>CSS3 Contact Form</title>
</head>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
<button id="i_save" value="save" name="i_save" onclick="save()">Save</button>
<button id="i_load" value="load" name="i_load" onclick="load()" >Load</button>
<br/>
<br/>
<div>Hello <span id="data">stranger</span>, How are you?
</div>
</html>
<script>
/// <summary>
/// HTML-encodes a string and returns the encoded string (analog of .NET Server.HtmlEncode method).
/// </summary>
/// <param name="str">The text string to encode.</param>
function HtmlEncode(str)
{
var strEncoded = new String(str);
strEncoded = strEncoded.replace(/&/g, "&");
strEncoded = strEncoded.replace(/</g, "<");
strEncoded = strEncoded.replace(/>/g, ">");
strEncoded = strEncoded.replace(/"/g, """);
return strEncoded;
}
function save() {
var val = $("input[name=firstname]").val();
$.ajax({
type: "POST",
url: "/myaction",
data: { "name" : val },
success: function(result) {
},
error: function(result) {
alert('error' + result);
}
});
};
function load() {
$.ajax({
type: "GET",
url: "/myaction",
success: function(result) {
var name = 'stranger';
if (result && result.name)
{
name = result.name;
}
//$('#data').html(HtmlEncode(name)); // XSS fixed
$('#data').html(name); // XSS attack
},
error: function(result) {
alert('error' + result);
}
});
}
</script>