@prosopo/procaptcha-frictionless 2.18.3 → 2.18.5
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/.turbo/turbo-build$colon$cjs.log +4 -4
- package/.turbo/turbo-build$colon$tsc.log +24 -24
- package/.turbo/turbo-build.log +12 -12
- package/CHANGELOG.md +50 -0
- package/dist/cjs/customDetectBot.cjs +1 -0
- package/dist/cjs/procaptchaFrictionless.cjs +18 -7
- package/dist/customDetectBot.d.ts.map +1 -1
- package/dist/customDetectBot.js +1 -0
- package/dist/customDetectBot.js.map +1 -1
- package/dist/detectorLoader.d.ts +7 -1
- package/dist/detectorLoader.d.ts.map +1 -1
- package/dist/detectorLoader.js.map +1 -1
- package/dist/procaptchaFrictionless.d.ts.map +1 -1
- package/dist/procaptchaFrictionless.js +19 -8
- package/dist/procaptchaFrictionless.js.map +1 -1
- package/dist/tests/sessionInvalidatedRemint.test.js +19 -1
- package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
- package/package.json +10 -10
- package/src/customDetectBot.ts +1 -0
- package/src/detectorLoader.ts +7 -0
- package/src/procaptchaFrictionless.ts +41 -14
- package/src/tests/sessionInvalidatedRemint.test.ts +26 -2
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-frictionless",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.5",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,19 +30,19 @@
|
|
|
30
30
|
},
|
|
31
31
|
"browserslist": ["> 0.5%, last 2 versions, not dead"],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@prosopo/api": "4.3.
|
|
34
|
-
"@prosopo/common": "3.1.
|
|
35
|
-
"@prosopo/locale": "3.6.
|
|
36
|
-
"@prosopo/procaptcha-common": "2.
|
|
37
|
-
"@prosopo/procaptcha-pow": "2.13.
|
|
38
|
-
"@prosopo/procaptcha-puzzle": "2.14.
|
|
39
|
-
"@prosopo/procaptcha-react": "2.13.
|
|
40
|
-
"@prosopo/types": "5.
|
|
33
|
+
"@prosopo/api": "4.3.6",
|
|
34
|
+
"@prosopo/common": "3.1.60",
|
|
35
|
+
"@prosopo/locale": "3.6.1",
|
|
36
|
+
"@prosopo/procaptcha-common": "2.18.0",
|
|
37
|
+
"@prosopo/procaptcha-pow": "2.13.5",
|
|
38
|
+
"@prosopo/procaptcha-puzzle": "2.14.5",
|
|
39
|
+
"@prosopo/procaptcha-react": "2.13.4",
|
|
40
|
+
"@prosopo/types": "5.11.0",
|
|
41
41
|
"@prosopo/widget-skeleton": "2.10.0",
|
|
42
42
|
"dotenv": "16.4.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@prosopo/config": "3.4.
|
|
45
|
+
"@prosopo/config": "3.4.2",
|
|
46
46
|
"@types/node": "22.10.2",
|
|
47
47
|
"@vitest/coverage-v8": "4.1.11",
|
|
48
48
|
"concurrently": "9.0.1",
|
package/src/customDetectBot.ts
CHANGED
|
@@ -381,6 +381,7 @@ const customDetectBot: BotDetectionFunction = async (
|
|
|
381
381
|
behaviorCollector1: detectionResult.mouseTracker,
|
|
382
382
|
behaviorCollector2: detectionResult.touchTracker,
|
|
383
383
|
behaviorCollector3: detectionResult.clickTracker,
|
|
384
|
+
behaviorCollector4: detectionResult.scrollTracker,
|
|
384
385
|
deviceCapability: detectionResult.hasTouchSupport,
|
|
385
386
|
encryptBehavioralData: detectionResult.encryptBehavioralData,
|
|
386
387
|
packBehavioralData: detectionResult.packBehavioralData,
|
package/src/detectorLoader.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
ClickEventPoint,
|
|
19
19
|
MouseMovementPoint,
|
|
20
20
|
PackedBehavioralData,
|
|
21
|
+
ScrollEventPoint,
|
|
21
22
|
TouchEventPoint,
|
|
22
23
|
} from "@prosopo/types";
|
|
23
24
|
|
|
@@ -58,6 +59,12 @@ export type DetectorType = (
|
|
|
58
59
|
getData: () => ClickEventPoint[];
|
|
59
60
|
clear: () => void;
|
|
60
61
|
};
|
|
62
|
+
scrollTracker?: {
|
|
63
|
+
start: () => void;
|
|
64
|
+
stop: () => void;
|
|
65
|
+
getData: () => ScrollEventPoint[];
|
|
66
|
+
clear: () => void;
|
|
67
|
+
};
|
|
61
68
|
hasTouchSupport?: string;
|
|
62
69
|
encryptBehavioralData?: (data: string) => Promise<string>;
|
|
63
70
|
packBehavioralData?: (behavioralData: BehavioralData) => PackedBehavioralData;
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
clearElement,
|
|
22
22
|
createElement,
|
|
23
23
|
getDefaultEvents,
|
|
24
|
+
getRestartDelayMs,
|
|
24
25
|
isSecureBrowserContext,
|
|
25
26
|
mountCheckbox,
|
|
26
27
|
mountTestModeBanner,
|
|
@@ -130,6 +131,10 @@ export const mountProcaptchaFrictionless = (
|
|
|
130
131
|
// `providerRetry` re-invokes `start` with no arguments, which would
|
|
131
132
|
// otherwise drop the flag on the first provider retry.
|
|
132
133
|
let nextMountAutoStart = false;
|
|
134
|
+
// Set when the re-mint was triggered by a wrong puzzle answer rather than a
|
|
135
|
+
// reload press, so the replacement challenge still tells the user they
|
|
136
|
+
// missed. Held alongside `nextMountAutoStart` for the same reason.
|
|
137
|
+
let nextMountShowRetry = false;
|
|
133
138
|
const manualStart = StartModeEnum.manual === config.startMode;
|
|
134
139
|
let manualStarted = false;
|
|
135
140
|
// The inner widget only listens for `procaptcha:execute` once /frictionless
|
|
@@ -193,13 +198,19 @@ export const mountProcaptchaFrictionless = (
|
|
|
193
198
|
state = defaultLoadingState(attemptCount ?? state.attemptCount);
|
|
194
199
|
};
|
|
195
200
|
|
|
201
|
+
// How many silent restarts this widget has already run. Drives the backoff
|
|
202
|
+
// so a client whose session keeps going missing costs the fleet a request
|
|
203
|
+
// every two minutes rather than every ten seconds, forever.
|
|
204
|
+
let restartCount = 0;
|
|
205
|
+
|
|
196
206
|
const restartComponentTimeout = () => {
|
|
207
|
+
const delay = getRestartDelayMs(restartCount);
|
|
208
|
+
restartCount += 1;
|
|
197
209
|
const timer = setTimeout(() => {
|
|
198
210
|
resetState(0);
|
|
199
211
|
events.onReset();
|
|
200
|
-
// `restart` frictionless widget after 10 seconds
|
|
201
212
|
restart();
|
|
202
|
-
},
|
|
213
|
+
}, delay);
|
|
203
214
|
teardown.add(() => clearTimeout(timer));
|
|
204
215
|
};
|
|
205
216
|
|
|
@@ -208,11 +219,16 @@ export const mountProcaptchaFrictionless = (
|
|
|
208
219
|
// never-ending requests to Providers when settings are incorrect, or the
|
|
209
220
|
// user is not human. We need to selectively re-render for events like
|
|
210
221
|
// `no session found` but not for other errors.
|
|
222
|
+
//
|
|
223
|
+
// NO_SESSION_FOUND is ours to fix and not the user's to read: the
|
|
224
|
+
// session behind the challenge is gone, the only way forward is a new
|
|
225
|
+
// one, and we are already minting it. Leave the checkbox in its loading
|
|
226
|
+
// state and re-mint behind it, rather than parking a support code on a
|
|
227
|
+
// widget that is about to start working again.
|
|
211
228
|
if ("CAPTCHA.NO_SESSION_FOUND" === errorKey) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
teardown.add(() => clearTimeout(timer));
|
|
229
|
+
restartComponentTimeout();
|
|
230
|
+
renderPlaceholder(config.mode, undefined, true);
|
|
231
|
+
return;
|
|
216
232
|
}
|
|
217
233
|
renderPlaceholder(
|
|
218
234
|
config.mode,
|
|
@@ -302,15 +318,22 @@ export const mountProcaptchaFrictionless = (
|
|
|
302
318
|
fallOverWithStyle(message, NO_SESSION_FOUND_KEY);
|
|
303
319
|
};
|
|
304
320
|
|
|
305
|
-
// The
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
//
|
|
310
|
-
// the
|
|
311
|
-
|
|
321
|
+
// The widget wants a replacement challenge — the user pressed reload, or
|
|
322
|
+
// the puzzle rejected their answer. The provider consumed this session
|
|
323
|
+
// when it issued the challenge, so there is no way to ask it for another
|
|
324
|
+
// one — mint a new session by re-running frictionless and re-mount the
|
|
325
|
+
// widget with `autoStart`, which is what makes a new challenge appear
|
|
326
|
+
// instead of the modal simply closing. Not one-shot: the user may keep
|
|
327
|
+
// asking for a different challenge, and at a low `puzzleTolerance` they
|
|
328
|
+
// may well miss several in a row.
|
|
329
|
+
const onReload = (
|
|
330
|
+
x?: number,
|
|
331
|
+
y?: number,
|
|
332
|
+
options?: { showRetry?: boolean },
|
|
333
|
+
) => {
|
|
312
334
|
pendingRetryCoords.current = normaliseRetryCoords(x, y);
|
|
313
335
|
nextMountAutoStart = true;
|
|
336
|
+
nextMountShowRetry = true === options?.showRetry;
|
|
314
337
|
// A reload mints a genuinely new session, so the invalidation
|
|
315
338
|
// budget for the *previous* one shouldn't count against it.
|
|
316
339
|
sessionInvalidatedAttempts.current = 0;
|
|
@@ -327,6 +350,8 @@ export const mountProcaptchaFrictionless = (
|
|
|
327
350
|
// widget instance that never got to consume them.
|
|
328
351
|
const forcedAutoStart = nextMountAutoStart;
|
|
329
352
|
nextMountAutoStart = false;
|
|
353
|
+
const startShowRetry = nextMountShowRetry;
|
|
354
|
+
nextMountShowRetry = false;
|
|
330
355
|
const { autoStart: resumedAutoStart, startCoords: retryStartCoords } =
|
|
331
356
|
consumeRetryMountProps(pendingRetryCoords, autoStart || forcedAutoStart);
|
|
332
357
|
const startCoords = escalationCoords ?? retryStartCoords;
|
|
@@ -338,6 +363,7 @@ export const mountProcaptchaFrictionless = (
|
|
|
338
363
|
i18n,
|
|
339
364
|
autoStart: resumedAutoStart,
|
|
340
365
|
startCoords,
|
|
366
|
+
startShowRetry,
|
|
341
367
|
onSessionInvalidated,
|
|
342
368
|
container: widgetContainer,
|
|
343
369
|
};
|
|
@@ -381,7 +407,7 @@ export const mountProcaptchaFrictionless = (
|
|
|
381
407
|
const mount = await ProcaptchaPuzzleLoader();
|
|
382
408
|
if (destroyed) return;
|
|
383
409
|
clearSlot();
|
|
384
|
-
solver = mount(slot, widgetProps);
|
|
410
|
+
solver = mount(slot, { ...widgetProps, onReload });
|
|
385
411
|
replayPendingExecute();
|
|
386
412
|
return;
|
|
387
413
|
}
|
|
@@ -446,6 +472,7 @@ export const mountProcaptchaFrictionless = (
|
|
|
446
472
|
behaviorCollector1: result.behaviorCollector1,
|
|
447
473
|
behaviorCollector2: result.behaviorCollector2,
|
|
448
474
|
behaviorCollector3: result.behaviorCollector3,
|
|
475
|
+
behaviorCollector4: result.behaviorCollector4,
|
|
449
476
|
deviceCapability: result.deviceCapability,
|
|
450
477
|
encryptBehavioralData: result.encryptBehavioralData,
|
|
451
478
|
getSimdReadings: result.getSimdReadings,
|
|
@@ -197,19 +197,43 @@ describe("NO_SESSION_FOUND recovery in the frictionless widget", () => {
|
|
|
197
197
|
expect(isCheckboxPlaceholder()).toBe(false);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
it("falls
|
|
200
|
+
it("falls back to the placeholder once the retry budget is spent, without showing the error", async () => {
|
|
201
201
|
for (let i = 0; i <= MAX_SESSION_INVALIDATED_RETRIES; i++) {
|
|
202
202
|
await reportSessionInvalidated();
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
// The budget-exceeding failure must not silently do nothing: the error
|
|
206
|
-
// reaches the host page and the widget renders the
|
|
206
|
+
// still reaches the host page and the widget renders the placeholder,
|
|
207
207
|
// whose NO_SESSION_FOUND branch schedules the full restart.
|
|
208
208
|
expect(onError).toHaveBeenCalled();
|
|
209
209
|
expect(isCheckboxPlaceholder()).toBe(true);
|
|
210
210
|
expect(detectBot).toHaveBeenCalledTimes(
|
|
211
211
|
MAX_SESSION_INVALIDATED_RETRIES + 1,
|
|
212
212
|
);
|
|
213
|
+
// But the user is not told about it: a re-mint is already scheduled, so
|
|
214
|
+
// the checkbox waits in its loading state instead.
|
|
215
|
+
expect(container.textContent).not.toContain("No session found");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// The re-mint loop has no natural end, so the delay between restarts is the
|
|
219
|
+
// only thing bounding what one persistently broken client costs the fleet.
|
|
220
|
+
it("waits before the restart rather than re-minting straight away", async () => {
|
|
221
|
+
vi.useFakeTimers();
|
|
222
|
+
try {
|
|
223
|
+
for (let i = 0; i <= MAX_SESSION_INVALIDATED_RETRIES; i++) {
|
|
224
|
+
const { onSessionInvalidated } = lastMount().props;
|
|
225
|
+
onSessionInvalidated?.(120, 340);
|
|
226
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
227
|
+
}
|
|
228
|
+
// getRestartDelayMs(0) is jittered across 5-10s, so nothing at 4s.
|
|
229
|
+
await vi.advanceTimersByTimeAsync(4000);
|
|
230
|
+
expect(restart).not.toHaveBeenCalled();
|
|
231
|
+
|
|
232
|
+
await vi.advanceTimersByTimeAsync(6000);
|
|
233
|
+
expect(restart).toHaveBeenCalledTimes(1);
|
|
234
|
+
} finally {
|
|
235
|
+
vi.useRealTimers();
|
|
236
|
+
}
|
|
213
237
|
});
|
|
214
238
|
|
|
215
239
|
// `resetState(0)` used to be `0 || state.attemptCount`, so the counter never
|