-
Notifications
You must be signed in to change notification settings - Fork 4
/
headers.js
277 lines (231 loc) · 9.24 KB
/
headers.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
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
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36';
var requestFilter = { urls: [ "<all_urls>" ] };
const fuckingsCookieName = 'Fuckings-To-The-Internet';
/////////////////////
// For generating consistent randomness
// We get consistent randomness in a time window of ten minutes
//
function simpleHash(str) {
var h = 0;
for (var i = 0; i < str.length; i++) {
h = Math.imul(31, h) + str.charCodeAt(i);
h %= 4294967295;
}
return h;
}
var LCG=s=>()=>(2**31-1&(s=Math.imul(48271,s)))/2**31;
const date = new Date();
// Decided against using the window.location because some inject code
// to run in about:blank (or another host and get the value back),
// which would make this moot
const hourlySeed = simpleHash(date.toDateString() + date.getHours().toString() + Math.floor(date.getMinutes() / 6).toString());
var hourlyRandom = LCG(hourlySeed);
function randomChars(len) {
var chars = '';
while (chars.length < len) {
chars += Math.random().toString(36).substring(2);
}
// Remove unnecessary additional characters.
return chars.substring(0, len);
}
function garbageBase64(len) {
var chars = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
while (chars.length < len) {
chars += possible.charAt(Math.floor(Math.random() * possible.length));
}
// Remove unnecessary additional characters.
return chars;
}
const generatedFpJsVid = randomChars(20);
const generatedFpJsVidT = garbageBase64(80);
const generatedFpJsIIDT = garbageBase64(80);
// I'm lazy, so sue me
// Not sure what they store there
chrome.webRequest.onBeforeRequest.addListener(
function() {
return {cancel: true};
},
{ urls: ["*://api.sjpf.io/*"] },
["blocking"]
);
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
var headers = details.requestHeaders;
const isFingerprint = (details.url.indexOf("fingerprintjs.com/") != -1 || details.url.indexOf("fpjs.io/") != -1 || details.url.indexOf("sjpf.io/") != -1); // lgtm [js/incomplete-url-substring-sanitization]
for(var i = 0, l = headers.length; i < l; ++i) {
if( headers[i].name == 'User-Agent' ) {
headers[i].value = userAgent;
} else if( headers[i].name == 'Accept-Language' ) {
headers[i].value = 'en-US,en;q=0.8';
} else if( headers[i].name == 'Accept' && details.url.indexOf("yahoo.com/") != -1 ) { // lgtm [js/incomplete-url-substring-sanitization]
headers[i].value = 'application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3';
} else if( headers[i].name.toLowerCase() == 'cookie') {
var newHeader = ''
const cookies = headers[i].value.split(';')
for (var cookie in cookies) {
var cookieName = cookies[cookie].split('=')[0].trim()
if (isFingerprint && cookieName == '_vid') {
newHeader += `_vid=` + generatedFpJsVid + `; Max-Age=0;`
console.log("replaced vid, old " + cookies[cookie].split('=')[1].trim() + ", new " + generatedFpJsVid);
} else if (isFingerprint && cookieName == '_vid_t') {
newHeader += `_vid_t=` + generatedFpJsVidT + `; Max-Age=0;`
console.log("replaced vid_t, old " + cookies[cookie].split('=')[1].trim() + ", new " + generatedFpJsVidT);
} else if (isFingerprint && cookieName == '_iidt') {
newHeader += `_iidt=` + generatedFpJsVidT + `; Max-Age=0;`
console.log("replaced _iidt, old " + cookies[cookie].split('=')[1].trim() + ", new " + generatedFpJsIIDT);
} else if (cookieName == fuckingsCookieName) {
continue;
} else if (!isFingerprint) {
newHeader += cookies[cookie] + ';';
}
}
headers[i].value = newHeader;
}
}
return {requestHeaders: headers};
}, requestFilter, ['requestHeaders','blocking','extraHeaders']);
var disabledOn = -1;
let disabledIn = new Set();
chrome.webRequest.onHeadersReceived.addListener(function(details) {
var headers = details.responseHeaders;
const enabled = (disabledIn.has(details.tabId) || details.tabId === -1) ? 'nofuck' : 'dofuck' + details.tabId;
if (details.tabId === -1) {
console.log(details);
}
if (details.url.indexOf("sjpf.io") != -1) {
}
const isFingerprint = (details.url.indexOf("fingerprintjs.com/") != -1 || details.url.indexOf("fpjs.io/") != -1 || details.url.indexOf("sjpf.io/") != -1); // lgtm [js/incomplete-url-substring-sanitization]
var isFavicon = details.url.indexOf("favicon.ico") !== -1; // our content script should enforce this
for(var i = 0, l = headers.length; i < l; ++i) {
if (headers[i].name.toLowerCase() != 'content-type') {
continue;
}
if (headers[i].value.toLowerCase().indexOf('icon') !== -1) {
isFavicon = true;
}
}
var hadCookies = false;
for(var i = 0, l = headers.length; i < l; ++i) {
if (isFavicon && headers[i].name.toLowerCase() == 'location') {
console.warn("Might be trying to fingerprint via favicon");
console.log(details);
headers[i].value = "localhost";
continue;
}
if (headers[i].name.toLowerCase() != 'set-cookie') {
continue
}
var newHeader = ''
const cookies = headers[i].value.split(';')
var wasOurs = false;
for (var cookie in cookies) {
var cookieName = cookies[cookie].split('=')[0].trim()
if (isFingerprint && cookieName == '_vid') {
headers[i].value = `_vid=` + generatedFpJsVid + `; Max-Age=0;`;
console.log("replaced vid, old " + cookies[cookie].split('=')[1].trim() + ", new " + generatedFpJsVid);
break;
} else if (cookieName == fuckingsCookieName) {
headers[i].value = `Fuckings-To-The-Internet=${enabled}; Max-Age=0;`;
wasOurs = true;
hadCookies = true;
break;
} else if (!isFingerprint) {
newHeader += cookies[cookie] + ';';
}
}
}
if (!hadCookies) {
headers.push({
name: "Set-Cookie",
value: `Fuckings-To-The-Internet=${enabled};`
});
}
details.responseHeaders = headers
return {responseHeaders: headers};
}, requestFilter, ['responseHeaders', 'blocking', 'extraHeaders']);
const canvas = document.createElement('canvas'); // Create the canvas
canvas.width = 16;
canvas.height = 16;
const ctx = canvas.getContext("2d");
var particles = [];
var mouse = {};
function particle() {
this.speed = {
x: -2 + Math.random() * 4,
y: -2 + Math.random() * 4
};
this.location = {
x: canvas.width / 2,
y: canvas.height / 2
};
this.radius = 1 + Math.random() * 8;
this.life = 20 + Math.random() * 10;
this.remaining_life = this.life;
this.r = 74;
this.g = 77;
this.b = 84;
}
const particle_count = 10;
for (var i = 0; i < particle_count; i++) {
particles.push(new particle());
}
function draw() {
ctx.globalCompositeOperation = "copy"; // clear the canvas
ctx.fillStyle = "rgba(0,0,0,0)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.globalCompositeOperation = "lighter";
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
ctx.beginPath();
p.opacity = Math.round(p.remaining_life / p.life * 100) / 100;
var gradient = ctx.createRadialGradient(p.location.x, p.location.y, 0, p.location.x, p.location.y, p.radius);
p.r = 255;
p.g = 69;
p.b = 0;
gradient.addColorStop(0, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")");
gradient.addColorStop(0.2, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")");
gradient.addColorStop(1, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", 0)");
ctx.fillStyle = gradient;
ctx.arc(p.location.x, p.location.y, p.radius, Math.PI * 2, false);
ctx.fill();
//lets move the particles
p.remaining_life--;
p.radius--;
p.location.x += p.speed.x;
p.location.y += p.speed.y;
//regenerate particles
if (p.remaining_life < 0 || p.radius < 0) {
particles[i] = new particle();
}
}
chrome.browserAction.setIcon({
imageData: ctx.getImageData(0, 0, 16, 16)
});
}
var interval = null;
function updateIcon(tab) {
if (disabledIn.has(tab)) {
if (!interval) {
interval = setInterval(draw, 66);
}
} else {
if (interval) {
clearInterval(interval);
interval = null
chrome.browserAction.setIcon({
path: "icon.png"
});
}
}
}
chrome.tabs.onActivated.addListener(function(tab) {
updateIcon(tab.tabId);
});
chrome.browserAction.onClicked.addListener(function(tab) {
if (disabledIn.has(tab.id)) {
disabledIn.delete(tab.id);
} else {
disabledIn.add(tab.id);
}
updateIcon(tab.id);
});