@webdecoy/client 0.3.0
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/README.md +108 -0
- package/dist/index.d.mts +469 -0
- package/dist/index.d.ts +469 -0
- package/dist/index.js +2335 -0
- package/dist/index.mjs +2312 -0
- package/dist/webdecoy.global.js +110 -0
- package/package.json +61 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2312 @@
|
|
|
1
|
+
// src/collectors/behavioral.ts
|
|
2
|
+
var BehavioralCollector = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.mousePositions = [];
|
|
5
|
+
this.mouseVelocities = [];
|
|
6
|
+
this.mouseAccelerations = [];
|
|
7
|
+
this.scrollEvents = [];
|
|
8
|
+
this.keyEvents = [];
|
|
9
|
+
this.touchEvents = [];
|
|
10
|
+
this.touchMultiTouchSeen = false;
|
|
11
|
+
this.touchIdentifiers = /* @__PURE__ */ new Set();
|
|
12
|
+
this.pointerPoints = [];
|
|
13
|
+
this.focusEvents = [];
|
|
14
|
+
this.clickData = null;
|
|
15
|
+
this.startTime = Date.now();
|
|
16
|
+
this.lastMousePos = null;
|
|
17
|
+
this.lastMouseTime = null;
|
|
18
|
+
this.lastVelocity = null;
|
|
19
|
+
this.eventDeltas = [];
|
|
20
|
+
}
|
|
21
|
+
recordMouseMove(e) {
|
|
22
|
+
const now = performance.now();
|
|
23
|
+
const pos = { x: e.clientX, y: e.clientY, t: now };
|
|
24
|
+
this.mousePositions.push(pos);
|
|
25
|
+
if (this.lastMousePos && this.lastMouseTime) {
|
|
26
|
+
const dt = now - this.lastMouseTime;
|
|
27
|
+
if (dt > 0) {
|
|
28
|
+
const dx = e.clientX - this.lastMousePos.x;
|
|
29
|
+
const dy = e.clientY - this.lastMousePos.y;
|
|
30
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
31
|
+
const velocity = distance / dt;
|
|
32
|
+
this.mouseVelocities.push({ v: velocity, t: now });
|
|
33
|
+
this.eventDeltas.push(dt);
|
|
34
|
+
if (this.lastVelocity !== null) {
|
|
35
|
+
const acceleration = (velocity - this.lastVelocity) / dt;
|
|
36
|
+
this.mouseAccelerations.push({ a: acceleration, t: now });
|
|
37
|
+
}
|
|
38
|
+
this.lastVelocity = velocity;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
this.lastMousePos = { x: e.clientX, y: e.clientY };
|
|
42
|
+
this.lastMouseTime = now;
|
|
43
|
+
if (this.mousePositions.length > 500) {
|
|
44
|
+
this.mousePositions.shift();
|
|
45
|
+
if (this.mouseVelocities.length > 500) this.mouseVelocities.shift();
|
|
46
|
+
if (this.mouseAccelerations.length > 500) this.mouseAccelerations.shift();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
recordMouseDown(e) {
|
|
50
|
+
this.clickData = {
|
|
51
|
+
x: e.clientX,
|
|
52
|
+
y: e.clientY,
|
|
53
|
+
button: e.button,
|
|
54
|
+
downTime: performance.now()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
recordMouseUp(_e) {
|
|
58
|
+
if (this.clickData) {
|
|
59
|
+
this.clickData.upTime = performance.now();
|
|
60
|
+
this.clickData.holdDuration = this.clickData.upTime - this.clickData.downTime;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
recordScroll(_e) {
|
|
64
|
+
this.scrollEvents.push({
|
|
65
|
+
x: window.scrollX,
|
|
66
|
+
y: window.scrollY,
|
|
67
|
+
t: performance.now()
|
|
68
|
+
});
|
|
69
|
+
if (this.scrollEvents.length > 100) this.scrollEvents.shift();
|
|
70
|
+
}
|
|
71
|
+
recordKeyEvent(e) {
|
|
72
|
+
this.keyEvents.push({
|
|
73
|
+
type: e.type,
|
|
74
|
+
keyLength: e.key ? e.key.length : 0,
|
|
75
|
+
// Don't store actual keys
|
|
76
|
+
t: performance.now()
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
recordTouch(e) {
|
|
80
|
+
const touches = e.touches && e.touches.length ? e.touches : e.changedTouches;
|
|
81
|
+
if (!touches || touches.length === 0) return;
|
|
82
|
+
if (touches.length > 1) this.touchMultiTouchSeen = true;
|
|
83
|
+
const touch = touches[0];
|
|
84
|
+
if (typeof touch.identifier === "number") this.touchIdentifiers.add(touch.identifier);
|
|
85
|
+
this.touchEvents.push({
|
|
86
|
+
x: touch.clientX,
|
|
87
|
+
y: touch.clientY,
|
|
88
|
+
t: performance.now(),
|
|
89
|
+
force: typeof touch.force === "number" ? touch.force : 0,
|
|
90
|
+
radiusX: typeof touch.radiusX === "number" ? touch.radiusX : 0,
|
|
91
|
+
radiusY: typeof touch.radiusY === "number" ? touch.radiusY : 0,
|
|
92
|
+
rotationAngle: typeof touch.rotationAngle === "number" ? touch.rotationAngle : 0,
|
|
93
|
+
identifier: typeof touch.identifier === "number" ? touch.identifier : -1,
|
|
94
|
+
touchCount: touches.length
|
|
95
|
+
});
|
|
96
|
+
if (this.touchEvents.length > 500) this.touchEvents.shift();
|
|
97
|
+
}
|
|
98
|
+
recordPointer(e) {
|
|
99
|
+
this.pointerPoints.push({
|
|
100
|
+
x: e.clientX,
|
|
101
|
+
y: e.clientY,
|
|
102
|
+
t: performance.now(),
|
|
103
|
+
type: e.type,
|
|
104
|
+
pressure: typeof e.pressure === "number" ? e.pressure : 0,
|
|
105
|
+
tiltX: typeof e.tiltX === "number" ? e.tiltX : 0,
|
|
106
|
+
tiltY: typeof e.tiltY === "number" ? e.tiltY : 0,
|
|
107
|
+
tangentialPressure: typeof e.tangentialPressure === "number" ? e.tangentialPressure : 0,
|
|
108
|
+
pointerType: e.pointerType || "unknown"
|
|
109
|
+
});
|
|
110
|
+
if (this.pointerPoints.length > 500) this.pointerPoints.shift();
|
|
111
|
+
}
|
|
112
|
+
recordFocus(e) {
|
|
113
|
+
var _a;
|
|
114
|
+
this.focusEvents.push({
|
|
115
|
+
type: e.type,
|
|
116
|
+
target: (_a = e.target) == null ? void 0 : _a.tagName,
|
|
117
|
+
t: performance.now()
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
analyze() {
|
|
121
|
+
const positions = this.mousePositions;
|
|
122
|
+
const velocities = this.mouseVelocities;
|
|
123
|
+
const accelerations = this.mouseAccelerations;
|
|
124
|
+
if (positions.length < 10) {
|
|
125
|
+
return this._getEmptyAnalysis();
|
|
126
|
+
}
|
|
127
|
+
let avgVelocity = 0;
|
|
128
|
+
let velocityVariance = 0;
|
|
129
|
+
if (velocities.length > 0) {
|
|
130
|
+
const sum = velocities.reduce((acc, v) => acc + v.v, 0);
|
|
131
|
+
avgVelocity = sum / velocities.length;
|
|
132
|
+
velocityVariance = velocities.reduce((acc, v) => {
|
|
133
|
+
return acc + Math.pow(v.v - avgVelocity, 2);
|
|
134
|
+
}, 0) / velocities.length;
|
|
135
|
+
}
|
|
136
|
+
let avgAcceleration = 0;
|
|
137
|
+
let accelerationChanges = 0;
|
|
138
|
+
if (accelerations.length > 0) {
|
|
139
|
+
avgAcceleration = accelerations.reduce((acc, a) => acc + a.a, 0) / accelerations.length;
|
|
140
|
+
for (let i = 1; i < accelerations.length; i++) {
|
|
141
|
+
if (Math.sign(accelerations[i].a) !== Math.sign(accelerations[i - 1].a)) {
|
|
142
|
+
accelerationChanges++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const microTremorScore = this._detectMicroTremor(positions);
|
|
147
|
+
const straightLineRatio = this._calculateStraightLineRatio(positions);
|
|
148
|
+
let microMovements = 0;
|
|
149
|
+
for (let i = 1; i < positions.length; i++) {
|
|
150
|
+
const dx = Math.abs(positions[i].x - positions[i - 1].x);
|
|
151
|
+
const dy = Math.abs(positions[i].y - positions[i - 1].y);
|
|
152
|
+
if (dx < 3 && dy < 3 && (dx > 0 || dy > 0)) {
|
|
153
|
+
microMovements++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const directionChanges = this._countDirectionChanges(positions);
|
|
157
|
+
const eventDeltaVariance = this._variance(this.eventDeltas);
|
|
158
|
+
const mouseEventRate = positions.length > 1 ? positions.length / ((positions[positions.length - 1].t - positions[0].t) / 1e3) : 0;
|
|
159
|
+
let trajectoryLength = 0;
|
|
160
|
+
for (let i = 1; i < positions.length; i++) {
|
|
161
|
+
const dx = positions[i].x - positions[i - 1].x;
|
|
162
|
+
const dy = positions[i].y - positions[i - 1].y;
|
|
163
|
+
trajectoryLength += Math.sqrt(dx * dx + dy * dy);
|
|
164
|
+
}
|
|
165
|
+
const touchAnalysis = this._analyzeTouchPoints(this.touchEvents);
|
|
166
|
+
const pointerAnalysis = this._analyzePointerPoints(this.pointerPoints);
|
|
167
|
+
return {
|
|
168
|
+
totalPoints: positions.length,
|
|
169
|
+
trajectoryLength,
|
|
170
|
+
avgVelocity,
|
|
171
|
+
velocityVariance,
|
|
172
|
+
avgAcceleration,
|
|
173
|
+
accelerationChanges,
|
|
174
|
+
microTremorScore,
|
|
175
|
+
straightLineRatio,
|
|
176
|
+
microMovements,
|
|
177
|
+
directionChanges,
|
|
178
|
+
eventDeltas: this.eventDeltas.slice(-50),
|
|
179
|
+
eventDeltaVariance,
|
|
180
|
+
mouseEventRate,
|
|
181
|
+
scrollEvents: this.scrollEvents.length,
|
|
182
|
+
keyEvents: this.keyEvents.length,
|
|
183
|
+
touchEvents: this.touchEvents.length,
|
|
184
|
+
focusEvents: this.focusEvents.length,
|
|
185
|
+
clickData: this.clickData,
|
|
186
|
+
interactionDuration: Date.now() - this.startTime,
|
|
187
|
+
...touchAnalysis,
|
|
188
|
+
...pointerAnalysis
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
_analyzeTouchPoints(touches) {
|
|
192
|
+
if (!touches || touches.length === 0) {
|
|
193
|
+
return {
|
|
194
|
+
touchTotalPoints: 0,
|
|
195
|
+
touchTrajectoryLength: 0,
|
|
196
|
+
touchAvgVelocity: 0,
|
|
197
|
+
touchVelocityVariance: 0,
|
|
198
|
+
touchMicroTremorScore: 0,
|
|
199
|
+
touchStraightLineRatio: 0,
|
|
200
|
+
touchDirectionChanges: 0,
|
|
201
|
+
touchForceMin: 0,
|
|
202
|
+
touchForceMax: 0,
|
|
203
|
+
touchForceVariance: 0,
|
|
204
|
+
touchRadiusMin: 0,
|
|
205
|
+
touchRadiusMax: 0,
|
|
206
|
+
touchRadiusVariance: 0,
|
|
207
|
+
touchMultiTouchSeen: this.touchMultiTouchSeen,
|
|
208
|
+
touchUniqueIdentifiers: this.touchIdentifiers.size,
|
|
209
|
+
touchForceAllZero: false,
|
|
210
|
+
touchForceAllOne: false
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
let trajLen = 0;
|
|
214
|
+
const vels = [];
|
|
215
|
+
for (let i = 1; i < touches.length; i++) {
|
|
216
|
+
const dx = touches[i].x - touches[i - 1].x;
|
|
217
|
+
const dy = touches[i].y - touches[i - 1].y;
|
|
218
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
219
|
+
trajLen += dist;
|
|
220
|
+
const dt = touches[i].t - touches[i - 1].t;
|
|
221
|
+
if (dt > 0) vels.push(dist / dt);
|
|
222
|
+
}
|
|
223
|
+
const avgVel = vels.length > 0 ? vels.reduce((a, b) => a + b, 0) / vels.length : 0;
|
|
224
|
+
const forces = touches.map((p) => p.force);
|
|
225
|
+
const radii = touches.map((p) => Math.max(p.radiusX || 0, p.radiusY || 0));
|
|
226
|
+
const forceAllZero = forces.length > 0 && forces.every((f) => f === 0);
|
|
227
|
+
const forceAllOne = forces.length > 0 && forces.every((f) => f === 1);
|
|
228
|
+
return {
|
|
229
|
+
touchTotalPoints: touches.length,
|
|
230
|
+
touchTrajectoryLength: trajLen,
|
|
231
|
+
touchAvgVelocity: avgVel,
|
|
232
|
+
touchVelocityVariance: this._variance(vels),
|
|
233
|
+
touchMicroTremorScore: this._detectMicroTremor(touches),
|
|
234
|
+
touchStraightLineRatio: this._calculateStraightLineRatio(touches),
|
|
235
|
+
touchDirectionChanges: this._countDirectionChanges(touches),
|
|
236
|
+
touchForceMin: forces.length > 0 ? Math.min(...forces) : 0,
|
|
237
|
+
touchForceMax: forces.length > 0 ? Math.max(...forces) : 0,
|
|
238
|
+
touchForceVariance: this._variance(forces),
|
|
239
|
+
touchRadiusMin: radii.length > 0 ? Math.min(...radii) : 0,
|
|
240
|
+
touchRadiusMax: radii.length > 0 ? Math.max(...radii) : 0,
|
|
241
|
+
touchRadiusVariance: this._variance(radii),
|
|
242
|
+
touchMultiTouchSeen: this.touchMultiTouchSeen,
|
|
243
|
+
touchUniqueIdentifiers: this.touchIdentifiers.size,
|
|
244
|
+
touchForceAllZero: forceAllZero,
|
|
245
|
+
touchForceAllOne: forceAllOne
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
_analyzePointerPoints(points) {
|
|
249
|
+
if (!points || points.length === 0) {
|
|
250
|
+
return {
|
|
251
|
+
pointerEvents: 0,
|
|
252
|
+
pointerAvgPressure: 0,
|
|
253
|
+
pointerPressureVariance: 0,
|
|
254
|
+
pointerMaxTilt: 0,
|
|
255
|
+
pointerHasNonMouseType: false,
|
|
256
|
+
pointerTypes: []
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const pressures = points.map((p) => p.pressure);
|
|
260
|
+
const avgP = pressures.length > 0 ? pressures.reduce((a, b) => a + b, 0) / pressures.length : 0;
|
|
261
|
+
let maxTilt = 0;
|
|
262
|
+
const types = /* @__PURE__ */ new Set();
|
|
263
|
+
for (const p of points) {
|
|
264
|
+
const tilt = Math.abs(p.tiltX || 0) + Math.abs(p.tiltY || 0);
|
|
265
|
+
if (tilt > maxTilt) maxTilt = tilt;
|
|
266
|
+
if (p.pointerType) types.add(p.pointerType);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
pointerEvents: points.length,
|
|
270
|
+
pointerAvgPressure: avgP,
|
|
271
|
+
pointerPressureVariance: this._variance(pressures),
|
|
272
|
+
pointerMaxTilt: maxTilt,
|
|
273
|
+
pointerHasNonMouseType: Array.from(types).some((t) => t !== "mouse" && t !== "unknown"),
|
|
274
|
+
pointerTypes: Array.from(types)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
analyzeClick(clickX, clickY, targetRect) {
|
|
278
|
+
const positions = this.mousePositions;
|
|
279
|
+
if (positions.length < 5) {
|
|
280
|
+
return this._getEmptyClickAnalysis();
|
|
281
|
+
}
|
|
282
|
+
const approachPoints = positions.slice(-20);
|
|
283
|
+
const targetCenterX = targetRect.left + targetRect.width / 2;
|
|
284
|
+
const targetCenterY = targetRect.top + targetRect.height / 2;
|
|
285
|
+
const clickPrecision = Math.sqrt(
|
|
286
|
+
Math.pow(clickX - targetCenterX, 2) + Math.pow(clickY - targetCenterY, 2)
|
|
287
|
+
);
|
|
288
|
+
let outsideMovement = 0;
|
|
289
|
+
let totalMovement = 0;
|
|
290
|
+
for (let i = 1; i < positions.length; i++) {
|
|
291
|
+
const dist = Math.sqrt(
|
|
292
|
+
Math.pow(positions[i].x - positions[i - 1].x, 2) + Math.pow(positions[i].y - positions[i - 1].y, 2)
|
|
293
|
+
);
|
|
294
|
+
totalMovement += dist;
|
|
295
|
+
const inTarget = positions[i].x >= targetRect.left && positions[i].x <= targetRect.right && positions[i].y >= targetRect.top && positions[i].y <= targetRect.bottom;
|
|
296
|
+
if (!inTarget) outsideMovement += dist;
|
|
297
|
+
}
|
|
298
|
+
const explorationRatio = totalMovement > 0 ? outsideMovement / totalMovement : 0;
|
|
299
|
+
let overshoots = 0;
|
|
300
|
+
let wasInTarget = false;
|
|
301
|
+
let passedTarget = false;
|
|
302
|
+
for (const point of approachPoints) {
|
|
303
|
+
const inTarget = point.x >= targetRect.left && point.x <= targetRect.right && point.y >= targetRect.top && point.y <= targetRect.bottom;
|
|
304
|
+
if (wasInTarget && !inTarget) passedTarget = true;
|
|
305
|
+
if (passedTarget && inTarget) {
|
|
306
|
+
overshoots++;
|
|
307
|
+
passedTarget = false;
|
|
308
|
+
}
|
|
309
|
+
wasInTarget = inTarget;
|
|
310
|
+
}
|
|
311
|
+
let hoverTime = 0;
|
|
312
|
+
for (let i = approachPoints.length - 1; i >= 0; i--) {
|
|
313
|
+
const point = approachPoints[i];
|
|
314
|
+
const inTarget = point.x >= targetRect.left && point.x <= targetRect.right && point.y >= targetRect.top && point.y <= targetRect.bottom;
|
|
315
|
+
if (inTarget && i < approachPoints.length - 1) {
|
|
316
|
+
hoverTime = approachPoints[approachPoints.length - 1].t - point.t;
|
|
317
|
+
} else if (!inTarget) {
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const directDistance = Math.sqrt(
|
|
322
|
+
Math.pow(approachPoints[approachPoints.length - 1].x - approachPoints[0].x, 2) + Math.pow(approachPoints[approachPoints.length - 1].y - approachPoints[0].y, 2)
|
|
323
|
+
);
|
|
324
|
+
let approachPathLength = 0;
|
|
325
|
+
for (let i = 1; i < approachPoints.length; i++) {
|
|
326
|
+
approachPathLength += Math.sqrt(
|
|
327
|
+
Math.pow(approachPoints[i].x - approachPoints[i - 1].x, 2) + Math.pow(approachPoints[i].y - approachPoints[i - 1].y, 2)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const approachDirectness = approachPathLength > 0 ? directDistance / approachPathLength : 1;
|
|
331
|
+
return {
|
|
332
|
+
clickPrecision,
|
|
333
|
+
explorationRatio,
|
|
334
|
+
overshootCorrections: overshoots,
|
|
335
|
+
hoverTime,
|
|
336
|
+
approachDirectness,
|
|
337
|
+
approachPoints: approachPoints.length
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
_detectMicroTremor(positions) {
|
|
341
|
+
if (positions.length < 20) return 0.5;
|
|
342
|
+
const windowSize = 5;
|
|
343
|
+
let totalNoise = 0;
|
|
344
|
+
for (let i = windowSize; i < positions.length - windowSize; i++) {
|
|
345
|
+
let smoothX = 0, smoothY = 0;
|
|
346
|
+
for (let j = i - windowSize; j <= i + windowSize; j++) {
|
|
347
|
+
smoothX += positions[j].x;
|
|
348
|
+
smoothY += positions[j].y;
|
|
349
|
+
}
|
|
350
|
+
smoothX /= windowSize * 2 + 1;
|
|
351
|
+
smoothY /= windowSize * 2 + 1;
|
|
352
|
+
const deviation = Math.sqrt(
|
|
353
|
+
Math.pow(positions[i].x - smoothX, 2) + Math.pow(positions[i].y - smoothY, 2)
|
|
354
|
+
);
|
|
355
|
+
totalNoise += deviation;
|
|
356
|
+
}
|
|
357
|
+
const avgNoise = totalNoise / (positions.length - windowSize * 2);
|
|
358
|
+
return Math.min(1, avgNoise / 2);
|
|
359
|
+
}
|
|
360
|
+
_calculateStraightLineRatio(positions) {
|
|
361
|
+
if (positions.length < 3) return 0;
|
|
362
|
+
let straightSegments = 0;
|
|
363
|
+
let totalSegments = 0;
|
|
364
|
+
for (let i = 2; i < positions.length; i++) {
|
|
365
|
+
const p1 = positions[i - 2];
|
|
366
|
+
const p2 = positions[i - 1];
|
|
367
|
+
const p3 = positions[i];
|
|
368
|
+
const angle1 = Math.atan2(p2.y - p1.y, p2.x - p1.x);
|
|
369
|
+
const angle2 = Math.atan2(p3.y - p2.y, p3.x - p2.x);
|
|
370
|
+
const angleDiff = Math.abs(angle2 - angle1);
|
|
371
|
+
totalSegments++;
|
|
372
|
+
if (angleDiff < 0.1) straightSegments++;
|
|
373
|
+
}
|
|
374
|
+
return totalSegments > 0 ? straightSegments / totalSegments : 0;
|
|
375
|
+
}
|
|
376
|
+
_countDirectionChanges(positions) {
|
|
377
|
+
let changes = 0;
|
|
378
|
+
for (let i = 2; i < positions.length; i++) {
|
|
379
|
+
const angle1 = Math.atan2(
|
|
380
|
+
positions[i - 1].y - positions[i - 2].y,
|
|
381
|
+
positions[i - 1].x - positions[i - 2].x
|
|
382
|
+
);
|
|
383
|
+
const angle2 = Math.atan2(
|
|
384
|
+
positions[i].y - positions[i - 1].y,
|
|
385
|
+
positions[i].x - positions[i - 1].x
|
|
386
|
+
);
|
|
387
|
+
if (Math.abs(angle2 - angle1) > Math.PI / 6) changes++;
|
|
388
|
+
}
|
|
389
|
+
return changes;
|
|
390
|
+
}
|
|
391
|
+
_variance(arr) {
|
|
392
|
+
if (arr.length === 0) return 0;
|
|
393
|
+
const mean = arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
394
|
+
return arr.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / arr.length;
|
|
395
|
+
}
|
|
396
|
+
_getEmptyAnalysis() {
|
|
397
|
+
return {
|
|
398
|
+
totalPoints: 0,
|
|
399
|
+
trajectoryLength: 0,
|
|
400
|
+
avgVelocity: 0,
|
|
401
|
+
velocityVariance: 0,
|
|
402
|
+
avgAcceleration: 0,
|
|
403
|
+
accelerationChanges: 0,
|
|
404
|
+
microTremorScore: 0.5,
|
|
405
|
+
straightLineRatio: 0,
|
|
406
|
+
microMovements: 0,
|
|
407
|
+
directionChanges: 0,
|
|
408
|
+
eventDeltas: [],
|
|
409
|
+
eventDeltaVariance: 0,
|
|
410
|
+
mouseEventRate: 0,
|
|
411
|
+
scrollEvents: this.scrollEvents.length,
|
|
412
|
+
keyEvents: this.keyEvents.length,
|
|
413
|
+
touchEvents: this.touchEvents.length,
|
|
414
|
+
focusEvents: this.focusEvents.length,
|
|
415
|
+
clickData: this.clickData,
|
|
416
|
+
interactionDuration: Date.now() - this.startTime,
|
|
417
|
+
...this._analyzeTouchPoints(this.touchEvents),
|
|
418
|
+
...this._analyzePointerPoints(this.pointerPoints)
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
_getEmptyClickAnalysis() {
|
|
422
|
+
return {
|
|
423
|
+
clickPrecision: 0,
|
|
424
|
+
explorationRatio: 0,
|
|
425
|
+
overshootCorrections: 0,
|
|
426
|
+
hoverTime: 0,
|
|
427
|
+
approachDirectness: 1,
|
|
428
|
+
approachPoints: 0
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// src/collectors/environment.ts
|
|
434
|
+
var EnvironmentalCollector = class {
|
|
435
|
+
collect() {
|
|
436
|
+
return {
|
|
437
|
+
// Comprehensive automation detection
|
|
438
|
+
webdriver: this._detectWebdriver(),
|
|
439
|
+
automationFlags: this._getAutomationFlags(),
|
|
440
|
+
cdp: this._detectCDP(),
|
|
441
|
+
playwright: this._detectPlaywright(),
|
|
442
|
+
// Browser fingerprints
|
|
443
|
+
canvasHash: this._getCanvasHash(),
|
|
444
|
+
webglInfo: this._getWebGLInfo(),
|
|
445
|
+
audioInfo: this._getAudioInfo(),
|
|
446
|
+
// Headless detection
|
|
447
|
+
headlessIndicators: this._getHeadlessIndicators(),
|
|
448
|
+
// System info
|
|
449
|
+
screen: this._getScreenInfo(),
|
|
450
|
+
navigator: this._getNavigatorInfo(),
|
|
451
|
+
// Timing fingerprints
|
|
452
|
+
jsExecutionTime: this._measureJSExecution(),
|
|
453
|
+
// Advanced fingerprint detections
|
|
454
|
+
mathFingerprint: this._getMathFingerprint(),
|
|
455
|
+
errorFingerprint: this._getErrorFingerprint(),
|
|
456
|
+
domRectFingerprint: this._getDOMRectFingerprint(),
|
|
457
|
+
cssMediaQueries: this._getCSSMediaQueries(),
|
|
458
|
+
permissionsInfo: this._getPermissionsInfo(),
|
|
459
|
+
fontsInfo: this._getFontsInfo()
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// Async detections collected separately
|
|
463
|
+
async collectAsync() {
|
|
464
|
+
const [speechInfo, webrtcInfo, workerConsistency] = await Promise.all([
|
|
465
|
+
this._getSpeechInfo(),
|
|
466
|
+
this._getWebRTCInfo(),
|
|
467
|
+
this._checkWorkerConsistency()
|
|
468
|
+
]);
|
|
469
|
+
return { speechInfo, webrtcInfo, workerConsistency };
|
|
470
|
+
}
|
|
471
|
+
_detectWebdriver() {
|
|
472
|
+
const nav = navigator;
|
|
473
|
+
const w = window;
|
|
474
|
+
return !!(nav.webdriver || w.document.__webdriver_evaluate || w.document.__selenium_evaluate || w.document.__webdriver_script_fn || w.document.__webdriver_script_func || w.document.__webdriver_script_function || w.document["$cdc_asdjflasutopfhvcZLmcfl_"] || w.document["$wdc_"] || w["_Selenium_IDE_Recorder"] || w["_phantom"] || w["__nightmare"] || w.callPhantom || w._phantom);
|
|
475
|
+
}
|
|
476
|
+
_getAutomationFlags() {
|
|
477
|
+
const nav = navigator;
|
|
478
|
+
const w = window;
|
|
479
|
+
return {
|
|
480
|
+
// Core automation
|
|
481
|
+
webdriver: !!nav.webdriver,
|
|
482
|
+
domAutomation: !!w.domAutomation,
|
|
483
|
+
domAutomationController: !!w.domAutomationController,
|
|
484
|
+
// Selenium
|
|
485
|
+
_selenium: !!w._selenium,
|
|
486
|
+
__webdriver_script_fn: !!w.__webdriver_script_fn,
|
|
487
|
+
__driver_evaluate: !!w.__driver_evaluate,
|
|
488
|
+
__webdriver_evaluate: !!w.__webdriver_evaluate,
|
|
489
|
+
__fxdriver_evaluate: !!w.__fxdriver_evaluate,
|
|
490
|
+
__driver_unwrapped: !!w.__driver_unwrapped,
|
|
491
|
+
__webdriver_unwrapped: !!w.__webdriver_unwrapped,
|
|
492
|
+
__fxdriver_unwrapped: !!w.__fxdriver_unwrapped,
|
|
493
|
+
_Selenium_IDE_Recorder: !!w._Selenium_IDE_Recorder,
|
|
494
|
+
calledSelenium: !!w.calledSelenium,
|
|
495
|
+
$chrome_asyncScriptInfo: !!w.$chrome_asyncScriptInfo,
|
|
496
|
+
$cdc_asdjflasutopfhvcZLmcfl_: !!w.$cdc_asdjflasutopfhvcZLmcfl_,
|
|
497
|
+
// PhantomJS
|
|
498
|
+
_phantom: !!w._phantom,
|
|
499
|
+
callPhantom: !!w.callPhantom,
|
|
500
|
+
// Nightmare
|
|
501
|
+
__nightmare: !!w.__nightmare,
|
|
502
|
+
// Watir
|
|
503
|
+
__lastWatirAlert: !!w.__lastWatirAlert,
|
|
504
|
+
__lastWatirConfirm: !!w.__lastWatirConfirm,
|
|
505
|
+
__lastWatirPrompt: !!w.__lastWatirPrompt,
|
|
506
|
+
// Browser properties
|
|
507
|
+
plugins: navigator.plugins ? navigator.plugins.length : 0,
|
|
508
|
+
languages: navigator.languages && navigator.languages.length > 0,
|
|
509
|
+
mimeTypes: navigator.mimeTypes ? navigator.mimeTypes.length : 0,
|
|
510
|
+
cookieEnabled: navigator.cookieEnabled,
|
|
511
|
+
doNotTrack: navigator.doNotTrack,
|
|
512
|
+
// Chrome specific
|
|
513
|
+
chrome: !!w.chrome,
|
|
514
|
+
chromeRuntime: !!(w.chrome && w.chrome.runtime && w.chrome.runtime.id),
|
|
515
|
+
// Permissions API
|
|
516
|
+
permissionsAPI: !!navigator.permissions
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
_detectPlaywright() {
|
|
520
|
+
try {
|
|
521
|
+
const w = window;
|
|
522
|
+
const signals = [];
|
|
523
|
+
const pwKeys = Object.getOwnPropertyNames(window).filter(
|
|
524
|
+
(k) => k.startsWith("__pw") || k.startsWith("__playwright")
|
|
525
|
+
);
|
|
526
|
+
if (pwKeys.length > 0) signals.push("playwright_globals");
|
|
527
|
+
const proto = Object.getPrototypeOf(navigator);
|
|
528
|
+
const desc = Object.getOwnPropertyDescriptor(proto, "webdriver");
|
|
529
|
+
if (!desc) {
|
|
530
|
+
signals.push("webdriver_deleted");
|
|
531
|
+
} else if (desc.configurable !== false) {
|
|
532
|
+
signals.push("webdriver_configurable");
|
|
533
|
+
}
|
|
534
|
+
const isChrome = /Chrome\//.test(navigator.userAgent) && !/Edg\//.test(navigator.userAgent);
|
|
535
|
+
if (isChrome && w.chrome && !w.chrome.runtime) {
|
|
536
|
+
signals.push("chrome_runtime_missing");
|
|
537
|
+
}
|
|
538
|
+
return { detected: signals.length > 0, signals };
|
|
539
|
+
} catch (e) {
|
|
540
|
+
return { detected: false, signals: [] };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
_detectCDP() {
|
|
544
|
+
try {
|
|
545
|
+
const w = window;
|
|
546
|
+
const signals = [];
|
|
547
|
+
const cdcKeys = Object.keys(window).filter((k) => k.startsWith("cdc_"));
|
|
548
|
+
if (cdcKeys.length > 0) {
|
|
549
|
+
signals.push("chromedriver_cdc");
|
|
550
|
+
}
|
|
551
|
+
if ("__webdriver_evaluate" in window) signals.push("selenium_evaluate");
|
|
552
|
+
if ("__driver_evaluate" in window) signals.push("selenium_driver_evaluate");
|
|
553
|
+
if ("__webdriver_unwrapped" in window) signals.push("selenium_unwrapped");
|
|
554
|
+
if ("__driver_unwrapped" in window) signals.push("selenium_driver_unwrapped");
|
|
555
|
+
if ("__selenium_evaluate" in window) signals.push("selenium_direct");
|
|
556
|
+
if ("__fxdriver_evaluate" in window) signals.push("firefox_driver");
|
|
557
|
+
if ("__fxdriver_unwrapped" in window) signals.push("firefox_driver_unwrapped");
|
|
558
|
+
if ("__puppeteer_evaluation_script__" in window) signals.push("puppeteer_eval");
|
|
559
|
+
if (document.__webdriver_script_fn) signals.push("cdp_script_injection");
|
|
560
|
+
try {
|
|
561
|
+
const descriptor = Object.getOwnPropertyDescriptor(navigator, "webdriver");
|
|
562
|
+
if (descriptor && typeof descriptor.get === "function") {
|
|
563
|
+
const getterStr = descriptor.get.toString();
|
|
564
|
+
if (getterStr.indexOf("[native code]") === -1) {
|
|
565
|
+
signals.push("webdriver_getter_modified");
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
} catch (e) {
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
detected: signals.length > 0,
|
|
572
|
+
signals
|
|
573
|
+
};
|
|
574
|
+
} catch (e) {
|
|
575
|
+
return { detected: false, signals: [] };
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
_getCanvasHash() {
|
|
579
|
+
try {
|
|
580
|
+
const canvas = document.createElement("canvas");
|
|
581
|
+
canvas.width = 200;
|
|
582
|
+
canvas.height = 50;
|
|
583
|
+
const ctx = canvas.getContext("2d");
|
|
584
|
+
ctx.textBaseline = "top";
|
|
585
|
+
ctx.font = "14px Arial";
|
|
586
|
+
ctx.fillStyle = "#f60";
|
|
587
|
+
ctx.fillRect(125, 1, 62, 20);
|
|
588
|
+
ctx.fillStyle = "#069";
|
|
589
|
+
ctx.fillText("FCaptcha", 2, 15);
|
|
590
|
+
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
|
|
591
|
+
ctx.fillText("FCaptcha", 4, 17);
|
|
592
|
+
const dataUrl = canvas.toDataURL();
|
|
593
|
+
let hash = 0;
|
|
594
|
+
for (let i = 0; i < dataUrl.length; i++) {
|
|
595
|
+
hash = (hash << 5) - hash + dataUrl.charCodeAt(i);
|
|
596
|
+
hash = hash & hash;
|
|
597
|
+
}
|
|
598
|
+
return { hash: hash.toString(16), dataLength: dataUrl.length, supported: true };
|
|
599
|
+
} catch (e) {
|
|
600
|
+
return { error: true, supported: false };
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
_getWebGLInfo() {
|
|
604
|
+
try {
|
|
605
|
+
const canvas = document.createElement("canvas");
|
|
606
|
+
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
607
|
+
if (!gl) return { supported: false };
|
|
608
|
+
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
609
|
+
const vendor = debugInfo ? gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) : "unknown";
|
|
610
|
+
const renderer = debugInfo ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : "unknown";
|
|
611
|
+
const rendererLower = renderer.toLowerCase();
|
|
612
|
+
const suspiciousRenderer = rendererLower.includes("swiftshader") || rendererLower.includes("llvmpipe") || rendererLower.includes("softpipe") || rendererLower.includes("virtualbox") || rendererLower.includes("vmware");
|
|
613
|
+
return {
|
|
614
|
+
supported: true,
|
|
615
|
+
vendor,
|
|
616
|
+
renderer,
|
|
617
|
+
version: gl.getParameter(gl.VERSION),
|
|
618
|
+
shadingVersion: gl.getParameter(gl.SHADING_LANGUAGE_VERSION),
|
|
619
|
+
suspiciousRenderer
|
|
620
|
+
};
|
|
621
|
+
} catch (e) {
|
|
622
|
+
return { supported: false, error: true };
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
_getAudioInfo() {
|
|
626
|
+
try {
|
|
627
|
+
const w = window;
|
|
628
|
+
const AudioContextCtor = w.AudioContext || w.webkitAudioContext;
|
|
629
|
+
if (!AudioContextCtor) return { supported: false };
|
|
630
|
+
const audioCtx = new AudioContextCtor();
|
|
631
|
+
const info = {
|
|
632
|
+
supported: true,
|
|
633
|
+
sampleRate: audioCtx.sampleRate,
|
|
634
|
+
state: audioCtx.state,
|
|
635
|
+
baseLatency: audioCtx.baseLatency
|
|
636
|
+
};
|
|
637
|
+
audioCtx.close();
|
|
638
|
+
return info;
|
|
639
|
+
} catch (e) {
|
|
640
|
+
return { supported: false, error: true };
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
_getHeadlessIndicators() {
|
|
644
|
+
const nav = navigator;
|
|
645
|
+
return {
|
|
646
|
+
hasOuterDimensions: window.outerWidth > 0 && window.outerHeight > 0,
|
|
647
|
+
innerEqualsOuter: window.innerWidth === window.outerWidth && window.innerHeight === window.outerHeight,
|
|
648
|
+
screenColorDepth: window.screen.colorDepth,
|
|
649
|
+
screenPixelDepth: window.screen.pixelDepth,
|
|
650
|
+
connectionType: nav.connection ? nav.connection.type : "unknown",
|
|
651
|
+
connectionRtt: nav.connection ? nav.connection.rtt : -1,
|
|
652
|
+
notificationPermission: typeof Notification !== "undefined" ? Notification.permission : "unsupported",
|
|
653
|
+
hasBattery: "getBattery" in navigator,
|
|
654
|
+
hasCredentials: "credentials" in navigator,
|
|
655
|
+
hasMediaDevices: "mediaDevices" in navigator
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
_getScreenInfo() {
|
|
659
|
+
return {
|
|
660
|
+
width: screen.width,
|
|
661
|
+
height: screen.height,
|
|
662
|
+
colorDepth: screen.colorDepth,
|
|
663
|
+
pixelRatio: window.devicePixelRatio,
|
|
664
|
+
availWidth: screen.availWidth,
|
|
665
|
+
availHeight: screen.availHeight,
|
|
666
|
+
innerWidth: window.innerWidth,
|
|
667
|
+
innerHeight: window.innerHeight
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
_getNavigatorInfo() {
|
|
671
|
+
var _a;
|
|
672
|
+
const nav = navigator;
|
|
673
|
+
return {
|
|
674
|
+
language: navigator.language,
|
|
675
|
+
languageCount: ((_a = navigator.languages) == null ? void 0 : _a.length) || 0,
|
|
676
|
+
platform: navigator.platform,
|
|
677
|
+
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
678
|
+
deviceMemory: nav.deviceMemory,
|
|
679
|
+
maxTouchPoints: navigator.maxTouchPoints || 0,
|
|
680
|
+
vendor: navigator.vendor,
|
|
681
|
+
userAgent: navigator.userAgent,
|
|
682
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
683
|
+
timezoneOffset: (/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
_measureJSExecution() {
|
|
687
|
+
const results = {};
|
|
688
|
+
let start = performance.now();
|
|
689
|
+
for (let i = 0; i < 1e3; i++) {
|
|
690
|
+
Math.sqrt(i) * Math.sin(i);
|
|
691
|
+
}
|
|
692
|
+
results.mathOps = performance.now() - start;
|
|
693
|
+
start = performance.now();
|
|
694
|
+
const arr = [];
|
|
695
|
+
for (let i = 0; i < 1e3; i++) arr.push(i);
|
|
696
|
+
results.arrayOps = performance.now() - start;
|
|
697
|
+
results.arrayLen = arr.length;
|
|
698
|
+
start = performance.now();
|
|
699
|
+
let str = "";
|
|
700
|
+
for (let i = 0; i < 100; i++) str += "a";
|
|
701
|
+
results.stringOps = performance.now() - start;
|
|
702
|
+
return results;
|
|
703
|
+
}
|
|
704
|
+
async measureRAFConsistency() {
|
|
705
|
+
return new Promise((resolve) => {
|
|
706
|
+
const times = [];
|
|
707
|
+
let frameCount = 0;
|
|
708
|
+
const maxFrames = 10;
|
|
709
|
+
function measure(timestamp) {
|
|
710
|
+
times.push(timestamp);
|
|
711
|
+
frameCount++;
|
|
712
|
+
if (frameCount < maxFrames) {
|
|
713
|
+
requestAnimationFrame(measure);
|
|
714
|
+
} else {
|
|
715
|
+
const deltas = [];
|
|
716
|
+
for (let i = 1; i < times.length; i++) {
|
|
717
|
+
deltas.push(times[i] - times[i - 1]);
|
|
718
|
+
}
|
|
719
|
+
const mean = deltas.reduce((a, b) => a + b, 0) / deltas.length;
|
|
720
|
+
const variance = deltas.reduce((sum, d) => sum + Math.pow(d - mean, 2), 0) / deltas.length;
|
|
721
|
+
resolve({ avgFrameTime: mean, frameTimeVariance: variance, frames: maxFrames });
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
requestAnimationFrame(measure);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
// ============================================================
|
|
728
|
+
// Advanced Fingerprint Detection Methods
|
|
729
|
+
// ============================================================
|
|
730
|
+
/**
|
|
731
|
+
* Math fingerprint - Different JS engines produce slightly different results
|
|
732
|
+
* for certain math operations. Headless browsers/VMs may show inconsistencies.
|
|
733
|
+
*/
|
|
734
|
+
_getMathFingerprint() {
|
|
735
|
+
try {
|
|
736
|
+
const results = {
|
|
737
|
+
// These produce engine-specific results
|
|
738
|
+
acos: Math.acos(0.123456789),
|
|
739
|
+
acosh: Math.acosh(1e308),
|
|
740
|
+
asin: Math.asin(0.123456789),
|
|
741
|
+
asinh: Math.asinh(1),
|
|
742
|
+
atanh: Math.atanh(0.5),
|
|
743
|
+
cbrt: Math.cbrt(100),
|
|
744
|
+
cosh: Math.cosh(1),
|
|
745
|
+
expm1: Math.expm1(1),
|
|
746
|
+
log1p: Math.log1p(10),
|
|
747
|
+
sinh: Math.sinh(1),
|
|
748
|
+
tan: Math.tan(-1e308),
|
|
749
|
+
tanh: Math.tanh(1),
|
|
750
|
+
// These can expose VM artifacts
|
|
751
|
+
pow: Math.pow(Math.PI, -100),
|
|
752
|
+
sin: Math.sin(Math.PI)
|
|
753
|
+
};
|
|
754
|
+
const str = Object.values(results).map((v) => String(v)).join(",");
|
|
755
|
+
let hash = 0;
|
|
756
|
+
for (let i = 0; i < str.length; i++) {
|
|
757
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
758
|
+
hash = hash & hash;
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
hash: hash.toString(16),
|
|
762
|
+
// Include a few key values for cross-checking
|
|
763
|
+
sinPi: results.sin,
|
|
764
|
+
tanLarge: results.tan,
|
|
765
|
+
supported: true
|
|
766
|
+
};
|
|
767
|
+
} catch (e) {
|
|
768
|
+
return { supported: false, error: true };
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Error fingerprint - Error message formatting varies by engine
|
|
773
|
+
* Uses safe error triggers (no eval/Function) to get engine-specific messages
|
|
774
|
+
*/
|
|
775
|
+
_getErrorFingerprint() {
|
|
776
|
+
try {
|
|
777
|
+
const errors = {};
|
|
778
|
+
try {
|
|
779
|
+
null.foo;
|
|
780
|
+
} catch (e) {
|
|
781
|
+
errors.typeError = e.message;
|
|
782
|
+
}
|
|
783
|
+
try {
|
|
784
|
+
[].length = -1;
|
|
785
|
+
} catch (e) {
|
|
786
|
+
errors.rangeError = e.message;
|
|
787
|
+
}
|
|
788
|
+
try {
|
|
789
|
+
decodeURIComponent("%");
|
|
790
|
+
} catch (e) {
|
|
791
|
+
errors.uriError = e.message;
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
const obj = {};
|
|
795
|
+
obj.undefinedMethod();
|
|
796
|
+
} catch (e) {
|
|
797
|
+
errors.refTypeError = e.message;
|
|
798
|
+
}
|
|
799
|
+
const str = Object.values(errors).join("|");
|
|
800
|
+
let hash = 0;
|
|
801
|
+
for (let i = 0; i < str.length; i++) {
|
|
802
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
803
|
+
hash = hash & hash;
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
hash: hash.toString(16),
|
|
807
|
+
typeError: errors.typeError,
|
|
808
|
+
supported: true
|
|
809
|
+
};
|
|
810
|
+
} catch (e) {
|
|
811
|
+
return { supported: false, error: true };
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* DOMRect fingerprint - Element rendering varies slightly between browsers/configs
|
|
816
|
+
*/
|
|
817
|
+
_getDOMRectFingerprint() {
|
|
818
|
+
try {
|
|
819
|
+
const container = document.createElement("div");
|
|
820
|
+
container.style.cssText = "position:absolute;left:-9999px;font-size:16px;font-family:Arial,sans-serif;";
|
|
821
|
+
const textA = document.createElement("span");
|
|
822
|
+
textA.textContent = "FCaptcha Test String 123";
|
|
823
|
+
container.appendChild(textA);
|
|
824
|
+
const textB = document.createElement("span");
|
|
825
|
+
textB.style.cssText = "letter-spacing:1px;word-spacing:2px;";
|
|
826
|
+
textB.textContent = "WWWW 0000";
|
|
827
|
+
container.appendChild(textB);
|
|
828
|
+
document.body.appendChild(container);
|
|
829
|
+
const rectA = textA.getBoundingClientRect();
|
|
830
|
+
const rectB = textB.getBoundingClientRect();
|
|
831
|
+
const range = document.createRange();
|
|
832
|
+
range.selectNode(textA);
|
|
833
|
+
const rangeRect = range.getBoundingClientRect();
|
|
834
|
+
document.body.removeChild(container);
|
|
835
|
+
const values = [
|
|
836
|
+
rectA.width,
|
|
837
|
+
rectA.height,
|
|
838
|
+
rectA.x,
|
|
839
|
+
rectA.y,
|
|
840
|
+
rectB.width,
|
|
841
|
+
rectB.height,
|
|
842
|
+
rangeRect.width,
|
|
843
|
+
rangeRect.height
|
|
844
|
+
];
|
|
845
|
+
const str = values.map((v) => v.toFixed(6)).join(",");
|
|
846
|
+
let hash = 0;
|
|
847
|
+
for (let i = 0; i < str.length; i++) {
|
|
848
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
849
|
+
hash = hash & hash;
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
hash: hash.toString(16),
|
|
853
|
+
rectAWidth: rectA.width,
|
|
854
|
+
rectBWidth: rectB.width,
|
|
855
|
+
rangeWidth: rangeRect.width,
|
|
856
|
+
supported: true
|
|
857
|
+
};
|
|
858
|
+
} catch (e) {
|
|
859
|
+
return { supported: false, error: true };
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* CSS Media Queries - Detect screen/device characteristics
|
|
864
|
+
*/
|
|
865
|
+
_getCSSMediaQueries() {
|
|
866
|
+
try {
|
|
867
|
+
const queries = {
|
|
868
|
+
// Color scheme preference
|
|
869
|
+
prefersColorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light",
|
|
870
|
+
prefersReducedMotion: window.matchMedia("(prefers-reduced-motion: reduce)").matches,
|
|
871
|
+
prefersReducedTransparency: window.matchMedia("(prefers-reduced-transparency: reduce)").matches,
|
|
872
|
+
prefersContrast: window.matchMedia("(prefers-contrast: more)").matches ? "more" : window.matchMedia("(prefers-contrast: less)").matches ? "less" : "no-preference",
|
|
873
|
+
// Pointer capabilities (helps identify device type)
|
|
874
|
+
anyHover: window.matchMedia("(any-hover: hover)").matches,
|
|
875
|
+
anyPointer: window.matchMedia("(any-pointer: fine)").matches ? "fine" : window.matchMedia("(any-pointer: coarse)").matches ? "coarse" : "none",
|
|
876
|
+
hover: window.matchMedia("(hover: hover)").matches,
|
|
877
|
+
pointer: window.matchMedia("(pointer: fine)").matches ? "fine" : window.matchMedia("(pointer: coarse)").matches ? "coarse" : "none",
|
|
878
|
+
// Display characteristics
|
|
879
|
+
colorGamut: window.matchMedia("(color-gamut: p3)").matches ? "p3" : window.matchMedia("(color-gamut: srgb)").matches ? "srgb" : "none",
|
|
880
|
+
displayMode: window.matchMedia("(display-mode: standalone)").matches ? "standalone" : window.matchMedia("(display-mode: fullscreen)").matches ? "fullscreen" : "browser",
|
|
881
|
+
orientation: window.matchMedia("(orientation: portrait)").matches ? "portrait" : "landscape",
|
|
882
|
+
// HDR
|
|
883
|
+
dynamicRange: window.matchMedia("(dynamic-range: high)").matches ? "high" : "standard",
|
|
884
|
+
// Forced colors (accessibility)
|
|
885
|
+
forcedColors: window.matchMedia("(forced-colors: active)").matches
|
|
886
|
+
};
|
|
887
|
+
return { ...queries, supported: true };
|
|
888
|
+
} catch (e) {
|
|
889
|
+
return { supported: false, error: true };
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Permissions API - Check browser permission states
|
|
894
|
+
*/
|
|
895
|
+
_getPermissionsInfo() {
|
|
896
|
+
try {
|
|
897
|
+
return {
|
|
898
|
+
hasPermissionsAPI: "permissions" in navigator,
|
|
899
|
+
hasClipboard: "clipboard" in navigator,
|
|
900
|
+
hasShare: "share" in navigator,
|
|
901
|
+
hasCredentials: "credentials" in navigator,
|
|
902
|
+
hasBluetooth: "bluetooth" in navigator,
|
|
903
|
+
hasUsb: "usb" in navigator,
|
|
904
|
+
hasSerial: "serial" in navigator,
|
|
905
|
+
hasHid: "hid" in navigator,
|
|
906
|
+
hasXR: "xr" in navigator,
|
|
907
|
+
hasGeolocation: "geolocation" in navigator,
|
|
908
|
+
hasMIDI: "requestMIDIAccess" in navigator,
|
|
909
|
+
supported: true
|
|
910
|
+
};
|
|
911
|
+
} catch (e) {
|
|
912
|
+
return { supported: false, error: true };
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Font detection - Check for system fonts
|
|
917
|
+
* Uses canvas-based detection (fast, doesn't require font loading)
|
|
918
|
+
*/
|
|
919
|
+
_getFontsInfo() {
|
|
920
|
+
try {
|
|
921
|
+
const baseFonts = ["monospace", "sans-serif", "serif"];
|
|
922
|
+
const testFonts = [
|
|
923
|
+
// Common system fonts
|
|
924
|
+
"Arial",
|
|
925
|
+
"Helvetica",
|
|
926
|
+
"Times New Roman",
|
|
927
|
+
"Courier New",
|
|
928
|
+
"Georgia",
|
|
929
|
+
"Verdana",
|
|
930
|
+
"Trebuchet MS",
|
|
931
|
+
"Comic Sans MS",
|
|
932
|
+
"Impact",
|
|
933
|
+
"Lucida Console",
|
|
934
|
+
// Mac fonts
|
|
935
|
+
"Menlo",
|
|
936
|
+
"Monaco",
|
|
937
|
+
"SF Pro",
|
|
938
|
+
"Helvetica Neue",
|
|
939
|
+
// Windows fonts
|
|
940
|
+
"Segoe UI",
|
|
941
|
+
"Consolas",
|
|
942
|
+
"Calibri",
|
|
943
|
+
"Cambria",
|
|
944
|
+
// Linux fonts
|
|
945
|
+
"DejaVu Sans",
|
|
946
|
+
"Liberation Sans",
|
|
947
|
+
"Ubuntu",
|
|
948
|
+
"Cantarell",
|
|
949
|
+
// CJK fonts
|
|
950
|
+
"MS Gothic",
|
|
951
|
+
"Meiryo",
|
|
952
|
+
"SimHei",
|
|
953
|
+
"Microsoft YaHei"
|
|
954
|
+
];
|
|
955
|
+
const canvas = document.createElement("canvas");
|
|
956
|
+
canvas.width = 400;
|
|
957
|
+
canvas.height = 40;
|
|
958
|
+
const ctx = canvas.getContext("2d");
|
|
959
|
+
const testString = "mmMWWLLiiff00";
|
|
960
|
+
const testSize = "72px";
|
|
961
|
+
const baseWidths = {};
|
|
962
|
+
for (const baseFont of baseFonts) {
|
|
963
|
+
ctx.font = testSize + " " + baseFont;
|
|
964
|
+
baseWidths[baseFont] = ctx.measureText(testString).width;
|
|
965
|
+
}
|
|
966
|
+
const detectedFonts = [];
|
|
967
|
+
for (const font of testFonts) {
|
|
968
|
+
let detected = false;
|
|
969
|
+
for (const baseFont of baseFonts) {
|
|
970
|
+
ctx.font = testSize + ' "' + font + '", ' + baseFont;
|
|
971
|
+
const width = ctx.measureText(testString).width;
|
|
972
|
+
if (width !== baseWidths[baseFont]) {
|
|
973
|
+
detected = true;
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (detected) {
|
|
978
|
+
detectedFonts.push(font);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const str = detectedFonts.join(",");
|
|
982
|
+
let hash = 0;
|
|
983
|
+
for (let i = 0; i < str.length; i++) {
|
|
984
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
985
|
+
hash = hash & hash;
|
|
986
|
+
}
|
|
987
|
+
return {
|
|
988
|
+
hash: hash.toString(16),
|
|
989
|
+
count: detectedFonts.length,
|
|
990
|
+
// Only include a few key fonts to keep payload small
|
|
991
|
+
hasArial: detectedFonts.includes("Arial"),
|
|
992
|
+
hasTimesNewRoman: detectedFonts.includes("Times New Roman"),
|
|
993
|
+
hasSegoeUI: detectedFonts.includes("Segoe UI"),
|
|
994
|
+
hasSFPro: detectedFonts.includes("SF Pro"),
|
|
995
|
+
hasDejaVuSans: detectedFonts.includes("DejaVu Sans"),
|
|
996
|
+
supported: true
|
|
997
|
+
};
|
|
998
|
+
} catch (e) {
|
|
999
|
+
return { supported: false, error: true };
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Speech Synthesis API - Get available voices
|
|
1004
|
+
* Voices are OS/browser specific and hard to spoof
|
|
1005
|
+
*/
|
|
1006
|
+
async _getSpeechInfo() {
|
|
1007
|
+
try {
|
|
1008
|
+
if (!("speechSynthesis" in window)) {
|
|
1009
|
+
return { supported: false };
|
|
1010
|
+
}
|
|
1011
|
+
const getVoices = () => {
|
|
1012
|
+
return new Promise((resolve) => {
|
|
1013
|
+
const voices2 = speechSynthesis.getVoices();
|
|
1014
|
+
if (voices2.length > 0) {
|
|
1015
|
+
resolve(voices2);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const timeout = setTimeout(() => resolve([]), 1e3);
|
|
1019
|
+
speechSynthesis.onvoiceschanged = () => {
|
|
1020
|
+
clearTimeout(timeout);
|
|
1021
|
+
resolve(speechSynthesis.getVoices());
|
|
1022
|
+
};
|
|
1023
|
+
});
|
|
1024
|
+
};
|
|
1025
|
+
const voices = await getVoices();
|
|
1026
|
+
const localVoices = voices.filter((v) => v.localService);
|
|
1027
|
+
const defaultVoice = voices.find((v) => v.default);
|
|
1028
|
+
const languages = [...new Set(voices.map((v) => v.lang))];
|
|
1029
|
+
const voiceNames = voices.map((v) => v.name).sort().join(",");
|
|
1030
|
+
let hash = 0;
|
|
1031
|
+
for (let i = 0; i < voiceNames.length; i++) {
|
|
1032
|
+
hash = (hash << 5) - hash + voiceNames.charCodeAt(i);
|
|
1033
|
+
hash = hash & hash;
|
|
1034
|
+
}
|
|
1035
|
+
return {
|
|
1036
|
+
hash: hash.toString(16),
|
|
1037
|
+
totalVoices: voices.length,
|
|
1038
|
+
localVoices: localVoices.length,
|
|
1039
|
+
languages: languages.length,
|
|
1040
|
+
defaultVoiceLang: (defaultVoice == null ? void 0 : defaultVoice.lang) || null,
|
|
1041
|
+
hasGoogleVoices: voices.some((v) => v.name.includes("Google")),
|
|
1042
|
+
hasMicrosoftVoices: voices.some((v) => v.name.includes("Microsoft")),
|
|
1043
|
+
hasAppleVoices: voices.some((v) => v.name.includes("Samantha") || v.name.includes("Alex")),
|
|
1044
|
+
supported: true
|
|
1045
|
+
};
|
|
1046
|
+
} catch (e) {
|
|
1047
|
+
return { supported: false, error: true };
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* WebRTC fingerprinting - Get local IPs and media devices
|
|
1052
|
+
* Very effective for detecting VMs, proxies, and headless browsers
|
|
1053
|
+
*/
|
|
1054
|
+
async _getWebRTCInfo() {
|
|
1055
|
+
try {
|
|
1056
|
+
const info = {
|
|
1057
|
+
supported: "RTCPeerConnection" in window,
|
|
1058
|
+
mediaDevices: { supported: false },
|
|
1059
|
+
localIPs: []
|
|
1060
|
+
};
|
|
1061
|
+
if (!info.supported) return info;
|
|
1062
|
+
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
|
|
1063
|
+
try {
|
|
1064
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
1065
|
+
info.mediaDevices = {
|
|
1066
|
+
supported: true,
|
|
1067
|
+
audioInputs: devices.filter((d) => d.kind === "audioinput").length,
|
|
1068
|
+
audioOutputs: devices.filter((d) => d.kind === "audiooutput").length,
|
|
1069
|
+
videoInputs: devices.filter((d) => d.kind === "videoinput").length,
|
|
1070
|
+
// Headless browsers typically have 0 devices
|
|
1071
|
+
totalDevices: devices.length
|
|
1072
|
+
};
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
info.mediaDevices = { supported: false, error: true };
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
try {
|
|
1078
|
+
const pc = new RTCPeerConnection({
|
|
1079
|
+
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
|
1080
|
+
});
|
|
1081
|
+
const localIPs = /* @__PURE__ */ new Set();
|
|
1082
|
+
pc.onicecandidate = (event) => {
|
|
1083
|
+
if (event.candidate) {
|
|
1084
|
+
const candidate = event.candidate.candidate;
|
|
1085
|
+
const ipRegex = /([0-9]{1,3}\.){3}[0-9]{1,3}/g;
|
|
1086
|
+
const matches = candidate.match(ipRegex);
|
|
1087
|
+
if (matches) {
|
|
1088
|
+
matches.forEach((ip) => {
|
|
1089
|
+
if (ip.startsWith("192.168.") || ip.startsWith("10.") || ip.startsWith("172.") || ip.startsWith("169.254.")) {
|
|
1090
|
+
localIPs.add(ip);
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
pc.createDataChannel("");
|
|
1097
|
+
await pc.createOffer().then((offer) => pc.setLocalDescription(offer));
|
|
1098
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1099
|
+
info.localIPs = Array.from(localIPs);
|
|
1100
|
+
info.hasLocalIP = localIPs.size > 0;
|
|
1101
|
+
pc.close();
|
|
1102
|
+
} catch (e) {
|
|
1103
|
+
info.localIPError = true;
|
|
1104
|
+
}
|
|
1105
|
+
return info;
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
return { supported: false, error: true };
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Worker consistency check - Compare main thread vs worker values
|
|
1112
|
+
* Spoofed values often don't match between contexts
|
|
1113
|
+
*/
|
|
1114
|
+
async _checkWorkerConsistency() {
|
|
1115
|
+
try {
|
|
1116
|
+
if (typeof Worker === "undefined") {
|
|
1117
|
+
return { supported: false };
|
|
1118
|
+
}
|
|
1119
|
+
const nav = navigator;
|
|
1120
|
+
const workerCode = `
|
|
1121
|
+
self.onmessage = function() {
|
|
1122
|
+
const data = {
|
|
1123
|
+
userAgent: navigator.userAgent,
|
|
1124
|
+
language: navigator.language,
|
|
1125
|
+
languages: navigator.languages ? Array.from(navigator.languages) : [],
|
|
1126
|
+
platform: navigator.platform,
|
|
1127
|
+
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
1128
|
+
deviceMemory: navigator.deviceMemory,
|
|
1129
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1130
|
+
timezoneOffset: new Date().getTimezoneOffset()
|
|
1131
|
+
};
|
|
1132
|
+
self.postMessage(data);
|
|
1133
|
+
};
|
|
1134
|
+
`;
|
|
1135
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
1136
|
+
const worker = new Worker(URL.createObjectURL(blob));
|
|
1137
|
+
const workerData = await new Promise((resolve, reject) => {
|
|
1138
|
+
const timeout = setTimeout(() => reject(new Error("timeout")), 2e3);
|
|
1139
|
+
worker.onmessage = (e) => {
|
|
1140
|
+
clearTimeout(timeout);
|
|
1141
|
+
resolve(e.data);
|
|
1142
|
+
};
|
|
1143
|
+
worker.onerror = () => {
|
|
1144
|
+
clearTimeout(timeout);
|
|
1145
|
+
reject(new Error("worker error"));
|
|
1146
|
+
};
|
|
1147
|
+
worker.postMessage("collect");
|
|
1148
|
+
});
|
|
1149
|
+
worker.terminate();
|
|
1150
|
+
const mainData = {
|
|
1151
|
+
userAgent: navigator.userAgent,
|
|
1152
|
+
language: navigator.language,
|
|
1153
|
+
languages: navigator.languages ? Array.from(navigator.languages) : [],
|
|
1154
|
+
platform: navigator.platform,
|
|
1155
|
+
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
1156
|
+
deviceMemory: nav.deviceMemory,
|
|
1157
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1158
|
+
timezoneOffset: (/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
1159
|
+
};
|
|
1160
|
+
const mismatches = [];
|
|
1161
|
+
if (workerData.userAgent !== mainData.userAgent) mismatches.push("userAgent");
|
|
1162
|
+
if (workerData.language !== mainData.language) mismatches.push("language");
|
|
1163
|
+
if (workerData.platform !== mainData.platform) mismatches.push("platform");
|
|
1164
|
+
if (workerData.hardwareConcurrency !== mainData.hardwareConcurrency) mismatches.push("hardwareConcurrency");
|
|
1165
|
+
if (workerData.deviceMemory !== mainData.deviceMemory) mismatches.push("deviceMemory");
|
|
1166
|
+
if (workerData.timezone !== mainData.timezone) mismatches.push("timezone");
|
|
1167
|
+
if (workerData.timezoneOffset !== mainData.timezoneOffset) mismatches.push("timezoneOffset");
|
|
1168
|
+
if (JSON.stringify(workerData.languages) !== JSON.stringify(mainData.languages)) mismatches.push("languages");
|
|
1169
|
+
return {
|
|
1170
|
+
supported: true,
|
|
1171
|
+
consistent: mismatches.length === 0,
|
|
1172
|
+
mismatches,
|
|
1173
|
+
mismatchCount: mismatches.length
|
|
1174
|
+
};
|
|
1175
|
+
} catch (e) {
|
|
1176
|
+
return { supported: false, error: true };
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// src/collectors/sensor.ts
|
|
1182
|
+
var SensorCollector = class {
|
|
1183
|
+
constructor() {
|
|
1184
|
+
this.motionEvents = [];
|
|
1185
|
+
this.orientationEvents = [];
|
|
1186
|
+
this._motionHandler = (e) => this._recordMotion(e);
|
|
1187
|
+
this._orientationHandler = (e) => this._recordOrientation(e);
|
|
1188
|
+
this._attached = false;
|
|
1189
|
+
}
|
|
1190
|
+
attach() {
|
|
1191
|
+
if (this._attached) return;
|
|
1192
|
+
this._attached = true;
|
|
1193
|
+
try {
|
|
1194
|
+
window.addEventListener("devicemotion", this._motionHandler, { passive: true });
|
|
1195
|
+
window.addEventListener("deviceorientation", this._orientationHandler, { passive: true });
|
|
1196
|
+
} catch (_e) {
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
detach() {
|
|
1200
|
+
if (!this._attached) return;
|
|
1201
|
+
this._attached = false;
|
|
1202
|
+
try {
|
|
1203
|
+
window.removeEventListener("devicemotion", this._motionHandler);
|
|
1204
|
+
window.removeEventListener("deviceorientation", this._orientationHandler);
|
|
1205
|
+
} catch (_e) {
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
_recordMotion(e) {
|
|
1209
|
+
const a = e.accelerationIncludingGravity || e.acceleration || {};
|
|
1210
|
+
this.motionEvents.push({
|
|
1211
|
+
x: typeof a.x === "number" ? a.x : 0,
|
|
1212
|
+
y: typeof a.y === "number" ? a.y : 0,
|
|
1213
|
+
z: typeof a.z === "number" ? a.z : 0,
|
|
1214
|
+
t: performance.now()
|
|
1215
|
+
});
|
|
1216
|
+
if (this.motionEvents.length > 300) this.motionEvents.shift();
|
|
1217
|
+
}
|
|
1218
|
+
_recordOrientation(e) {
|
|
1219
|
+
this.orientationEvents.push({
|
|
1220
|
+
alpha: typeof e.alpha === "number" ? e.alpha : 0,
|
|
1221
|
+
beta: typeof e.beta === "number" ? e.beta : 0,
|
|
1222
|
+
gamma: typeof e.gamma === "number" ? e.gamma : 0,
|
|
1223
|
+
t: performance.now()
|
|
1224
|
+
});
|
|
1225
|
+
if (this.orientationEvents.length > 300) this.orientationEvents.shift();
|
|
1226
|
+
}
|
|
1227
|
+
analyze() {
|
|
1228
|
+
const motion = this.motionEvents;
|
|
1229
|
+
const orientation = this.orientationEvents;
|
|
1230
|
+
let motionAccelVariance = 0;
|
|
1231
|
+
let motionAccelAvg = 0;
|
|
1232
|
+
if (motion.length > 1) {
|
|
1233
|
+
const mags = motion.map((m) => Math.sqrt(m.x * m.x + m.y * m.y + m.z * m.z));
|
|
1234
|
+
motionAccelAvg = mags.reduce((a, b) => a + b, 0) / mags.length;
|
|
1235
|
+
motionAccelVariance = mags.reduce((s, v) => s + (v - motionAccelAvg) * (v - motionAccelAvg), 0) / mags.length;
|
|
1236
|
+
}
|
|
1237
|
+
let orientationVariance = 0;
|
|
1238
|
+
if (orientation.length > 1) {
|
|
1239
|
+
const tilts = orientation.map((o) => Math.abs(o.beta) + Math.abs(o.gamma));
|
|
1240
|
+
const mean = tilts.reduce((a, b) => a + b, 0) / tilts.length;
|
|
1241
|
+
orientationVariance = tilts.reduce((s, v) => s + (v - mean) * (v - mean), 0) / tilts.length;
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
motionEventCount: motion.length,
|
|
1245
|
+
motionAccelAvg,
|
|
1246
|
+
motionAccelVariance,
|
|
1247
|
+
orientationEventCount: orientation.length,
|
|
1248
|
+
orientationVariance,
|
|
1249
|
+
hasSensorSupport: typeof window.DeviceMotionEvent !== "undefined"
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
// src/collectors/form.ts
|
|
1255
|
+
var FormAnalyzer = class {
|
|
1256
|
+
constructor() {
|
|
1257
|
+
this.pageLoadTime = performance.now();
|
|
1258
|
+
this.firstInteractionTime = null;
|
|
1259
|
+
this.lastInteractionTime = null;
|
|
1260
|
+
this.totalEvents = 0;
|
|
1261
|
+
this.eventLog = [];
|
|
1262
|
+
this.textareaStats = /* @__PURE__ */ new Map();
|
|
1263
|
+
this.submitData = null;
|
|
1264
|
+
this._setupListeners();
|
|
1265
|
+
}
|
|
1266
|
+
_setupListeners() {
|
|
1267
|
+
const interactionEvents = ["mousedown", "keydown", "touchstart", "scroll"];
|
|
1268
|
+
interactionEvents.forEach((eventType) => {
|
|
1269
|
+
document.addEventListener(eventType, (e) => this._recordInteraction(e), { passive: true });
|
|
1270
|
+
});
|
|
1271
|
+
document.addEventListener("keydown", (e) => this._recordTextareaKey(e), { passive: true });
|
|
1272
|
+
document.addEventListener("keyup", (e) => this._recordTextareaKey(e), { passive: true });
|
|
1273
|
+
document.addEventListener("submit", (e) => this._recordSubmit(e), { capture: true });
|
|
1274
|
+
this._interceptFormSubmit();
|
|
1275
|
+
}
|
|
1276
|
+
_recordInteraction(e) {
|
|
1277
|
+
var _a;
|
|
1278
|
+
const now = performance.now();
|
|
1279
|
+
if (this.firstInteractionTime === null) {
|
|
1280
|
+
this.firstInteractionTime = now;
|
|
1281
|
+
}
|
|
1282
|
+
this.lastInteractionTime = now;
|
|
1283
|
+
this.totalEvents++;
|
|
1284
|
+
this.eventLog.push({
|
|
1285
|
+
type: e.type,
|
|
1286
|
+
time: now,
|
|
1287
|
+
target: ((_a = e.target) == null ? void 0 : _a.tagName) || "unknown"
|
|
1288
|
+
});
|
|
1289
|
+
if (this.eventLog.length > 50) {
|
|
1290
|
+
this.eventLog.shift();
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
_recordTextareaKey(e) {
|
|
1294
|
+
const target = e.target;
|
|
1295
|
+
if ((target == null ? void 0 : target.tagName) !== "TEXTAREA") return;
|
|
1296
|
+
const textareaId = target.id || target.name || "unnamed";
|
|
1297
|
+
if (!this.textareaStats.has(textareaId)) {
|
|
1298
|
+
this.textareaStats.set(textareaId, {
|
|
1299
|
+
keydowns: [],
|
|
1300
|
+
keyups: [],
|
|
1301
|
+
intervals: [],
|
|
1302
|
+
lastKeyTime: null,
|
|
1303
|
+
inputWithoutKey: 0,
|
|
1304
|
+
pasteCount: 0,
|
|
1305
|
+
dwellTimes: [],
|
|
1306
|
+
rollovers: 0,
|
|
1307
|
+
activeKeyCount: 0,
|
|
1308
|
+
pendingKeydowns: []
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
const stats = this.textareaStats.get(textareaId);
|
|
1312
|
+
const now = performance.now();
|
|
1313
|
+
const isModifier = ["Shift", "Control", "Alt", "Meta", "CapsLock", "NumLock", "ScrollLock"].includes(e.key);
|
|
1314
|
+
if (e.type === "keydown") {
|
|
1315
|
+
stats.keydowns.push(now);
|
|
1316
|
+
if (stats.lastKeyTime !== null) {
|
|
1317
|
+
stats.intervals.push(now - stats.lastKeyTime);
|
|
1318
|
+
}
|
|
1319
|
+
stats.lastKeyTime = now;
|
|
1320
|
+
if (!isModifier && !e.repeat) {
|
|
1321
|
+
if (stats.activeKeyCount > 0) {
|
|
1322
|
+
stats.rollovers++;
|
|
1323
|
+
}
|
|
1324
|
+
stats.activeKeyCount++;
|
|
1325
|
+
stats.pendingKeydowns.push(now);
|
|
1326
|
+
}
|
|
1327
|
+
if (stats.keydowns.length > 200) stats.keydowns.shift();
|
|
1328
|
+
if (stats.intervals.length > 200) stats.intervals.shift();
|
|
1329
|
+
} else if (e.type === "keyup") {
|
|
1330
|
+
stats.keyups.push(now);
|
|
1331
|
+
if (stats.keyups.length > 200) stats.keyups.shift();
|
|
1332
|
+
if (!isModifier && stats.activeKeyCount > 0) {
|
|
1333
|
+
stats.activeKeyCount--;
|
|
1334
|
+
if (stats.pendingKeydowns.length > 0) {
|
|
1335
|
+
const keydownTime = stats.pendingKeydowns.shift();
|
|
1336
|
+
const dwell = now - keydownTime;
|
|
1337
|
+
if (dwell > 0 && dwell < 2e3) {
|
|
1338
|
+
stats.dwellTimes.push(dwell);
|
|
1339
|
+
if (stats.dwellTimes.length > 100) stats.dwellTimes.shift();
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
_interceptFormSubmit() {
|
|
1346
|
+
const self = this;
|
|
1347
|
+
const originalSubmit = HTMLFormElement.prototype.submit;
|
|
1348
|
+
HTMLFormElement.prototype.submit = function() {
|
|
1349
|
+
self._recordProgrammaticSubmit(this);
|
|
1350
|
+
return originalSubmit.apply(this, arguments);
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
_recordProgrammaticSubmit(_form) {
|
|
1354
|
+
const now = performance.now();
|
|
1355
|
+
this.submitData = {
|
|
1356
|
+
method: "programmatic",
|
|
1357
|
+
// form.submit() called directly
|
|
1358
|
+
time: now,
|
|
1359
|
+
timeSincePageLoad: now - this.pageLoadTime,
|
|
1360
|
+
timeSinceFirstInteraction: this.firstInteractionTime ? now - this.firstInteractionTime : null,
|
|
1361
|
+
timeSinceLastInteraction: this.lastInteractionTime ? now - this.lastInteractionTime : null,
|
|
1362
|
+
eventsBeforeSubmit: this.totalEvents,
|
|
1363
|
+
hadTriggerEvent: false
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
_recordSubmit(_e) {
|
|
1367
|
+
const now = performance.now();
|
|
1368
|
+
const lastEvents = this.eventLog.slice(-5);
|
|
1369
|
+
const recentKeydown = lastEvents.find((ev) => ev.type === "keydown" && now - ev.time < 100);
|
|
1370
|
+
const recentMousedown = lastEvents.find((ev) => ev.type === "mousedown" && now - ev.time < 100);
|
|
1371
|
+
let method = "unknown";
|
|
1372
|
+
if (recentKeydown) {
|
|
1373
|
+
method = "keyboard";
|
|
1374
|
+
} else if (recentMousedown) {
|
|
1375
|
+
method = "mouse";
|
|
1376
|
+
} else if (!this.submitData) {
|
|
1377
|
+
method = "programmatic_click";
|
|
1378
|
+
}
|
|
1379
|
+
if (!this.submitData || this.submitData.method === "programmatic") {
|
|
1380
|
+
this.submitData = {
|
|
1381
|
+
method,
|
|
1382
|
+
time: now,
|
|
1383
|
+
timeSincePageLoad: now - this.pageLoadTime,
|
|
1384
|
+
timeSinceFirstInteraction: this.firstInteractionTime ? now - this.firstInteractionTime : null,
|
|
1385
|
+
timeSinceLastInteraction: this.lastInteractionTime ? now - this.lastInteractionTime : null,
|
|
1386
|
+
eventsBeforeSubmit: this.totalEvents,
|
|
1387
|
+
hadTriggerEvent: method === "keyboard" || method === "mouse"
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
analyze() {
|
|
1392
|
+
const now = performance.now();
|
|
1393
|
+
const textareaAnalysis = {};
|
|
1394
|
+
this.textareaStats.forEach((stats, id) => {
|
|
1395
|
+
const intervals = stats.intervals;
|
|
1396
|
+
let avgInterval = 0;
|
|
1397
|
+
let intervalVariance = 0;
|
|
1398
|
+
if (intervals.length > 0) {
|
|
1399
|
+
avgInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
|
|
1400
|
+
intervalVariance = intervals.reduce((acc, i) => acc + Math.pow(i - avgInterval, 2), 0) / intervals.length;
|
|
1401
|
+
}
|
|
1402
|
+
textareaAnalysis[id] = {
|
|
1403
|
+
keyCount: stats.keydowns.length,
|
|
1404
|
+
avgKeyInterval: avgInterval,
|
|
1405
|
+
keyIntervalVariance: intervalVariance,
|
|
1406
|
+
keydownUpRatio: stats.keyups.length > 0 ? stats.keydowns.length / stats.keyups.length : 0,
|
|
1407
|
+
pasteCount: stats.pasteCount,
|
|
1408
|
+
intervals: stats.intervals.slice(-100),
|
|
1409
|
+
dwellTimes: stats.dwellTimes.slice(-100),
|
|
1410
|
+
rollovers: stats.rollovers
|
|
1411
|
+
};
|
|
1412
|
+
});
|
|
1413
|
+
const textareas = document.querySelectorAll("textarea");
|
|
1414
|
+
textareas.forEach((ta) => {
|
|
1415
|
+
const id = ta.id || ta.name || "unnamed";
|
|
1416
|
+
const contentLength = (ta.value || "").length;
|
|
1417
|
+
if (contentLength > 0) {
|
|
1418
|
+
if (!textareaAnalysis[id]) {
|
|
1419
|
+
textareaAnalysis[id] = {
|
|
1420
|
+
keyCount: 0,
|
|
1421
|
+
avgKeyInterval: 0,
|
|
1422
|
+
keyIntervalVariance: 0,
|
|
1423
|
+
keydownUpRatio: 0,
|
|
1424
|
+
pasteCount: 0,
|
|
1425
|
+
contentLength,
|
|
1426
|
+
noKeyboardEvents: true
|
|
1427
|
+
// Flag for server-side detection
|
|
1428
|
+
};
|
|
1429
|
+
} else {
|
|
1430
|
+
textareaAnalysis[id].contentLength = contentLength;
|
|
1431
|
+
textareaAnalysis[id].noKeyboardEvents = textareaAnalysis[id].keyCount === 0;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
return {
|
|
1436
|
+
// Timing signals
|
|
1437
|
+
pageLoadToFirstInteraction: this.firstInteractionTime ? this.firstInteractionTime - this.pageLoadTime : null,
|
|
1438
|
+
pageLoadToNow: now - this.pageLoadTime,
|
|
1439
|
+
totalInteractionEvents: this.totalEvents,
|
|
1440
|
+
// Submit analysis (credential stuffing detection)
|
|
1441
|
+
submit: this.submitData || {
|
|
1442
|
+
method: "none",
|
|
1443
|
+
eventsBeforeSubmit: this.totalEvents,
|
|
1444
|
+
hadTriggerEvent: false
|
|
1445
|
+
},
|
|
1446
|
+
// Textarea analysis (spam detection)
|
|
1447
|
+
textareaKeyboard: Object.keys(textareaAnalysis).length > 0 ? textareaAnalysis : null
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
// Track paste events on textareas
|
|
1451
|
+
recordPaste(e) {
|
|
1452
|
+
const target = e.target;
|
|
1453
|
+
if ((target == null ? void 0 : target.tagName) !== "TEXTAREA") return;
|
|
1454
|
+
const textareaId = target.id || target.name || "unnamed";
|
|
1455
|
+
if (this.textareaStats.has(textareaId)) {
|
|
1456
|
+
this.textareaStats.get(textareaId).pasteCount++;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
var globalFormAnalyzer = null;
|
|
1461
|
+
function getFormAnalyzer() {
|
|
1462
|
+
if (!globalFormAnalyzer) {
|
|
1463
|
+
globalFormAnalyzer = new FormAnalyzer();
|
|
1464
|
+
document.addEventListener("paste", (e) => globalFormAnalyzer.recordPaste(e), { passive: true });
|
|
1465
|
+
}
|
|
1466
|
+
return globalFormAnalyzer;
|
|
1467
|
+
}
|
|
1468
|
+
if (typeof document !== "undefined") {
|
|
1469
|
+
if (document.readyState === "loading") {
|
|
1470
|
+
document.addEventListener("DOMContentLoaded", () => getFormAnalyzer());
|
|
1471
|
+
} else {
|
|
1472
|
+
getFormAnalyzer();
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/sha256.ts
|
|
1477
|
+
async function sha256(message) {
|
|
1478
|
+
const msgBuffer = new TextEncoder().encode(message);
|
|
1479
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
|
|
1480
|
+
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// src/temporal.ts
|
|
1484
|
+
var TemporalCollector = class {
|
|
1485
|
+
constructor() {
|
|
1486
|
+
this.firstInteractionTime = null;
|
|
1487
|
+
this.powResult = null;
|
|
1488
|
+
this.pageLoadTime = performance.now();
|
|
1489
|
+
}
|
|
1490
|
+
recordFirstInteraction() {
|
|
1491
|
+
if (!this.firstInteractionTime) {
|
|
1492
|
+
this.firstInteractionTime = performance.now();
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
/** Legacy single-threaded PoW (prefer PoWManager). */
|
|
1496
|
+
async performProofOfWork(difficulty = 4) {
|
|
1497
|
+
const prefix = `${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
1498
|
+
const target = "0".repeat(difficulty);
|
|
1499
|
+
const startTime = performance.now();
|
|
1500
|
+
let nonce = 0;
|
|
1501
|
+
let iterations = 0;
|
|
1502
|
+
for (; ; ) {
|
|
1503
|
+
const hash = await sha256(`${prefix}:${nonce}`);
|
|
1504
|
+
iterations++;
|
|
1505
|
+
if (hash.startsWith(target)) {
|
|
1506
|
+
this.powResult = {
|
|
1507
|
+
prefix,
|
|
1508
|
+
nonce,
|
|
1509
|
+
hash,
|
|
1510
|
+
iterations,
|
|
1511
|
+
duration: performance.now() - startTime,
|
|
1512
|
+
difficulty
|
|
1513
|
+
};
|
|
1514
|
+
return this.powResult;
|
|
1515
|
+
}
|
|
1516
|
+
nonce++;
|
|
1517
|
+
if (iterations % 1e3 === 0) {
|
|
1518
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
collect(clickTime) {
|
|
1523
|
+
const performanceTiming = {};
|
|
1524
|
+
if (performance.timing) {
|
|
1525
|
+
const timing = performance.timing;
|
|
1526
|
+
performanceTiming.dnsLookup = timing.domainLookupEnd - timing.domainLookupStart;
|
|
1527
|
+
performanceTiming.tcpConnection = timing.connectEnd - timing.connectStart;
|
|
1528
|
+
performanceTiming.serverResponse = timing.responseEnd - timing.requestStart;
|
|
1529
|
+
performanceTiming.domLoad = timing.domContentLoadedEventEnd - timing.navigationStart;
|
|
1530
|
+
performanceTiming.fullLoad = timing.loadEventEnd - timing.navigationStart;
|
|
1531
|
+
}
|
|
1532
|
+
return {
|
|
1533
|
+
pageLoadToFirstInteraction: this.firstInteractionTime ? this.firstInteractionTime - this.pageLoadTime : null,
|
|
1534
|
+
firstInteractionToClick: this.firstInteractionTime && clickTime ? clickTime - this.firstInteractionTime : null,
|
|
1535
|
+
totalSessionTime: performance.now() - this.pageLoadTime,
|
|
1536
|
+
performanceTiming,
|
|
1537
|
+
pow: this.powResult
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
// src/config.ts
|
|
1543
|
+
var serverUrl = null;
|
|
1544
|
+
var basePath = "/__webdecoy";
|
|
1545
|
+
function getServerUrl() {
|
|
1546
|
+
return serverUrl;
|
|
1547
|
+
}
|
|
1548
|
+
function setServerUrl(url) {
|
|
1549
|
+
serverUrl = url;
|
|
1550
|
+
}
|
|
1551
|
+
function getBasePath() {
|
|
1552
|
+
return basePath;
|
|
1553
|
+
}
|
|
1554
|
+
function setBasePath(path) {
|
|
1555
|
+
basePath = path.replace(/\/$/, "");
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/pow.ts
|
|
1559
|
+
var PoWManager = class {
|
|
1560
|
+
constructor() {
|
|
1561
|
+
this.workers = [];
|
|
1562
|
+
this.challenge = null;
|
|
1563
|
+
this.solution = null;
|
|
1564
|
+
this.solving = false;
|
|
1565
|
+
this.solvePromise = null;
|
|
1566
|
+
this.startTime = null;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Inline Web Worker for PoW computation. Each worker scans a disjoint nonce
|
|
1570
|
+
* slice via `(startNonce + k*stride)`, so N workers explore the space N-way.
|
|
1571
|
+
*/
|
|
1572
|
+
_createWorker() {
|
|
1573
|
+
const workerCode = `
|
|
1574
|
+
async function sha256(message) {
|
|
1575
|
+
const msgBuffer = new TextEncoder().encode(message);
|
|
1576
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
|
|
1577
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
1578
|
+
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
self.onmessage = async function(e) {
|
|
1582
|
+
const { prefix, difficulty, signalsHash, startNonce = 0, stride = 1, batchSize = 10000 } = e.data;
|
|
1583
|
+
const target = '0'.repeat(difficulty);
|
|
1584
|
+
let nonce = startNonce;
|
|
1585
|
+
let iterations = 0;
|
|
1586
|
+
const startTime = performance.now();
|
|
1587
|
+
|
|
1588
|
+
const inputPrefix = signalsHash ? prefix + ':' + signalsHash : prefix;
|
|
1589
|
+
|
|
1590
|
+
while (true) {
|
|
1591
|
+
for (let i = 0; i < batchSize; i++) {
|
|
1592
|
+
const hash = await sha256(inputPrefix + ':' + nonce);
|
|
1593
|
+
iterations++;
|
|
1594
|
+
|
|
1595
|
+
if (hash.startsWith(target)) {
|
|
1596
|
+
self.postMessage({
|
|
1597
|
+
found: true,
|
|
1598
|
+
nonce,
|
|
1599
|
+
hash,
|
|
1600
|
+
iterations,
|
|
1601
|
+
duration: performance.now() - startTime
|
|
1602
|
+
});
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
nonce += stride;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
self.postMessage({
|
|
1609
|
+
found: false,
|
|
1610
|
+
progress: iterations,
|
|
1611
|
+
elapsed: performance.now() - startTime
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
`;
|
|
1616
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
1617
|
+
return new Worker(URL.createObjectURL(blob));
|
|
1618
|
+
}
|
|
1619
|
+
/** Use half of hardwareConcurrency, leaving headroom for the page. */
|
|
1620
|
+
_threadCount() {
|
|
1621
|
+
const hc = typeof navigator !== "undefined" && navigator.hardwareConcurrency || 1;
|
|
1622
|
+
return Math.max(1, Math.floor(hc / 2));
|
|
1623
|
+
}
|
|
1624
|
+
_terminateWorkers() {
|
|
1625
|
+
for (const w of this.workers) {
|
|
1626
|
+
try {
|
|
1627
|
+
w.terminate();
|
|
1628
|
+
} catch {
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
this.workers = [];
|
|
1632
|
+
}
|
|
1633
|
+
async fetchChallenge(siteKey) {
|
|
1634
|
+
const serverUrl2 = getServerUrl();
|
|
1635
|
+
if (!serverUrl2) {
|
|
1636
|
+
return this._generateLocalChallenge();
|
|
1637
|
+
}
|
|
1638
|
+
try {
|
|
1639
|
+
const response = await fetch(
|
|
1640
|
+
`${serverUrl2}${getBasePath()}/challenge?siteKey=${encodeURIComponent(siteKey || "default")}`
|
|
1641
|
+
);
|
|
1642
|
+
if (!response.ok) {
|
|
1643
|
+
console.warn(`PoW challenge fetch failed (status ${response.status}), using local challenge`);
|
|
1644
|
+
return this._generateLocalChallenge();
|
|
1645
|
+
}
|
|
1646
|
+
this.challenge = await response.json();
|
|
1647
|
+
return this.challenge;
|
|
1648
|
+
} catch (e) {
|
|
1649
|
+
console.warn("PoW challenge fetch failed, using local challenge:", e);
|
|
1650
|
+
return this._generateLocalChallenge();
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
_generateLocalChallenge() {
|
|
1654
|
+
const id = Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
1655
|
+
this.challenge = {
|
|
1656
|
+
challengeId: id,
|
|
1657
|
+
prefix: `${id}:${Date.now()}:4`,
|
|
1658
|
+
difficulty: 4,
|
|
1659
|
+
expiresAt: Date.now() + 3e5,
|
|
1660
|
+
local: true
|
|
1661
|
+
};
|
|
1662
|
+
return this.challenge;
|
|
1663
|
+
}
|
|
1664
|
+
/** Solve without signals binding (legacy). */
|
|
1665
|
+
async startSolving(siteKey) {
|
|
1666
|
+
return this._solve(siteKey, null);
|
|
1667
|
+
}
|
|
1668
|
+
/** Solve with a signals hash bound into the PoW input. */
|
|
1669
|
+
async solveWithSignalsHash(siteKey, signalsHash) {
|
|
1670
|
+
return this._solve(siteKey, signalsHash);
|
|
1671
|
+
}
|
|
1672
|
+
async _solve(siteKey, signalsHash) {
|
|
1673
|
+
if (this.solving && this.solvePromise) return this.solvePromise;
|
|
1674
|
+
if (!this.challenge) {
|
|
1675
|
+
await this.fetchChallenge(siteKey);
|
|
1676
|
+
}
|
|
1677
|
+
const challenge = this.challenge;
|
|
1678
|
+
this.solving = true;
|
|
1679
|
+
this.startTime = performance.now();
|
|
1680
|
+
this.solvePromise = new Promise((resolve, reject) => {
|
|
1681
|
+
const threads = this._threadCount();
|
|
1682
|
+
let settled = false;
|
|
1683
|
+
const finish = (fn, value) => {
|
|
1684
|
+
if (settled) return;
|
|
1685
|
+
settled = true;
|
|
1686
|
+
this.solving = false;
|
|
1687
|
+
this._terminateWorkers();
|
|
1688
|
+
fn(value);
|
|
1689
|
+
};
|
|
1690
|
+
for (let i = 0; i < threads; i++) {
|
|
1691
|
+
const worker = this._createWorker();
|
|
1692
|
+
worker.onmessage = (e) => {
|
|
1693
|
+
if (e.data.found) {
|
|
1694
|
+
this.solution = {
|
|
1695
|
+
challengeId: challenge.challengeId,
|
|
1696
|
+
nonce: e.data.nonce,
|
|
1697
|
+
hash: e.data.hash,
|
|
1698
|
+
iterations: e.data.iterations,
|
|
1699
|
+
duration: e.data.duration,
|
|
1700
|
+
difficulty: challenge.difficulty,
|
|
1701
|
+
signalsHash: signalsHash || null,
|
|
1702
|
+
local: challenge.local || false
|
|
1703
|
+
};
|
|
1704
|
+
finish(resolve, this.solution);
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
worker.onerror = (e) => {
|
|
1708
|
+
finish(reject, e);
|
|
1709
|
+
};
|
|
1710
|
+
worker.postMessage({
|
|
1711
|
+
prefix: challenge.prefix,
|
|
1712
|
+
difficulty: challenge.difficulty,
|
|
1713
|
+
signalsHash: signalsHash || null,
|
|
1714
|
+
startNonce: i,
|
|
1715
|
+
stride: threads,
|
|
1716
|
+
batchSize: 5e3
|
|
1717
|
+
});
|
|
1718
|
+
this.workers.push(worker);
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
return this.solvePromise;
|
|
1722
|
+
}
|
|
1723
|
+
async getSolution(siteKey) {
|
|
1724
|
+
if (this.solution) return this.solution;
|
|
1725
|
+
if (this.solving && this.solvePromise) return this.solvePromise;
|
|
1726
|
+
return this.startSolving(siteKey);
|
|
1727
|
+
}
|
|
1728
|
+
reset() {
|
|
1729
|
+
this._terminateWorkers();
|
|
1730
|
+
this.challenge = null;
|
|
1731
|
+
this.solution = null;
|
|
1732
|
+
this.solving = false;
|
|
1733
|
+
this.solvePromise = null;
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
var globalPoWManager = null;
|
|
1737
|
+
function getPoWManager() {
|
|
1738
|
+
if (!globalPoWManager) {
|
|
1739
|
+
globalPoWManager = new PoWManager();
|
|
1740
|
+
}
|
|
1741
|
+
return globalPoWManager;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// src/widget.ts
|
|
1745
|
+
var CaptchaWidget = class {
|
|
1746
|
+
constructor(container, options) {
|
|
1747
|
+
this.token = null;
|
|
1748
|
+
this.verified = false;
|
|
1749
|
+
const el = typeof container === "string" ? document.getElementById(container) : container;
|
|
1750
|
+
if (!el) throw new Error("WebDecoy captcha: container element not found");
|
|
1751
|
+
this.container = el;
|
|
1752
|
+
this.options = Object.assign(
|
|
1753
|
+
{
|
|
1754
|
+
siteKey: null,
|
|
1755
|
+
theme: "light",
|
|
1756
|
+
size: "normal",
|
|
1757
|
+
callback: null,
|
|
1758
|
+
errorCallback: null,
|
|
1759
|
+
expiredCallback: null,
|
|
1760
|
+
powDifficulty: 4
|
|
1761
|
+
},
|
|
1762
|
+
options
|
|
1763
|
+
);
|
|
1764
|
+
this.id = "webdecoy_" + Math.random().toString(36).slice(2, 11);
|
|
1765
|
+
this.behavioral = new BehavioralCollector();
|
|
1766
|
+
this.environmental = new EnvironmentalCollector();
|
|
1767
|
+
this.temporal = new TemporalCollector();
|
|
1768
|
+
this.sensor = new SensorCollector();
|
|
1769
|
+
this.powManager = getPoWManager();
|
|
1770
|
+
this._init();
|
|
1771
|
+
}
|
|
1772
|
+
_init() {
|
|
1773
|
+
this._createWidget();
|
|
1774
|
+
this._attachListeners();
|
|
1775
|
+
void this._fetchChallenge();
|
|
1776
|
+
}
|
|
1777
|
+
async _fetchChallenge() {
|
|
1778
|
+
try {
|
|
1779
|
+
await this.powManager.fetchChallenge(this.options.siteKey);
|
|
1780
|
+
} catch (e) {
|
|
1781
|
+
console.warn("PoW challenge fetch failed:", e);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
_createWidget() {
|
|
1785
|
+
const isDark = this.options.theme === "dark";
|
|
1786
|
+
this.container.innerHTML = `
|
|
1787
|
+
<div class="webdecoy-widget ${isDark ? "webdecoy-dark" : ""}" id="${this.id}">
|
|
1788
|
+
<style>
|
|
1789
|
+
.webdecoy-widget {
|
|
1790
|
+
font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
1791
|
+
background: ${isDark ? "#1e1e1e" : "#fafafa"};
|
|
1792
|
+
border: 1px solid ${isDark ? "#424242" : "#d3d3d3"};
|
|
1793
|
+
border-radius: 6px;
|
|
1794
|
+
padding: 12px 16px;
|
|
1795
|
+
display: inline-flex;
|
|
1796
|
+
align-items: center;
|
|
1797
|
+
gap: 12px;
|
|
1798
|
+
min-width: 280px;
|
|
1799
|
+
box-sizing: border-box;
|
|
1800
|
+
user-select: none;
|
|
1801
|
+
}
|
|
1802
|
+
.webdecoy-checkbox {
|
|
1803
|
+
width: 24px; height: 24px;
|
|
1804
|
+
border: 2px solid ${isDark ? "#555" : "#c1c1c1"};
|
|
1805
|
+
border-radius: 4px; cursor: pointer;
|
|
1806
|
+
display: flex; align-items: center; justify-content: center;
|
|
1807
|
+
background: ${isDark ? "#252525" : "#fff"};
|
|
1808
|
+
transition: all 0.15s ease; flex-shrink: 0;
|
|
1809
|
+
}
|
|
1810
|
+
.webdecoy-checkbox:hover { border-color: #00bcd4; }
|
|
1811
|
+
.webdecoy-checkbox.loading { border-color: #00bcd4; }
|
|
1812
|
+
.webdecoy-checkbox.verified { background: #4caf50; border-color: #4caf50; }
|
|
1813
|
+
.webdecoy-checkbox.failed { background: #f44336; border-color: #f44336; }
|
|
1814
|
+
.webdecoy-spinner {
|
|
1815
|
+
width: 16px; height: 16px;
|
|
1816
|
+
border: 2px solid ${isDark ? "#555" : "#e0e0e0"};
|
|
1817
|
+
border-top-color: #00bcd4; border-radius: 50%;
|
|
1818
|
+
animation: webdecoy-spin 0.8s linear infinite;
|
|
1819
|
+
}
|
|
1820
|
+
@keyframes webdecoy-spin { to { transform: rotate(360deg); } }
|
|
1821
|
+
.webdecoy-checkmark { display: none; color: white; font-size: 14px; font-weight: bold; }
|
|
1822
|
+
.webdecoy-checkbox.verified .webdecoy-checkmark { display: block; }
|
|
1823
|
+
.webdecoy-x { display: none; color: white; font-size: 14px; font-weight: bold; }
|
|
1824
|
+
.webdecoy-checkbox.failed .webdecoy-x { display: block; }
|
|
1825
|
+
.webdecoy-label { color: ${isDark ? "#e0e0e0" : "#555"}; font-size: 14px; flex-grow: 1; }
|
|
1826
|
+
.webdecoy-branding { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
|
|
1827
|
+
.webdecoy-brand { font-size: 11px; font-weight: 600; color: #ff2a6d; letter-spacing: 0.5px; }
|
|
1828
|
+
</style>
|
|
1829
|
+
<div class="webdecoy-checkbox" role="checkbox" aria-checked="false" tabindex="0">
|
|
1830
|
+
<div class="webdecoy-spinner" style="display: none;"></div>
|
|
1831
|
+
<span class="webdecoy-checkmark">\u2713</span>
|
|
1832
|
+
<span class="webdecoy-x">\u2715</span>
|
|
1833
|
+
</div>
|
|
1834
|
+
<span class="webdecoy-label">I'm not a robot</span>
|
|
1835
|
+
<div class="webdecoy-branding">
|
|
1836
|
+
<span class="webdecoy-brand">WebDecoy</span>
|
|
1837
|
+
</div>
|
|
1838
|
+
</div>
|
|
1839
|
+
`;
|
|
1840
|
+
this.checkbox = this.container.querySelector(".webdecoy-checkbox");
|
|
1841
|
+
this.spinner = this.container.querySelector(".webdecoy-spinner");
|
|
1842
|
+
this.label = this.container.querySelector(".webdecoy-label");
|
|
1843
|
+
}
|
|
1844
|
+
_attachListeners() {
|
|
1845
|
+
document.addEventListener("mousemove", (e) => this.behavioral.recordMouseMove(e), { passive: true });
|
|
1846
|
+
document.addEventListener("mousedown", (e) => this.behavioral.recordMouseDown(e), { passive: true });
|
|
1847
|
+
document.addEventListener("mouseup", (e) => this.behavioral.recordMouseUp(e), { passive: true });
|
|
1848
|
+
document.addEventListener("scroll", (e) => this.behavioral.recordScroll(e), { passive: true });
|
|
1849
|
+
document.addEventListener("keydown", (e) => this.behavioral.recordKeyEvent(e), { passive: true });
|
|
1850
|
+
document.addEventListener("keyup", (e) => this.behavioral.recordKeyEvent(e), { passive: true });
|
|
1851
|
+
document.addEventListener("touchstart", (e) => this.behavioral.recordTouch(e), { passive: true });
|
|
1852
|
+
document.addEventListener("touchmove", (e) => this.behavioral.recordTouch(e), { passive: true });
|
|
1853
|
+
document.addEventListener("pointermove", (e) => this.behavioral.recordPointer(e), { passive: true });
|
|
1854
|
+
document.addEventListener("pointerdown", (e) => this.behavioral.recordPointer(e), { passive: true });
|
|
1855
|
+
document.addEventListener("pointerup", (e) => this.behavioral.recordPointer(e), { passive: true });
|
|
1856
|
+
document.addEventListener("focus", (e) => this.behavioral.recordFocus(e), { passive: true, capture: true });
|
|
1857
|
+
document.addEventListener("blur", (e) => this.behavioral.recordFocus(e), { passive: true, capture: true });
|
|
1858
|
+
this.sensor.attach();
|
|
1859
|
+
const recordFirst = () => this.temporal.recordFirstInteraction();
|
|
1860
|
+
document.addEventListener("mousemove", recordFirst, { once: true });
|
|
1861
|
+
document.addEventListener("touchstart", recordFirst, { once: true });
|
|
1862
|
+
document.addEventListener("keydown", recordFirst, { once: true });
|
|
1863
|
+
this.checkbox.addEventListener("click", (e) => void this._handleClick(e));
|
|
1864
|
+
this.checkbox.addEventListener("keydown", (e) => {
|
|
1865
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1866
|
+
e.preventDefault();
|
|
1867
|
+
void this._handleClick(e);
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
async _handleClick(e) {
|
|
1872
|
+
var _a, _b, _c;
|
|
1873
|
+
if (this.verified || this.checkbox.classList.contains("loading")) return;
|
|
1874
|
+
const clickTime = performance.now();
|
|
1875
|
+
const rect = this.checkbox.getBoundingClientRect();
|
|
1876
|
+
this.checkbox.classList.add("loading");
|
|
1877
|
+
this.spinner.style.display = "block";
|
|
1878
|
+
this.label.textContent = "Verifying...";
|
|
1879
|
+
try {
|
|
1880
|
+
const behavioralData = this.behavioral.analyze();
|
|
1881
|
+
const clickX = "clientX" in e ? e.clientX : rect.left;
|
|
1882
|
+
const clickY = "clientY" in e ? e.clientY : rect.top;
|
|
1883
|
+
const clickData = this.behavioral.analyzeClick(clickX, clickY, rect);
|
|
1884
|
+
const envData = this.environmental.collect();
|
|
1885
|
+
const [rafData, asyncEnvData] = await Promise.all([
|
|
1886
|
+
this.environmental.measureRAFConsistency(),
|
|
1887
|
+
this.environmental.collectAsync()
|
|
1888
|
+
]);
|
|
1889
|
+
const temporalData = this.temporal.collect(clickTime);
|
|
1890
|
+
const formAnalysis = getFormAnalyzer().analyze();
|
|
1891
|
+
const sensorData = this.sensor.analyze();
|
|
1892
|
+
const signals = {
|
|
1893
|
+
behavioral: { ...behavioralData, ...clickData },
|
|
1894
|
+
environmental: { ...envData, rafConsistency: rafData, ...asyncEnvData, sensor: sensorData },
|
|
1895
|
+
temporal: temporalData,
|
|
1896
|
+
formAnalysis,
|
|
1897
|
+
meta: {
|
|
1898
|
+
widgetId: this.id,
|
|
1899
|
+
siteKey: this.options.siteKey,
|
|
1900
|
+
challengeNonce: ((_a = this.powManager.challenge) == null ? void 0 : _a.nonce) || null,
|
|
1901
|
+
timestamp: Date.now(),
|
|
1902
|
+
userAgent: navigator.userAgent,
|
|
1903
|
+
screenSize: `${screen.width}x${screen.height}`,
|
|
1904
|
+
viewportSize: `${window.innerWidth}x${window.innerHeight}`,
|
|
1905
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
const signalsJson = JSON.stringify(signals);
|
|
1909
|
+
const signalsHash = await sha256(signalsJson);
|
|
1910
|
+
const powSolution = await this.powManager.solveWithSignalsHash(this.options.siteKey, signalsHash);
|
|
1911
|
+
const powTiming = {
|
|
1912
|
+
duration: powSolution.duration,
|
|
1913
|
+
iterations: powSolution.iterations,
|
|
1914
|
+
difficulty: powSolution.difficulty
|
|
1915
|
+
};
|
|
1916
|
+
const result = await this._verify(signals, powSolution, signalsJson, signalsHash, powTiming);
|
|
1917
|
+
if (result.success) {
|
|
1918
|
+
this._showSuccess((_b = result.token) != null ? _b : "");
|
|
1919
|
+
} else {
|
|
1920
|
+
this._showFailure((_c = result.message) != null ? _c : void 0);
|
|
1921
|
+
}
|
|
1922
|
+
} catch (error) {
|
|
1923
|
+
console.error("WebDecoy captcha error:", error);
|
|
1924
|
+
this._showFailure("Verification failed. Please try again.");
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
async _verify(signals, powSolution, signalsJson, signalsHash, powTiming) {
|
|
1928
|
+
const serverUrl2 = getServerUrl();
|
|
1929
|
+
if (!serverUrl2) return this._clientSideVerify(signals);
|
|
1930
|
+
try {
|
|
1931
|
+
const response = await fetch(serverUrl2 + getBasePath() + "/verify", {
|
|
1932
|
+
method: "POST",
|
|
1933
|
+
headers: { "Content-Type": "application/json" },
|
|
1934
|
+
body: JSON.stringify({
|
|
1935
|
+
siteKey: this.options.siteKey,
|
|
1936
|
+
signals,
|
|
1937
|
+
signalsJson: signalsJson || null,
|
|
1938
|
+
powSolution: powSolution ? {
|
|
1939
|
+
challengeId: powSolution.challengeId,
|
|
1940
|
+
nonce: powSolution.nonce,
|
|
1941
|
+
hash: powSolution.hash,
|
|
1942
|
+
signalsHash: signalsHash || null
|
|
1943
|
+
} : null,
|
|
1944
|
+
powTiming: powTiming || null
|
|
1945
|
+
})
|
|
1946
|
+
});
|
|
1947
|
+
return await response.json();
|
|
1948
|
+
} catch {
|
|
1949
|
+
console.warn("Server unavailable, using client-side verification");
|
|
1950
|
+
return this._clientSideVerify(signals);
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
_clientSideVerify(signals) {
|
|
1954
|
+
let score = 0;
|
|
1955
|
+
const b = signals.behavioral;
|
|
1956
|
+
const e = signals.environmental;
|
|
1957
|
+
const t = signals.temporal;
|
|
1958
|
+
const isTouchUser = (b.touchEvents || 0) >= 3;
|
|
1959
|
+
const isKbdUser = (b.keyEvents || 0) > 0 && b.totalPoints === 0;
|
|
1960
|
+
if (b.totalPoints < 5 && b.trajectoryLength < 10 && !isTouchUser && !isKbdUser) score += 0.35;
|
|
1961
|
+
else if (b.totalPoints < 10 && !isTouchUser && !isKbdUser && b.trajectoryLength < 30) score += 0.15;
|
|
1962
|
+
if (b.microTremorScore < 0.2) score += 0.12;
|
|
1963
|
+
if (b.velocityVariance < 0.03) score += 0.1;
|
|
1964
|
+
if (b.explorationRatio < 0.05) score += 0.08;
|
|
1965
|
+
if (b.overshootCorrections === 0 && b.trajectoryLength > 100) score += 0.05;
|
|
1966
|
+
if (b.clickPrecision < 2) score += 0.05;
|
|
1967
|
+
if (b.straightLineRatio > 0.8) score += 0.08;
|
|
1968
|
+
if (b.microMovements < 5 && b.totalPoints > 50) score += 0.06;
|
|
1969
|
+
if (e.webdriver) score += 0.25;
|
|
1970
|
+
if (e.automationFlags && e.automationFlags.plugins === 0) score += 0.05;
|
|
1971
|
+
if (e.webglInfo && e.webglInfo.suspiciousRenderer) score += 0.1;
|
|
1972
|
+
if (e.headlessIndicators && !e.headlessIndicators.hasOuterDimensions) score += 0.12;
|
|
1973
|
+
if (e.headlessIndicators && e.headlessIndicators.innerEqualsOuter) score += 0.05;
|
|
1974
|
+
if (t.pow && t.pow.duration < 50) score += 0.1;
|
|
1975
|
+
if (b.eventDeltaVariance < 3) score += 0.08;
|
|
1976
|
+
if (b.interactionDuration < 300) score += 0.07;
|
|
1977
|
+
const passed = score < 0.5;
|
|
1978
|
+
return {
|
|
1979
|
+
success: passed,
|
|
1980
|
+
score,
|
|
1981
|
+
token: passed ? btoa(JSON.stringify({ timestamp: Date.now(), score, id: this.id })) : null,
|
|
1982
|
+
message: passed ? null : "Verification failed"
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
_showSuccess(token) {
|
|
1986
|
+
this.verified = true;
|
|
1987
|
+
this.token = token;
|
|
1988
|
+
this.checkbox.classList.remove("loading");
|
|
1989
|
+
this.checkbox.classList.add("verified");
|
|
1990
|
+
this.checkbox.setAttribute("aria-checked", "true");
|
|
1991
|
+
this.spinner.style.display = "none";
|
|
1992
|
+
this.label.textContent = "Verified";
|
|
1993
|
+
if (this.options.callback) this.options.callback(token);
|
|
1994
|
+
this.container.dispatchEvent(new CustomEvent("webdecoy:verified", { detail: { token } }));
|
|
1995
|
+
}
|
|
1996
|
+
_showFailure(message) {
|
|
1997
|
+
this.checkbox.classList.remove("loading");
|
|
1998
|
+
this.checkbox.classList.add("failed");
|
|
1999
|
+
this.spinner.style.display = "none";
|
|
2000
|
+
this.label.textContent = message || "Verification failed";
|
|
2001
|
+
if (this.options.errorCallback) this.options.errorCallback(message);
|
|
2002
|
+
setTimeout(() => {
|
|
2003
|
+
this.checkbox.classList.remove("failed");
|
|
2004
|
+
this.label.textContent = "I'm not a robot";
|
|
2005
|
+
}, 3e3);
|
|
2006
|
+
}
|
|
2007
|
+
getToken() {
|
|
2008
|
+
return this.token;
|
|
2009
|
+
}
|
|
2010
|
+
reset() {
|
|
2011
|
+
this.verified = false;
|
|
2012
|
+
this.token = null;
|
|
2013
|
+
this.behavioral = new BehavioralCollector();
|
|
2014
|
+
this.temporal = new TemporalCollector();
|
|
2015
|
+
if (this.sensor) this.sensor.detach();
|
|
2016
|
+
this.sensor = new SensorCollector();
|
|
2017
|
+
this.sensor.attach();
|
|
2018
|
+
this.powManager.reset();
|
|
2019
|
+
this.checkbox.classList.remove("verified", "failed", "loading");
|
|
2020
|
+
this.checkbox.setAttribute("aria-checked", "false");
|
|
2021
|
+
this.spinner.style.display = "none";
|
|
2022
|
+
this.label.textContent = "I'm not a robot";
|
|
2023
|
+
void this._fetchChallenge();
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
|
|
2027
|
+
// src/invisible.ts
|
|
2028
|
+
var InvisibleSession = class {
|
|
2029
|
+
constructor(options) {
|
|
2030
|
+
this.lastScore = null;
|
|
2031
|
+
this.listeners = [];
|
|
2032
|
+
this.options = Object.assign(
|
|
2033
|
+
{
|
|
2034
|
+
siteKey: null,
|
|
2035
|
+
serverUrl: null,
|
|
2036
|
+
minCollectionTime: 2e3,
|
|
2037
|
+
autoScore: true,
|
|
2038
|
+
scoreThreshold: 0.5,
|
|
2039
|
+
powDifficulty: 3
|
|
2040
|
+
},
|
|
2041
|
+
options
|
|
2042
|
+
);
|
|
2043
|
+
this.id = "webdecoy_inv_" + Math.random().toString(36).slice(2, 11);
|
|
2044
|
+
this.behavioral = new BehavioralCollector();
|
|
2045
|
+
this.environmental = new EnvironmentalCollector();
|
|
2046
|
+
this.temporal = new TemporalCollector();
|
|
2047
|
+
this.sensor = new SensorCollector();
|
|
2048
|
+
this.powManager = new PoWManager();
|
|
2049
|
+
this.startTime = Date.now();
|
|
2050
|
+
this._init();
|
|
2051
|
+
}
|
|
2052
|
+
_init() {
|
|
2053
|
+
this._attachListeners();
|
|
2054
|
+
const recordFirst = () => this.temporal.recordFirstInteraction();
|
|
2055
|
+
document.addEventListener("mousemove", recordFirst, { once: true });
|
|
2056
|
+
document.addEventListener("touchstart", recordFirst, { once: true });
|
|
2057
|
+
document.addEventListener("keydown", recordFirst, { once: true });
|
|
2058
|
+
document.addEventListener("scroll", recordFirst, { once: true });
|
|
2059
|
+
if (this.options.autoScore) this._attachToForms();
|
|
2060
|
+
void this._fetchChallenge();
|
|
2061
|
+
}
|
|
2062
|
+
async _fetchChallenge() {
|
|
2063
|
+
try {
|
|
2064
|
+
await this.powManager.fetchChallenge(this.options.siteKey);
|
|
2065
|
+
} catch (e) {
|
|
2066
|
+
console.warn("PoW challenge fetch failed:", e);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
_attachListeners() {
|
|
2070
|
+
const handlers = {
|
|
2071
|
+
mousemove: (e) => this.behavioral.recordMouseMove(e),
|
|
2072
|
+
mousedown: (e) => this.behavioral.recordMouseDown(e),
|
|
2073
|
+
mouseup: (e) => this.behavioral.recordMouseUp(e),
|
|
2074
|
+
scroll: (e) => this.behavioral.recordScroll(e),
|
|
2075
|
+
keydown: (e) => this.behavioral.recordKeyEvent(e),
|
|
2076
|
+
keyup: (e) => this.behavioral.recordKeyEvent(e),
|
|
2077
|
+
touchmove: (e) => this.behavioral.recordTouch(e),
|
|
2078
|
+
touchstart: (e) => this.behavioral.recordTouch(e),
|
|
2079
|
+
pointermove: (e) => this.behavioral.recordPointer(e),
|
|
2080
|
+
pointerdown: (e) => this.behavioral.recordPointer(e),
|
|
2081
|
+
pointerup: (e) => this.behavioral.recordPointer(e),
|
|
2082
|
+
focus: (e) => this.behavioral.recordFocus(e),
|
|
2083
|
+
blur: (e) => this.behavioral.recordFocus(e)
|
|
2084
|
+
};
|
|
2085
|
+
for (const [event, handler] of Object.entries(handlers)) {
|
|
2086
|
+
const opts = event === "focus" || event === "blur" ? { passive: true, capture: true } : { passive: true };
|
|
2087
|
+
document.addEventListener(event, handler, opts);
|
|
2088
|
+
this.listeners.push({ event, handler, opts });
|
|
2089
|
+
}
|
|
2090
|
+
this.sensor.attach();
|
|
2091
|
+
}
|
|
2092
|
+
_attachToForms() {
|
|
2093
|
+
document.addEventListener("submit", async (e) => {
|
|
2094
|
+
const form = e.target;
|
|
2095
|
+
if (form.dataset.webdecoyIgnore) return;
|
|
2096
|
+
let tokenField = form.querySelector('input[name="webdecoy_token"]');
|
|
2097
|
+
if (!tokenField) {
|
|
2098
|
+
tokenField = document.createElement("input");
|
|
2099
|
+
tokenField.type = "hidden";
|
|
2100
|
+
tokenField.name = "webdecoy_token";
|
|
2101
|
+
form.appendChild(tokenField);
|
|
2102
|
+
}
|
|
2103
|
+
if (!this.lastScore || Date.now() - this.lastScore.timestamp > 6e4) {
|
|
2104
|
+
e.preventDefault();
|
|
2105
|
+
try {
|
|
2106
|
+
const result = await this.execute(form.dataset.webdecoyAction || "form_submit");
|
|
2107
|
+
tokenField.value = result.token || "";
|
|
2108
|
+
if (result.success) {
|
|
2109
|
+
form.submit();
|
|
2110
|
+
} else {
|
|
2111
|
+
document.dispatchEvent(
|
|
2112
|
+
new CustomEvent("webdecoy:blocked", { detail: { score: result.score, form } })
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
} catch (error) {
|
|
2116
|
+
console.error("WebDecoy captcha error:", error);
|
|
2117
|
+
form.submit();
|
|
2118
|
+
}
|
|
2119
|
+
} else {
|
|
2120
|
+
tokenField.value = this.lastScore.token || "";
|
|
2121
|
+
}
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
async execute(action = "") {
|
|
2125
|
+
var _a;
|
|
2126
|
+
const elapsed = Date.now() - this.startTime;
|
|
2127
|
+
if (elapsed < this.options.minCollectionTime) {
|
|
2128
|
+
await new Promise((r) => setTimeout(r, this.options.minCollectionTime - elapsed));
|
|
2129
|
+
}
|
|
2130
|
+
const behavioralData = this.behavioral.analyze();
|
|
2131
|
+
const envData = this.environmental.collect();
|
|
2132
|
+
const temporalData = this.temporal.collect(Date.now());
|
|
2133
|
+
const [rafData, asyncEnvData] = await Promise.all([
|
|
2134
|
+
this.environmental.measureRAFConsistency(),
|
|
2135
|
+
this.environmental.collectAsync()
|
|
2136
|
+
]);
|
|
2137
|
+
const formAnalysis = getFormAnalyzer().analyze();
|
|
2138
|
+
const sensorData = this.sensor.analyze();
|
|
2139
|
+
const signals = {
|
|
2140
|
+
behavioral: behavioralData,
|
|
2141
|
+
environmental: { ...envData, rafConsistency: rafData, ...asyncEnvData, sensor: sensorData },
|
|
2142
|
+
temporal: temporalData,
|
|
2143
|
+
formAnalysis,
|
|
2144
|
+
meta: {
|
|
2145
|
+
sessionId: this.id,
|
|
2146
|
+
siteKey: this.options.siteKey,
|
|
2147
|
+
action,
|
|
2148
|
+
challengeNonce: ((_a = this.powManager.challenge) == null ? void 0 : _a.nonce) || null,
|
|
2149
|
+
timestamp: Date.now(),
|
|
2150
|
+
userAgent: navigator.userAgent,
|
|
2151
|
+
screenSize: `${screen.width}x${screen.height}`,
|
|
2152
|
+
viewportSize: `${window.innerWidth}x${window.innerHeight}`,
|
|
2153
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
2154
|
+
sessionDuration: Date.now() - this.startTime,
|
|
2155
|
+
invisible: true
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
const signalsJson = JSON.stringify(signals);
|
|
2159
|
+
const signalsHash = await sha256(signalsJson);
|
|
2160
|
+
const powSolution = await this.powManager.solveWithSignalsHash(this.options.siteKey, signalsHash);
|
|
2161
|
+
const powTiming = {
|
|
2162
|
+
duration: powSolution.duration,
|
|
2163
|
+
iterations: powSolution.iterations,
|
|
2164
|
+
difficulty: powSolution.difficulty
|
|
2165
|
+
};
|
|
2166
|
+
const result = await this._score(signals, action, powSolution, signalsJson, signalsHash, powTiming);
|
|
2167
|
+
this.lastScore = { ...result, timestamp: Date.now() };
|
|
2168
|
+
return result;
|
|
2169
|
+
}
|
|
2170
|
+
async _score(signals, action, powSolution, signalsJson, signalsHash, powTiming) {
|
|
2171
|
+
const url = this.options.serverUrl || getServerUrl();
|
|
2172
|
+
if (!url) return this._clientSideScore(signals);
|
|
2173
|
+
try {
|
|
2174
|
+
const response = await fetch(url + getBasePath() + "/score", {
|
|
2175
|
+
method: "POST",
|
|
2176
|
+
headers: { "Content-Type": "application/json" },
|
|
2177
|
+
body: JSON.stringify({
|
|
2178
|
+
siteKey: this.options.siteKey,
|
|
2179
|
+
signals,
|
|
2180
|
+
signalsJson: signalsJson || null,
|
|
2181
|
+
action,
|
|
2182
|
+
powSolution: powSolution ? {
|
|
2183
|
+
challengeId: powSolution.challengeId,
|
|
2184
|
+
nonce: powSolution.nonce,
|
|
2185
|
+
hash: powSolution.hash,
|
|
2186
|
+
signalsHash: signalsHash || null
|
|
2187
|
+
} : null,
|
|
2188
|
+
powTiming: powTiming || null
|
|
2189
|
+
})
|
|
2190
|
+
});
|
|
2191
|
+
return await response.json();
|
|
2192
|
+
} catch {
|
|
2193
|
+
console.warn("WebDecoy server unavailable, using client-side scoring");
|
|
2194
|
+
return this._clientSideScore(signals);
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
_clientSideScore(signals) {
|
|
2198
|
+
let score = 0;
|
|
2199
|
+
const b = signals.behavioral;
|
|
2200
|
+
const e = signals.environmental;
|
|
2201
|
+
const t = signals.temporal;
|
|
2202
|
+
const m = signals.meta;
|
|
2203
|
+
const isTouchUsr = (b.touchEvents || 0) >= 3;
|
|
2204
|
+
const isKbdUsr = (b.keyEvents || 0) > 0 && b.totalPoints === 0;
|
|
2205
|
+
if (b.totalPoints < 5 && b.trajectoryLength < 10 && !isTouchUsr && !isKbdUsr) score += 0.35;
|
|
2206
|
+
else if (b.totalPoints < 10 && !isTouchUsr && !isKbdUsr && b.trajectoryLength < 30) score += 0.15;
|
|
2207
|
+
if (b.microTremorScore < 0.2) score += 0.12;
|
|
2208
|
+
if (b.velocityVariance < 0.03) score += 0.1;
|
|
2209
|
+
if (b.totalPoints < 10 && m.sessionDuration > 5e3) score += 0.08;
|
|
2210
|
+
if (b.scrollEvents === 0 && b.keyEvents === 0 && m.sessionDuration > 1e4) score += 0.06;
|
|
2211
|
+
if (b.eventDeltaVariance < 3) score += 0.08;
|
|
2212
|
+
if (b.straightLineRatio > 0.8) score += 0.08;
|
|
2213
|
+
if (e.webdriver) score += 0.25;
|
|
2214
|
+
if (e.automationFlags && e.automationFlags.plugins === 0) score += 0.06;
|
|
2215
|
+
if (e.headlessIndicators && !e.headlessIndicators.hasOuterDimensions) score += 0.12;
|
|
2216
|
+
if (e.webglInfo && e.webglInfo.suspiciousRenderer) score += 0.1;
|
|
2217
|
+
if (t.pow && t.pow.duration < 30) score += 0.1;
|
|
2218
|
+
if (m.sessionDuration < 500) score += 0.12;
|
|
2219
|
+
if (m.sessionDuration < 1e3 && b.totalPoints < 5) score += 0.15;
|
|
2220
|
+
const success = score < this.options.scoreThreshold;
|
|
2221
|
+
return {
|
|
2222
|
+
success,
|
|
2223
|
+
score: Math.min(1, score),
|
|
2224
|
+
action: m.action,
|
|
2225
|
+
token: success ? btoa(JSON.stringify({ timestamp: Date.now(), score, action: m.action, id: this.id })) : null
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
getScore() {
|
|
2229
|
+
return this.lastScore;
|
|
2230
|
+
}
|
|
2231
|
+
destroy() {
|
|
2232
|
+
for (const { event, handler, opts } of this.listeners) {
|
|
2233
|
+
document.removeEventListener(event, handler, opts);
|
|
2234
|
+
}
|
|
2235
|
+
this.listeners = [];
|
|
2236
|
+
if (this.powManager) this.powManager.reset();
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
|
|
2240
|
+
// src/client.ts
|
|
2241
|
+
var WebDecoyCaptcha = {
|
|
2242
|
+
widgets: /* @__PURE__ */ new Map(),
|
|
2243
|
+
get serverUrl() {
|
|
2244
|
+
return getServerUrl();
|
|
2245
|
+
},
|
|
2246
|
+
set serverUrl(url) {
|
|
2247
|
+
setServerUrl(url);
|
|
2248
|
+
},
|
|
2249
|
+
configure(options) {
|
|
2250
|
+
if (options.serverUrl) setServerUrl(options.serverUrl);
|
|
2251
|
+
if (options.basePath) setBasePath(options.basePath);
|
|
2252
|
+
},
|
|
2253
|
+
render(container, options) {
|
|
2254
|
+
const widget = new CaptchaWidget(container, options);
|
|
2255
|
+
this.widgets.set(widget.id, widget);
|
|
2256
|
+
return widget.id;
|
|
2257
|
+
},
|
|
2258
|
+
getResponse(widgetId) {
|
|
2259
|
+
const widget = this.widgets.get(widgetId);
|
|
2260
|
+
return widget && widget instanceof CaptchaWidget ? widget.getToken() : null;
|
|
2261
|
+
},
|
|
2262
|
+
reset(widgetId) {
|
|
2263
|
+
const widget = this.widgets.get(widgetId);
|
|
2264
|
+
if (widget instanceof CaptchaWidget) widget.reset();
|
|
2265
|
+
},
|
|
2266
|
+
invisible(options) {
|
|
2267
|
+
const session = new InvisibleSession(options);
|
|
2268
|
+
this.widgets.set(session.id, session);
|
|
2269
|
+
return session;
|
|
2270
|
+
},
|
|
2271
|
+
async execute(siteKey, options = {}) {
|
|
2272
|
+
const session = new InvisibleSession({
|
|
2273
|
+
siteKey,
|
|
2274
|
+
serverUrl: getServerUrl(),
|
|
2275
|
+
minCollectionTime: options.minTime || 1e3,
|
|
2276
|
+
autoScore: false,
|
|
2277
|
+
powDifficulty: options.powDifficulty || 3
|
|
2278
|
+
});
|
|
2279
|
+
const result = await session.execute(options.action || "");
|
|
2280
|
+
session.destroy();
|
|
2281
|
+
return result;
|
|
2282
|
+
},
|
|
2283
|
+
getSignals() {
|
|
2284
|
+
const environmental = new EnvironmentalCollector();
|
|
2285
|
+
return { environmental: environmental.collect() };
|
|
2286
|
+
},
|
|
2287
|
+
autoInit() {
|
|
2288
|
+
document.querySelectorAll("[data-webdecoy]").forEach((container) => {
|
|
2289
|
+
const siteKey = container.dataset.sitekey || container.dataset.webdecoy;
|
|
2290
|
+
const theme = container.dataset.theme || "light";
|
|
2291
|
+
const endpoint = container.dataset.endpoint;
|
|
2292
|
+
const callbackName = container.dataset.callback;
|
|
2293
|
+
const callback = callbackName ? window[callbackName] : void 0;
|
|
2294
|
+
if (endpoint) setServerUrl(endpoint);
|
|
2295
|
+
this.render(container, { siteKey, theme, callback: callback != null ? callback : null });
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
export {
|
|
2300
|
+
BehavioralCollector,
|
|
2301
|
+
CaptchaWidget,
|
|
2302
|
+
EnvironmentalCollector,
|
|
2303
|
+
FormAnalyzer,
|
|
2304
|
+
InvisibleSession,
|
|
2305
|
+
PoWManager,
|
|
2306
|
+
SensorCollector,
|
|
2307
|
+
TemporalCollector,
|
|
2308
|
+
WebDecoyCaptcha,
|
|
2309
|
+
getFormAnalyzer,
|
|
2310
|
+
getPoWManager,
|
|
2311
|
+
sha256
|
|
2312
|
+
};
|