@anonympins/fingerprint 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +70 -60
- package/package.json +1 -1
- package/src/js/fingerprint.client.js +831 -635
- package/src/js/fingerprint.js +249 -31
- package/src/js/pow.solver.js +531 -497
- package/src/js/problem-manager.js +24 -0
- package/src/js/tests/fingerprint.client.init.test.js +140 -119
- package/src/js/tests/fingerprint.test.js +2451 -2319
- package/src/js/tests/pow.solver.test.js +233 -197
- package/src/js/tests/problem-manager.test.js +358 -322
- package/src/php/Challenge/ChallengeUtils.php +415 -361
- package/src/php/Config/SecurityProfiles.php +276 -271
- package/src/php/FingerprintClient.php +131 -131
- package/src/php/FingerprintEngine.php +36 -2
- package/src/php/Optimization/FunctionRegistry.php +63 -62
- package/src/php/Optimization/OptimizationOperators.php +401 -304
- package/src/php/ProblemManager.php +29 -0
- package/src/php/RequestContext.php +90 -90
- package/src/php/Store/IStore.php +41 -41
- package/src/php/Store/RedisStore.php +53 -53
- package/src/php/Tests/FingerprintEngineTest.php +330 -299
- package/src/php/Tests/ProblemManagerTest.php +376 -296
- package/src/php/Tests/RequestUtilsTest.php +386 -253
- package/src/php/Tests/problems.config.json +3 -3
- package/src/php/Utils/RequestUtils.php +201 -17
|
@@ -1,636 +1,832 @@
|
|
|
1
|
-
import {cyrb53 as jsCyrb53, FingerprintBuilder} from './fingerprint.builder.js';
|
|
2
|
-
import {solveChallenge} from './pow.solver.js';
|
|
3
|
-
|
|
4
|
-
// Variable pour stocker la fonction de hachage active.
|
|
5
|
-
// Par défaut, c'est l'implémentation JavaScript.
|
|
6
|
-
let activeCyrb53 = jsCyrb53;
|
|
7
|
-
|
|
8
|
-
const
|
|
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
|
-
this.
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
1
|
+
import {cyrb53 as jsCyrb53, FingerprintBuilder} from './fingerprint.builder.js';
|
|
2
|
+
import {solveChallenge} from './pow.solver.js';
|
|
3
|
+
|
|
4
|
+
// Variable pour stocker la fonction de hachage active.
|
|
5
|
+
// Par défaut, c'est l'implémentation JavaScript.
|
|
6
|
+
let activeCyrb53 = jsCyrb53;
|
|
7
|
+
|
|
8
|
+
const DB_NAME = 'wasm-cache-db';
|
|
9
|
+
const DB_VERSION = 1;
|
|
10
|
+
const STORE_NAME = 'wasm-modules';
|
|
11
|
+
|
|
12
|
+
function getCachedWasm(url) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
if (typeof indexedDB === 'undefined') return resolve(null);
|
|
15
|
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
16
|
+
request.onupgradeneeded = (e) => {
|
|
17
|
+
const db = e.target.result;
|
|
18
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
19
|
+
db.createObjectStore(STORE_NAME);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
request.onsuccess = (e) => {
|
|
23
|
+
const db = e.target.result;
|
|
24
|
+
try {
|
|
25
|
+
const transaction = db.transaction(STORE_NAME, 'readonly');
|
|
26
|
+
const store = transaction.objectStore(STORE_NAME);
|
|
27
|
+
const getReq = store.get(url);
|
|
28
|
+
getReq.onsuccess = () => resolve(getReq.result);
|
|
29
|
+
getReq.onerror = () => resolve(null);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
resolve(null);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
request.onerror = () => resolve(null);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function cacheWasm(url, data) {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
if (typeof indexedDB === 'undefined') return resolve(false);
|
|
41
|
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
42
|
+
request.onupgradeneeded = (e) => {
|
|
43
|
+
const db = e.target.result;
|
|
44
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
45
|
+
db.createObjectStore(STORE_NAME);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
request.onsuccess = (e) => {
|
|
49
|
+
const db = e.target.result;
|
|
50
|
+
try {
|
|
51
|
+
const transaction = db.transaction(STORE_NAME, 'readwrite');
|
|
52
|
+
const store = transaction.objectStore(STORE_NAME);
|
|
53
|
+
store.put(data, url);
|
|
54
|
+
transaction.oncomplete = () => resolve(true);
|
|
55
|
+
transaction.onerror = () => resolve(false);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
resolve(false);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
request.onerror = () => resolve(false);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ClientLibrary = {
|
|
65
|
+
// Cache pour éviter de recalculer les constantes (Hardware, etc.)
|
|
66
|
+
_cachedBuilder: null,
|
|
67
|
+
/**
|
|
68
|
+
* @private
|
|
69
|
+
* Dispatches a custom event from the window object.
|
|
70
|
+
* @param {string} eventName - The name of the event.
|
|
71
|
+
* @param {object} [detail={}] - The data to include in the event's detail property.
|
|
72
|
+
*/
|
|
73
|
+
_dispatchEvent(eventName, detail = {}) {
|
|
74
|
+
if (typeof window === 'undefined' || typeof CustomEvent === 'undefined') return;
|
|
75
|
+
const event = new CustomEvent(`fingerprint:${eventName}`, { detail });
|
|
76
|
+
window.dispatchEvent(event);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Wrapper interne pour la fonction de hachage.
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
_hasher: (str, seed) => activeCyrb53(str, seed),
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Génère l'empreinte de l'appareil actuel.
|
|
87
|
+
*/
|
|
88
|
+
getDeviceFingerprint() {
|
|
89
|
+
if (typeof window === "undefined") {
|
|
90
|
+
console.error("getDeviceFingerprint can only be called on the client-side.");
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!this._cachedBuilder) {
|
|
95
|
+
const nav = window.navigator;
|
|
96
|
+
const screen = window.screen;
|
|
97
|
+
|
|
98
|
+
this._cachedBuilder = new FingerprintBuilder();
|
|
99
|
+
|
|
100
|
+
// 1. Hardware (Très stable) : Cœurs, RAM, GPU (si dispo via canvas), Touch
|
|
101
|
+
this._cachedBuilder.add(
|
|
102
|
+
"hw", // Utilise maintenant le hasher actif
|
|
103
|
+
`${nav.hardwareConcurrency}_${nav.deviceMemory}_${nav.maxTouchPoints}`,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// 2. Geo/Locale (Stable sauf voyage/VPN) : Timezone, Langue
|
|
107
|
+
this._cachedBuilder.add(
|
|
108
|
+
"geo",
|
|
109
|
+
`${Intl.DateTimeFormat().resolvedOptions().timeZone}_${nav.language}_${new Date().getTimezoneOffset()}`,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// 3. Screen (Stable sauf changement moniteur/zoom) : Dimensions, ColorDepth
|
|
113
|
+
this._cachedBuilder.add(
|
|
114
|
+
"scr",
|
|
115
|
+
`${screen.width}x${screen.height}_${screen.colorDepth}`,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// 4. Platform (Stable) : OS, Engine
|
|
119
|
+
this._cachedBuilder.add("os", nav.platform);
|
|
120
|
+
|
|
121
|
+
// 5. Graphics (WebGL Vendor/Renderer) - Invariant matériel fort
|
|
122
|
+
try {
|
|
123
|
+
const canvas = document.createElement("canvas");
|
|
124
|
+
const gl =
|
|
125
|
+
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
126
|
+
if (gl) {
|
|
127
|
+
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
128
|
+
if (debugInfo) {
|
|
129
|
+
const vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
|
|
130
|
+
const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
131
|
+
this._cachedBuilder.add("gpu", `${vendor}_${renderer}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 6. Canvas Fingerprinting (Rendering quirks)
|
|
138
|
+
try {
|
|
139
|
+
const canvas = document.createElement("canvas");
|
|
140
|
+
const ctx = canvas.getContext("2d");
|
|
141
|
+
if (ctx) {
|
|
142
|
+
canvas.width = 200;
|
|
143
|
+
canvas.height = 50;
|
|
144
|
+
ctx.textBaseline = "alphabetic";
|
|
145
|
+
ctx.font = "14px 'Arial'";
|
|
146
|
+
ctx.fillStyle = "#f60";
|
|
147
|
+
ctx.fillRect(125, 1, 62, 20);
|
|
148
|
+
ctx.fillStyle = "#069";
|
|
149
|
+
ctx.fillText("fingerprint", 2, 15);
|
|
150
|
+
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
|
|
151
|
+
ctx.fillText("fingerprint", 4, 17);
|
|
152
|
+
this._cachedBuilder.add("cvs", canvas.toDataURL());
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 7. Détection des artefacts du Chrome DevTools Protocol (CDP)
|
|
158
|
+
// Ces variables sont souvent injectées par les outils d'automatisation.
|
|
159
|
+
const cdpFootprints = [
|
|
160
|
+
'cdc_adoQpoasnfa76pfcZLmcfl_Array',
|
|
161
|
+
'cdc_adoQpoasnfa76pfcZLmcfl_Promise',
|
|
162
|
+
'cdc_adoQpoasnfa76pfcZLmcfl_Symbol',
|
|
163
|
+
'$cdc_asdjflasutopfhvcZLmcfl_',
|
|
164
|
+
'_selenium',
|
|
165
|
+
'_driver'
|
|
166
|
+
];
|
|
167
|
+
if (cdpFootprints.some(fp => window[fp])) {
|
|
168
|
+
this._cachedBuilder.add("cdp", "true");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 7. Bot Detection (Indication cachée)
|
|
172
|
+
if (nav.webdriver) this._cachedBuilder.add("bot", "true");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return this._cachedBuilder.toString();
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Génère une signature de requête incluant le contexte.
|
|
180
|
+
* @param {object} payload
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Génère une signature de requête incluant le contexte.
|
|
184
|
+
* @param {object} payload
|
|
185
|
+
*/
|
|
186
|
+
generateRequestSignature(payload = {}) {
|
|
187
|
+
const deviceFp = this.getDeviceFingerprint();
|
|
188
|
+
const sortedPayload = Object.keys(payload)
|
|
189
|
+
.sort()
|
|
190
|
+
.map((k) => `${k}=${payload[k]}`)
|
|
191
|
+
.join("&");
|
|
192
|
+
const payloadHash = this._hasher(sortedPayload);
|
|
193
|
+
return `${deviceFp}|req:${payloadHash}`;
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Génère une signature HMAC-SHA256 en utilisant l'API Web Crypto.
|
|
198
|
+
* @param {object} payload - Les données à signer.
|
|
199
|
+
* @param {string} secret - La clé secrète partagée.
|
|
200
|
+
* @returns {Promise<string>} La signature hexadécimale.
|
|
201
|
+
*/
|
|
202
|
+
async generateClientSideSignature(payload, secret) {
|
|
203
|
+
const sortedPayload = Object.keys(payload).sort().map((k) => `${k}=${payload[k]}`).join("&");
|
|
204
|
+
const encoder = new TextEncoder();
|
|
205
|
+
const key = await window.crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
206
|
+
name: "HMAC",
|
|
207
|
+
hash: "SHA-256"
|
|
208
|
+
}, false, ["sign"]);
|
|
209
|
+
const signatureBuffer = await window.crypto.subtle.sign("HMAC", key, encoder.encode(sortedPayload));
|
|
210
|
+
const hashArray = Array.from(new Uint8Array(signatureBuffer));
|
|
211
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @internal
|
|
216
|
+
* Resets the cached fingerprint builder. Used for testing purposes.
|
|
217
|
+
*/
|
|
218
|
+
_resetCache() {
|
|
219
|
+
// Réinitialise le hasher à l'implémentation JS par défaut.
|
|
220
|
+
activeCyrb53 = jsCyrb53;
|
|
221
|
+
this._cachedBuilder = null;
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Injecte des éléments interactifs fantômes invisibles pour piéger les bots (focus/hover).
|
|
226
|
+
*/
|
|
227
|
+
injectPhantomTraps() {
|
|
228
|
+
if (typeof document === 'undefined') return;
|
|
229
|
+
|
|
230
|
+
// Création d'un élément interactif fantôme
|
|
231
|
+
const phantom = document.createElement('a');
|
|
232
|
+
phantom.href = '#';
|
|
233
|
+
// Nom trompeur pour attirer les analyseurs automatiques de liens / formulaires
|
|
234
|
+
phantom.id = 'sys-session-recovery';
|
|
235
|
+
phantom.tabIndex = 0; // Dans le flux naturel de tabulation
|
|
236
|
+
phantom.setAttribute('aria-hidden', 'true'); // Masqué pour les screen readers légitimes
|
|
237
|
+
|
|
238
|
+
// Style invisible mais interactif (1px x 1px, presque transparent)
|
|
239
|
+
phantom.style.position = 'fixed';
|
|
240
|
+
phantom.style.top = '1px';
|
|
241
|
+
phantom.style.left = '1px';
|
|
242
|
+
phantom.style.width = '1px';
|
|
243
|
+
phantom.style.height = '1px';
|
|
244
|
+
phantom.style.opacity = '0.001';
|
|
245
|
+
phantom.style.zIndex = '99999';
|
|
246
|
+
phantom.style.overflow = 'hidden';
|
|
247
|
+
phantom.style.pointerEvents = 'auto';
|
|
248
|
+
|
|
249
|
+
const triggerTrap = () => {
|
|
250
|
+
this.onHoneypotTrigger();
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
phantom.addEventListener('focus', triggerTrap, { passive: true });
|
|
254
|
+
phantom.addEventListener('mouseover', triggerTrap, { passive: true });
|
|
255
|
+
|
|
256
|
+
document.body.appendChild(phantom);
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Démarre le suivi des événements tactiles sur mobile/tablette.
|
|
261
|
+
*/
|
|
262
|
+
startTouchEventTracker() {
|
|
263
|
+
if (this._touchTrackerAttached) return;
|
|
264
|
+
this._touchTrackerAttached = true;
|
|
265
|
+
|
|
266
|
+
const handleTouch = (e) => {
|
|
267
|
+
if (touchMovementsHistory.length >= TOUCH_HISTORY_MAX) {
|
|
268
|
+
touchMovementsHistory.shift();
|
|
269
|
+
}
|
|
270
|
+
const touch = e.touches[0] || e.changedTouches[0];
|
|
271
|
+
if (!touch) return;
|
|
272
|
+
|
|
273
|
+
const radiusX = touch.radiusX || 0;
|
|
274
|
+
const radiusY = touch.radiusY || 0;
|
|
275
|
+
const radius = (radiusX + radiusY) / 2;
|
|
276
|
+
const force = touch.force || touch.webkitForce || 0;
|
|
277
|
+
|
|
278
|
+
touchMovementsHistory.push({
|
|
279
|
+
x: touch.clientX,
|
|
280
|
+
y: touch.clientY,
|
|
281
|
+
t: performance.now(),
|
|
282
|
+
p: force,
|
|
283
|
+
r: radius,
|
|
284
|
+
num: e.touches.length
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
document.addEventListener('touchstart', handleTouch, { passive: true });
|
|
289
|
+
document.addEventListener('touchmove', handleTouch, { passive: true });
|
|
290
|
+
document.addEventListener('touchend', handleTouch, { passive: true });
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Démarre le suivi des mouvements de la souris pour calculer l'entropie.
|
|
295
|
+
* À appeler une fois sur la page.
|
|
296
|
+
*/
|
|
297
|
+
startMouseEntropyTracker() {
|
|
298
|
+
// Utiliser un drapeau pour éviter d'attacher l'écouteur plusieurs fois
|
|
299
|
+
if (this._mouseTrackerAttached) return;
|
|
300
|
+
this._mouseTrackerAttached = true;
|
|
301
|
+
|
|
302
|
+
document.addEventListener('mousemove', (e) => {
|
|
303
|
+
// NOUVEAU: Capturer une série de points {x, y, t}
|
|
304
|
+
if (mouseMovementsHistory.length >= MOUSE_HISTORY_MAX) {
|
|
305
|
+
// Garder la taille de l'historique constante pour éviter une consommation mémoire excessive.
|
|
306
|
+
mouseMovementsHistory.shift();
|
|
307
|
+
}
|
|
308
|
+
mouseMovementsHistory.push({
|
|
309
|
+
x: e.clientX,
|
|
310
|
+
y: e.clientY,
|
|
311
|
+
t: performance.now()
|
|
312
|
+
});
|
|
313
|
+
}, {passive: true});
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Démarre le suivi de la dynamique de frappe pour calculer la latence.
|
|
318
|
+
* À appeler une fois sur la page.
|
|
319
|
+
*/
|
|
320
|
+
startKeystrokeDynamicsTracker() {
|
|
321
|
+
// S'assurer de ne pas attacher l'écouteur plusieurs fois
|
|
322
|
+
if (keystrokeTimestamps.length > 0) return;
|
|
323
|
+
|
|
324
|
+
document.addEventListener('keydown', () => {
|
|
325
|
+
const now = performance.now();
|
|
326
|
+
if (keystrokeTimestamps.length > 0) {
|
|
327
|
+
const lastTimestamp = keystrokeTimestamps[keystrokeTimestamps.length - 1];
|
|
328
|
+
const latency = now - lastTimestamp;
|
|
329
|
+
// On ignore les latences irréalistes (trop longues ou trop courtes)
|
|
330
|
+
if (latency > 10 && latency < 2000) { // Augmenté à 2s
|
|
331
|
+
if (keystrokeLatencies.length >= KEYSTROKE_HISTORY_MAX) {
|
|
332
|
+
keystrokeLatencies.shift(); // Garder la taille de l'historique
|
|
333
|
+
}
|
|
334
|
+
keystrokeLatencies.push(latency);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
keystrokeTimestamps.push(now);
|
|
338
|
+
}, {passive: true});
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Starts tracking click events to analyze position variance.
|
|
343
|
+
* @private
|
|
344
|
+
*/
|
|
345
|
+
startClickTracker() {
|
|
346
|
+
if (this._clickTrackerAttached) return;
|
|
347
|
+
this._clickTrackerAttached = true;
|
|
348
|
+
|
|
349
|
+
document.addEventListener('click', (e) => {
|
|
350
|
+
if (clicksHistory.length >= CLICKS_HISTORY_MAX) {
|
|
351
|
+
clicksHistory.shift();
|
|
352
|
+
}
|
|
353
|
+
// Generate a simple identifier for the target element
|
|
354
|
+
const target = e.target;
|
|
355
|
+
const targetId = target.id || target.name || target.tagName;
|
|
356
|
+
|
|
357
|
+
clicksHistory.push({
|
|
358
|
+
x: e.clientX,
|
|
359
|
+
y: e.clientY,
|
|
360
|
+
t: performance.now(),
|
|
361
|
+
targetId: this._hasher(targetId) // Hash the ID to keep it short and consistent
|
|
362
|
+
});
|
|
363
|
+
}, { passive: true });
|
|
364
|
+
},
|
|
365
|
+
/**
|
|
366
|
+
* Initialise ou réinitialise les honeypots côté client pour une détection immédiate.
|
|
367
|
+
* Les anciens écouteurs sont supprimés avant d'en ajouter de nouveaux.
|
|
368
|
+
* @param {string[]} honeypotFieldNames - Noms des champs de formulaire cachés.
|
|
369
|
+
*/
|
|
370
|
+
initializeHoneypots(honeypotFieldNames) {
|
|
371
|
+
// 1. Nettoyer les anciens écouteurs
|
|
372
|
+
activeHoneypotListeners.forEach((listener, field) => {
|
|
373
|
+
field.removeEventListener('input', listener);
|
|
374
|
+
});
|
|
375
|
+
activeHoneypotListeners.clear();
|
|
376
|
+
|
|
377
|
+
// 2. Ajouter les nouveaux écouteurs
|
|
378
|
+
honeypotFieldNames.forEach(fieldName => {
|
|
379
|
+
const field = document.querySelector(`[name="${fieldName}"]`);
|
|
380
|
+
if (field) {
|
|
381
|
+
// On utilise une fonction nommée (ou une référence) pour pouvoir la supprimer plus tard.
|
|
382
|
+
// L'option { once: true } est excellente, mais pour une réinitialisation complète,
|
|
383
|
+
// il est plus propre de gérer le nettoyage nous-mêmes.
|
|
384
|
+
const listener = () => {
|
|
385
|
+
this.onHoneypotTrigger();
|
|
386
|
+
// Se supprime lui-même après exécution, comme { once: true }
|
|
387
|
+
field.removeEventListener('input', listener);
|
|
388
|
+
};
|
|
389
|
+
field.addEventListener('input', listener);
|
|
390
|
+
activeHoneypotListeners.set(field, listener); // On stocke la référence
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Récupère les métriques comportementales collectées.
|
|
397
|
+
* À appeler avant d'envoyer une requête sensible.
|
|
398
|
+
* @returns {ClientBehaviorMetrics}
|
|
399
|
+
*/
|
|
400
|
+
getClientBehaviorMetrics() {
|
|
401
|
+
// Add history length as a behavioral signal.
|
|
402
|
+
metrics.historyLength = window.history.length;
|
|
403
|
+
|
|
404
|
+
// Ajoute un timestamp au moment de la collecte pour la détection de rejeu.
|
|
405
|
+
metrics.clicksHistory = clicksHistory;
|
|
406
|
+
metrics.clientTimestamp = Date.now();
|
|
407
|
+
|
|
408
|
+
metrics.touchMovementsHistory = touchMovementsHistory;
|
|
409
|
+
// NOUVEAU: Inclure l'historique des mouvements de la souris pour une analyse côté serveur.
|
|
410
|
+
metrics.mouseMovementsHistory = mouseMovementsHistory;
|
|
411
|
+
|
|
412
|
+
// Calcule la latence moyenne des frappes
|
|
413
|
+
if (keystrokeLatencies.length > 0) {
|
|
414
|
+
const sum = keystrokeLatencies.reduce((a, b) => a + b, 0);
|
|
415
|
+
metrics.keystrokeLatency = sum / keystrokeLatencies.length;
|
|
416
|
+
} else {
|
|
417
|
+
metrics.keystrokeLatency = 0;
|
|
418
|
+
}
|
|
419
|
+
return metrics;
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Enrichit une requête fetch avec les en-têtes de fingerprinting et de comportement.
|
|
424
|
+
* @param {RequestInfo} resource
|
|
425
|
+
* @param {RequestInit} [options]
|
|
426
|
+
* @returns {Promise<Response>}
|
|
427
|
+
*/
|
|
428
|
+
async protectedFetch(resource, options = {}) {
|
|
429
|
+
const fp = this.getDeviceFingerprint();
|
|
430
|
+
const behavior = this.getClientBehaviorMetrics();
|
|
431
|
+
|
|
432
|
+
const headers = new Headers(options.headers || {});
|
|
433
|
+
headers.set('X-Device-Fingerprint', fp);
|
|
434
|
+
headers.set('X-Behavior-Metrics', JSON.stringify(behavior));
|
|
435
|
+
|
|
436
|
+
options.headers = headers;
|
|
437
|
+
return fetch(resource, options);
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
// --- Système d'interception de Fetch robuste et anti-conflit ---
|
|
441
|
+
|
|
442
|
+
_isFetchPatched: false,
|
|
443
|
+
_interceptorChain: [],
|
|
444
|
+
// On stocke la fonction fetch originale et on la lie à son contexte (window)
|
|
445
|
+
// pour éviter les erreurs "Illegal invocation" si une autre lib la modifie.
|
|
446
|
+
_originalFetch: (typeof window !== 'undefined') ? window.fetch.bind(window) : null,
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Adds an interceptor function to the `fetch` chain.
|
|
450
|
+
* Chaque intercepteur reçoit `resource`, `options`, et une fonction `next`.
|
|
451
|
+
* Il DOIT appeler `next(resource, options)` pour continuer la chaîne.
|
|
452
|
+
* @param {function(RequestInfo, RequestInit, function): Promise<Response>} interceptor
|
|
453
|
+
*/
|
|
454
|
+
addFetchInterceptor(interceptor) {
|
|
455
|
+
if (!this._isFetchPatched) {
|
|
456
|
+
this.patchGlobalFetch();
|
|
457
|
+
}
|
|
458
|
+
this._interceptorChain.push(interceptor);
|
|
459
|
+
},
|
|
460
|
+
|
|
461
|
+
patchGlobalFetch() {
|
|
462
|
+
if (this._isFetchPatched || !this._originalFetch) return;
|
|
463
|
+
|
|
464
|
+
this._isFetchPatched = true;
|
|
465
|
+
window.fetch = (resource, options) => {
|
|
466
|
+
// Le "dispatcher" qui exécute la chaîne.
|
|
467
|
+
const dispatch = (index, res, opts) => {
|
|
468
|
+
if (index >= this._interceptorChain.length) {
|
|
469
|
+
// Fin de la chaîne, on appelle le fetch original.
|
|
470
|
+
return this._originalFetch(res, opts);
|
|
471
|
+
}
|
|
472
|
+
const nextInterceptor = this._interceptorChain[index];
|
|
473
|
+
// Appelle l'intercepteur actuel en lui passant la fonction pour appeler le suivant.
|
|
474
|
+
return nextInterceptor(res, opts, (nextRes, nextOpts) => dispatch(index + 1, nextRes, nextOpts));
|
|
475
|
+
};
|
|
476
|
+
return dispatch(0, resource, options || {});
|
|
477
|
+
};
|
|
478
|
+
},
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* La fonction qui est appelée lorsqu'un honeypot est déclenché.
|
|
482
|
+
* @private
|
|
483
|
+
*/
|
|
484
|
+
onHoneypotTrigger() {
|
|
485
|
+
metrics.honeypotInteraction = true;
|
|
486
|
+
// Émettre un événement pour que l'application puisse réagir.
|
|
487
|
+
this._dispatchEvent('honeypotTriggered');
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Initialise l'intercepteur de fingerprinting.
|
|
492
|
+
* Il s'ajoute à la chaîne d'interception sans écraser les autres.
|
|
493
|
+
* @param {string[]} [targetDomains] - Optionnel. Liste de domaines à protéger.
|
|
494
|
+
* Si non fourni, protège les requêtes de même origine.
|
|
495
|
+
*/
|
|
496
|
+
initializeFetch(targetDomains = []) {
|
|
497
|
+
const fingerprintInterceptor = (resource, options, next) => {
|
|
498
|
+
const requestUrl = (resource instanceof Request) ? resource.url : String(resource);
|
|
499
|
+
let shouldProtect = false;
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
const url = new URL(requestUrl, window.location.origin);
|
|
503
|
+
// Protéger si la liste de domaines est vide ET que la requête est de même origine,
|
|
504
|
+
// OU si le domaine de la requête est dans la liste fournie.
|
|
505
|
+
shouldProtect = (targetDomains.length === 0 && url.origin === window.location.origin) ||
|
|
506
|
+
(targetDomains.length > 0 && targetDomains.includes(url.hostname));
|
|
507
|
+
} catch (e) {
|
|
508
|
+
// Si l'URL est relative (ex: '/api/data'), new URL() ne lèvera pas d'erreur.
|
|
509
|
+
// Ce bloc est une sécurité pour les cas où l'URL serait malformée.
|
|
510
|
+
// On protège par défaut si aucune liste de domaines n'est spécifiée.
|
|
511
|
+
shouldProtect = targetDomains.length === 0;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (shouldProtect) {
|
|
515
|
+
const fp = this.getDeviceFingerprint();
|
|
516
|
+
const behavior = this.getClientBehaviorMetrics();
|
|
517
|
+
const headers = new Headers(options.headers || {});
|
|
518
|
+
headers.set('X-Device-Fingerprint', fp);
|
|
519
|
+
headers.set('X-Behavior-Metrics', JSON.stringify(behavior));
|
|
520
|
+
options.headers = headers;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Passe la main à l'intercepteur suivant dans la chaîne.
|
|
524
|
+
return next(resource, options);
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
this.addFetchInterceptor(fingerprintInterceptor);
|
|
528
|
+
}, // <-- VIRGULE AJOUTÉE ICI
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Injects visually hidden "honeypot" links into the DOM to trap bots.
|
|
532
|
+
* @param {string[]} urls - An array of trap URLs to inject.
|
|
533
|
+
* @private
|
|
534
|
+
*/
|
|
535
|
+
injectTrapLinks(urls) {
|
|
536
|
+
if (!urls || urls.length === 0 || typeof document === 'undefined') {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const trapContainer = document.createElement('div');
|
|
541
|
+
trapContainer.setAttribute('aria-hidden', 'true');
|
|
542
|
+
trapContainer.style.position = 'absolute';
|
|
543
|
+
trapContainer.style.left = '-9999px';
|
|
544
|
+
trapContainer.style.top = '-9999px';
|
|
545
|
+
trapContainer.style.transform = 'scale(0)';
|
|
546
|
+
trapContainer.style.pointerEvents = 'none';
|
|
547
|
+
|
|
548
|
+
urls.forEach((url,i) => {
|
|
549
|
+
const link = document.createElement('a');
|
|
550
|
+
link.href = url;
|
|
551
|
+
link.rel = 'nofollow';
|
|
552
|
+
link.tabIndex = -1; // Make it unfocusable
|
|
553
|
+
link.innerHTML = `<span>> ${i+1}</span>`; // SEO-insignificant content
|
|
554
|
+
trapContainer.appendChild(link);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
document.body.appendChild(trapContainer);
|
|
558
|
+
},
|
|
559
|
+
/**
|
|
560
|
+
* Intercepte une réponse de challenge JSON, le résout, et réessaie la requête.
|
|
561
|
+
* @param {Response} response - La réponse initiale (potentiellement 429).
|
|
562
|
+
* @param {RequestInfo} resource - La ressource de la requête originale.
|
|
563
|
+
* @param {RequestInit} options - Les options de la requête originale.
|
|
564
|
+
* @returns {Promise<Response>} - La réponse de la requête réessayée.
|
|
565
|
+
* @private
|
|
566
|
+
*/
|
|
567
|
+
async solveChallengeAndRetry(response, resource, options) {
|
|
568
|
+
if (response.status !== 404 || !response.headers.get('content-type')?.includes('application/json') || response.bodyUsed) {
|
|
569
|
+
return response;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
try {
|
|
573
|
+
const challengeData = await response.json();
|
|
574
|
+
if (!challengeData.challenge || !challengeData.challenge.type) {
|
|
575
|
+
return response; // Pas un challenge JSON valide
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
console.log(`[Fingerprint] Received a '${challengeData.challenge.type}' challenge. Solving...`);
|
|
579
|
+
this._dispatchEvent('challengeReceived', { challenge: challengeData.challenge });
|
|
580
|
+
|
|
581
|
+
// L'empreinte de l'appareil qui résout le challenge est cruciale.
|
|
582
|
+
const solverFp = this.getDeviceFingerprint();
|
|
583
|
+
const solutionWrapper = await solveChallenge(challengeData.challenge, solverFp);
|
|
584
|
+
console.log('[Fingerprint] Challenge solved. Retrying original request.');
|
|
585
|
+
|
|
586
|
+
this._dispatchEvent('challengeSolved', { solution: solutionWrapper.rawSolution });
|
|
587
|
+
// Ajouter la solution aux paramètres de la requête pour le nouvel essai
|
|
588
|
+
const url = new URL((resource instanceof Request) ? resource.url : String(resource), window.location.origin);
|
|
589
|
+
// La logique de formatage est maintenant cachée dans la classe ChallengeSolution.
|
|
590
|
+
solutionWrapper.applyToUrl(url);
|
|
591
|
+
|
|
592
|
+
// On ajoute l'empreinte du solveur à la requête de réessai.
|
|
593
|
+
url.searchParams.set('pow_fp', solverFp);
|
|
594
|
+
|
|
595
|
+
// On utilise la chaîne d'intercepteurs pour la requête réessayée,
|
|
596
|
+
// ce qui garantit que le fetch original est appelé avec le bon contexte.
|
|
597
|
+
// Cela évite de réintroduire l'erreur "Illegal invocation".
|
|
598
|
+
return window.fetch(url.toString(), options);
|
|
599
|
+
} catch (e) {
|
|
600
|
+
console.error('[Fingerprint] Failed to solve or retry challenge:', e);
|
|
601
|
+
return response; // Retourne la réponse 429 originale en cas d'échec
|
|
602
|
+
}
|
|
603
|
+
}, // <-- VIRGULE AJOUTÉE ICI
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Initialise toutes les protections côté client en une seule fois.
|
|
607
|
+
* Tente également de charger le module WASM si `wasmPath` est fourni.
|
|
608
|
+
* C'est la méthode d'initialisation recommandée.
|
|
609
|
+
* @param {ClientConfig} [config={}] - L'objet de configuration.
|
|
610
|
+
*/
|
|
611
|
+
initializeClient(config = {}) {
|
|
612
|
+
const {
|
|
613
|
+
mouse = true,
|
|
614
|
+
keystrokes = true,
|
|
615
|
+
clicks = true, // Add new option
|
|
616
|
+
touches = true, // Nouveau paramètre tactiles
|
|
617
|
+
phantomTraps = true, // NOUVEAU
|
|
618
|
+
honeypots = [],
|
|
619
|
+
trapUrls = [], // Nouveau paramètre pour les URL pièges
|
|
620
|
+
wasmPath, // Nouveau paramètre
|
|
621
|
+
fetch: fetchConfig = {}
|
|
622
|
+
} = config;
|
|
623
|
+
|
|
624
|
+
// Tentative de chargement du WASM si le chemin est fourni
|
|
625
|
+
if (wasmPath) {
|
|
626
|
+
this.initializeWasm(wasmPath);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (mouse) {
|
|
630
|
+
this.startMouseEntropyTracker();
|
|
631
|
+
}
|
|
632
|
+
if (keystrokes) {
|
|
633
|
+
this.startKeystrokeDynamicsTracker();
|
|
634
|
+
}
|
|
635
|
+
if (clicks) {
|
|
636
|
+
this.startClickTracker();
|
|
637
|
+
}
|
|
638
|
+
if (touches) {
|
|
639
|
+
this.startTouchEventTracker();
|
|
640
|
+
}
|
|
641
|
+
if (phantomTraps) {
|
|
642
|
+
this.injectPhantomTraps();
|
|
643
|
+
}
|
|
644
|
+
if (honeypots.length > 0) {
|
|
645
|
+
this.initializeHoneypots(honeypots);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Injection dynamique des liens pièges au démarrage
|
|
649
|
+
if (trapUrls.length > 0) {
|
|
650
|
+
this.injectTrapLinks(trapUrls);
|
|
651
|
+
}
|
|
652
|
+
// On active l'interception si `fetch` est configuré, même avec un objet vide.
|
|
653
|
+
if (config.fetch) {
|
|
654
|
+
this.initializeFetch(fetchConfig.targetDomains);
|
|
655
|
+
|
|
656
|
+
// Ajoute l'intercepteur pour la résolution de challenge
|
|
657
|
+
if (fetchConfig.handleChallenges !== false) {
|
|
658
|
+
this.addFetchInterceptor(async (resource, options, next) => {
|
|
659
|
+
const originalResponse = await next(resource, options);
|
|
660
|
+
// On clone la réponse pour que la lecture du corps par solveChallengeAndRetry ne la consomme pas pour l'appelant original.
|
|
661
|
+
return this.solveChallengeAndRetry(originalResponse.clone(), resource, options);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Tente de charger et d'initialiser le module WebAssembly pour un hachage plus rapide.
|
|
669
|
+
* Si le chargement échoue, il se rabat silencieusement sur l'implémentation JS.
|
|
670
|
+
* @param {string} wasmPath - Le chemin vers le script de chargement du module WASM (ex: '/fp.js').
|
|
671
|
+
*/
|
|
672
|
+
async initializeWasm(wasmPath) {
|
|
673
|
+
try {
|
|
674
|
+
// 1. Injecter le script qui charge le module WASM
|
|
675
|
+
const script = document.createElement('script');
|
|
676
|
+
script.src = wasmPath;
|
|
677
|
+
await new Promise((resolve, reject) => {
|
|
678
|
+
script.onload = resolve;
|
|
679
|
+
script.onerror = reject;
|
|
680
|
+
document.head.appendChild(script);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
// 2. Attendre que la fonction globale `createFingerprintModule` soit disponible
|
|
684
|
+
if (typeof window.createFingerprintModule !== 'function') {
|
|
685
|
+
throw new Error('WASM loader script did not expose createFingerprintModule.');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// 3. Initialiser le module
|
|
689
|
+
const wasmUrl = wasmPath.replace(/\.js$/, '.wasm');
|
|
690
|
+
const wasmModule = await window.createFingerprintModule({
|
|
691
|
+
instantiateWasm: (imports, successCallback) => {
|
|
692
|
+
(async () => {
|
|
693
|
+
try {
|
|
694
|
+
const cached = await getCachedWasm(wasmUrl);
|
|
695
|
+
if (cached) {
|
|
696
|
+
let instance;
|
|
697
|
+
if (cached instanceof WebAssembly.Module) {
|
|
698
|
+
instance = await WebAssembly.instantiate(cached, imports);
|
|
699
|
+
} else {
|
|
700
|
+
const result = await WebAssembly.instantiate(cached, imports);
|
|
701
|
+
instance = result.instance;
|
|
702
|
+
}
|
|
703
|
+
successCallback(instance, cached);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const response = await fetch(wasmUrl);
|
|
708
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
709
|
+
|
|
710
|
+
let cachedData = arrayBuffer;
|
|
711
|
+
let isModuleCached = false;
|
|
712
|
+
try {
|
|
713
|
+
const compiledModule = await WebAssembly.compile(arrayBuffer);
|
|
714
|
+
const success = await cacheWasm(wasmUrl, compiledModule);
|
|
715
|
+
if (success) {
|
|
716
|
+
cachedData = compiledModule;
|
|
717
|
+
isModuleCached = true;
|
|
718
|
+
}
|
|
719
|
+
} catch (e) {
|
|
720
|
+
// Fallback if browser doesn't allow structured cloning of Compiled Modules
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (!isModuleCached) {
|
|
724
|
+
await cacheWasm(wasmUrl, arrayBuffer);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
let instance;
|
|
728
|
+
if (cachedData instanceof WebAssembly.Module) {
|
|
729
|
+
instance = await WebAssembly.instantiate(cachedData, imports);
|
|
730
|
+
} else {
|
|
731
|
+
const result = await WebAssembly.instantiate(arrayBuffer, imports);
|
|
732
|
+
instance = result.instance;
|
|
733
|
+
}
|
|
734
|
+
successCallback(instance, cachedData);
|
|
735
|
+
} catch (err) {
|
|
736
|
+
console.warn('[Fingerprint] Custom WASM instantiation failed, falling back to default Emscripten loader:', err);
|
|
737
|
+
successCallback(null);
|
|
738
|
+
}
|
|
739
|
+
})();
|
|
740
|
+
return {}; // Async instantiation indicator for Emscripten
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
if (typeof wasmModule._hash_string !== 'function') {
|
|
744
|
+
throw new Error('WASM module did not export _hash_string.');
|
|
745
|
+
}
|
|
746
|
+
window.wasmModule = wasmModule;
|
|
747
|
+
ClientLibrary.wasmModule = wasmModule;
|
|
748
|
+
|
|
749
|
+
// 4. Remplacer la fonction de hachage par la version WASM
|
|
750
|
+
activeCyrb53 = (str) => {
|
|
751
|
+
// La fonction C++ attend un pointeur, Emscripten gère la conversion
|
|
752
|
+
return wasmModule._hash_string(str);
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
console.log('[Fingerprint] WASM module loaded successfully. Using fast hashing.');
|
|
756
|
+
// NOUVEAU: Ajoute un indicateur à l'empreinte pour que le serveur sache que le WASM est actif.
|
|
757
|
+
if (this._cachedBuilder) {
|
|
758
|
+
this._cachedBuilder.addRaw('wasm', 'true');
|
|
759
|
+
}
|
|
760
|
+
} catch (error) {
|
|
761
|
+
console.warn('[Fingerprint] WASM module failed to load. Falling back to JS implementation. Error:', error);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* @typedef {object} ClientBehaviorMetrics
|
|
768
|
+
* @property {number} mouseEntropy - Entropie des mouvements de la souris.
|
|
769
|
+
* @property {Array<{x: number, y: number, t: number}>} mouseMovementsHistory - Historique des points de la souris.
|
|
770
|
+
* @property {number} keystrokeLatency - Latence moyenne entre les frappes.
|
|
771
|
+
* @property {boolean} honeypotInteraction - Vrai si un honeypot a été touché.
|
|
772
|
+
* @property {Array<{x: number, y: number, t: number, targetId: string}>} clicksHistory - Historique des clics.
|
|
773
|
+
* @property {Array<{x: number, y: number, t: number, p: number, r: number, num: number}>} touchMovementsHistory - Historique des glissements tactiles.
|
|
774
|
+
* @property {number} historyLength - La longueur de l'historique de session du navigateur (`window.history.length`).
|
|
775
|
+
* @property {number} clientTimestamp - Timestamp (Date.now()) de la collecte des métriques.
|
|
776
|
+
* @property {string[]} [trapUrls] - URLs pièges à injecter dynamiquement.
|
|
777
|
+
*/
|
|
778
|
+
/** @type {ClientBehaviorMetrics} */
|
|
779
|
+
const metrics = {
|
|
780
|
+
mouseEntropy: 0, // Conservé pour la compatibilité, mais l'analyse se fait maintenant sur l'historique
|
|
781
|
+
mouseMovementsHistory: [],
|
|
782
|
+
touchMovementsHistory: [],
|
|
783
|
+
clicksHistory: [],
|
|
784
|
+
keystrokeLatency: 0,
|
|
785
|
+
honeypotInteraction: false,
|
|
786
|
+
historyLength: 0,
|
|
787
|
+
clientTimestamp: 0,
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
let lastMousePos = { x: 0, y: 0 };
|
|
791
|
+
let mouseMovementsHistory = []; // NOUVEAU: Historique des points de la souris
|
|
792
|
+
let touchMovementsHistory = []; // NOUVEAU: Historique des gestes tactiles
|
|
793
|
+
const TOUCH_HISTORY_MAX = 100;
|
|
794
|
+
const MOUSE_HISTORY_MAX = 100; // Limite le nombre de points stockés
|
|
795
|
+
let clicksHistory = [];
|
|
796
|
+
const CLICKS_HISTORY_MAX = 50;
|
|
797
|
+
let activeHoneypotListeners = new Map(); // Garde une trace des écouteurs actifs
|
|
798
|
+
let keystrokeTimestamps = [];
|
|
799
|
+
let keystrokeLatencies = []; // NOUVEAU: Tableau dédié pour les latences
|
|
800
|
+
const KEYSTROKE_HISTORY_MAX = 20; // On garde l'historique des 20 dernières frappes
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
// Exporter les fonctions individuellement pour la compatibilité ascendante
|
|
805
|
+
export const getDeviceFingerprint = ClientLibrary.getDeviceFingerprint.bind(ClientLibrary);
|
|
806
|
+
export const generateRequestSignature = ClientLibrary.generateRequestSignature.bind(ClientLibrary);
|
|
807
|
+
export const generateClientSideSignature = ClientLibrary.generateClientSideSignature.bind(ClientLibrary);
|
|
808
|
+
export const _resetCache = ClientLibrary._resetCache.bind(ClientLibrary);
|
|
809
|
+
export const startMouseEntropyTracker = ClientLibrary.startMouseEntropyTracker.bind(ClientLibrary);
|
|
810
|
+
export const startKeystrokeDynamicsTracker = ClientLibrary.startKeystrokeDynamicsTracker.bind(ClientLibrary);
|
|
811
|
+
export const startClickTracker = ClientLibrary.startClickTracker.bind(ClientLibrary);
|
|
812
|
+
export const startTouchEventTracker = ClientLibrary.startTouchEventTracker.bind(ClientLibrary);
|
|
813
|
+
export const initializeHoneypots = ClientLibrary.initializeHoneypots.bind(ClientLibrary);
|
|
814
|
+
export const getClientBehaviorMetrics = ClientLibrary.getClientBehaviorMetrics.bind(ClientLibrary);
|
|
815
|
+
export const protectedFetch = ClientLibrary.protectedFetch.bind(ClientLibrary);
|
|
816
|
+
export const addFetchInterceptor = ClientLibrary.addFetchInterceptor.bind(ClientLibrary);
|
|
817
|
+
export const patchGlobalFetch = ClientLibrary.patchGlobalFetch.bind(ClientLibrary);
|
|
818
|
+
export const initializeFetch = ClientLibrary.initializeFetch.bind(ClientLibrary);
|
|
819
|
+
export const initializeClient = ClientLibrary.initializeClient.bind(ClientLibrary);
|
|
820
|
+
export const initializeWasm = ClientLibrary.initializeWasm.bind(ClientLibrary);
|
|
821
|
+
export const injectTrapLinks = ClientLibrary.injectTrapLinks.bind(ClientLibrary);
|
|
822
|
+
export const injectPhantomTraps = ClientLibrary.injectPhantomTraps.bind(ClientLibrary);
|
|
823
|
+
export const solveChallengeAndRetry = ClientLibrary.solveChallengeAndRetry.bind(ClientLibrary);
|
|
824
|
+
|
|
825
|
+
// Export the internal object for testing purposes
|
|
826
|
+
export default ClientLibrary;
|
|
827
|
+
|
|
828
|
+
// --- Global Export for Browser ---
|
|
829
|
+
// Attach the library to the window object to make it accessible from inline scripts.
|
|
830
|
+
if (typeof window !== 'undefined') {
|
|
831
|
+
window.ClientLibrary = ClientLibrary;
|
|
636
832
|
}
|