-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
186 lines (173 loc) · 5.17 KB
/
main.js
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
(function(_, $, window) {
/**
* Get list of all properties of the object.
* for-in is listing of all enumerable properties.
*
* @param {Object} object
* @returns {Object}
*/
var getObjectProperty = function(object) {
var property,
obj = {};
for (property in object)
obj[property] = object[property];
return obj;
};
/**
* Get list of all properties name of the object.
*
* @param {Object} object
* @returns {Array}
*/
var getObjectPropertyNamesToArray = function(object) {
var property,
arr = [];
for (property in object)
arr.push(property);
return arr;
};
// fingerprint data
var data = [];
// for implements
var navigatorPropNames = getObjectPropertyNamesToArray(window.navigator),
screenPropNames = getObjectPropertyNamesToArray(window.screen);
/**
* 1. Enumerated the navigator and screen object,
* i.e., request the listing of all properties
* of the aforementioned objects.
*/
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen)
});
/**
* 2. Enumerated the navigator object again, to ensure
* that the order of enumeration does not change.
*/
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen)
});
/**
* 3. Created a custom object, populated it, and enumerated
* it. A custom, JavaScript-created object, allows us to
* compare the behavior of browser-populated objects
* (such as navigator) with the behavior of “classic”
* JavaScript objects.
*/
var customObject = {
'customObject': 'data',
'fingerprinting': 'fingerprint'
};
data.push({
'customObject': getObjectProperty(customObject)
});
/**
* 4. Attempted to delete a property of the navigator
* object, the screen object, and the custom object.
*/
var navigatorTmp = _.cloneDeep(window.navigator),
screenTmp = _.cloneDeep(window.screen),
customObjectTmp = _.cloneDeep(customObject);
data.push({
'navigator_delete': delete window.navigator[navigatorPropNames[0]],
'screen_delete': delete window.screen[screenPropNames[0]],
'customObject_delete': delete customObject.fingerprinting,
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen),
'customObject': getObjectProperty(customObject)
});
/**
* 5. Add the possibly-deleted properties back to their objects.
*/
window.navigator[navigatorPropNames[0]] = navigatorTmp[navigatorPropNames[0]];
window.screen[screenPropNames[0]] = screenTmp[screenPropNames[0]];
customObject.fingerprinting = customObjectTmp.fingerprinting;
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen),
'customObject': getObjectProperty(customObject)
});
/**
* 6. Attempted to modify an existing property of the
* navigator and screen objects.
*/
window.navigator[navigatorPropNames[1]] = {};
window.screen[screenPropNames[1]] = {};
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen)
});
/**
* 7. If Object.defineProperty is implemented in
* the current browser, utilize it to make an existing
* property in the navigator, screen, and custom
* object non-enumerable.
*/
if ('defineProperty' in Object) {
Object.defineProperty(window.navigator, navigatorPropNames[2], {
enumerable: false
});
Object.defineProperty(window.screen, screenPropNames[2], {
enumerable: false,
});
Object.defineProperty(customObject, 'fingerprinting', {
enumerable: false,
});
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen),
'customObject': getObjectProperty(customObject)
});
} else {
data.push({
'Object.defineProperty': 'not supported'
});
}
/**
* 8. Attempt to delete the navigator and screen objects.
*/
try {
delete window.navigator;
delete window.screen;
} catch (err) {
console.log(err);
}
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen)
});
/**
* 9. Attempt to assign new custom objects to the
* navigator and screen variable names.
*/
var newCustomObject = {
'newCustomObject': 'data',
'fingerprinting': 'fingerprint'
};
try {
window.navigator = newCustomObject;
window.screen = newCustomObject;
} catch (err) {
console.log(err);
}
data.push({
'navigator': getObjectProperty(window.navigator),
'screen': getObjectProperty(window.screen)
});
// console.log(data);
var $dd;
_.each(data, function(obj, idx) {
_.each(obj, function(val, key) {
$('#step' + (idx + 1)).append($.parseHTML('<dt>' + key + '</dt>' + '<dd id="step' + (idx + 1) + key + '"></dd>'));
$dd = $('#step' + (idx + 1) + key);
if (typeof val === 'object') {
_.each(val, function(value, property) {
$dd.append(property + ': ' + value + '<br>');
});
} else {
$dd.append(val);
}
});
});
}(_, jQuery, window));