@prosopo/procaptcha-frictionless 2.18.7 → 2.19.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/.turbo/turbo-build$colon$cjs.log +4 -7
- package/.turbo/turbo-build$colon$tsc.log +24 -27
- package/.turbo/turbo-build.log +5 -11
- package/CHANGELOG.md +32 -0
- package/LICENSE +201 -0
- package/dist/cjs/customDetectBot.cjs +3 -3
- package/dist/cjs/procaptchaFrictionless.cjs +4 -1
- package/dist/customDetectBot.d.ts.map +1 -1
- package/dist/customDetectBot.js +3 -3
- package/dist/customDetectBot.js.map +1 -1
- package/dist/procaptchaFrictionless.d.ts.map +1 -1
- package/dist/procaptchaFrictionless.js +4 -1
- package/dist/procaptchaFrictionless.js.map +1 -1
- package/dist/tests/sessionInvalidatedRemint.test.js +26 -0
- package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
- package/package.json +70 -69
- package/src/authenticatedBadge.ts +0 -170
- package/src/customDetectBot.ts +0 -392
- package/src/detectorLoader.ts +0 -133
- package/src/detectorPrefetch.ts +0 -115
- package/src/frictionlessResultGuard.ts +0 -110
- package/src/index.ts +0 -15
- package/src/procaptchaFrictionless.ts +0 -626
- package/src/sessionInvalidatedRecovery.ts +0 -110
- package/src/tests/authenticatedBadge.unit.test.ts +0 -101
- package/src/tests/customDetectBot.test.ts +0 -77
- package/src/tests/customDetectBotAssignTimeout.test.ts +0 -185
- package/src/tests/customDetectBotSimd.test.ts +0 -173
- package/src/tests/detectorLoader.test.ts +0 -108
- package/src/tests/detectorPrefetch.test.ts +0 -114
- package/src/tests/escalationClientSession.test.ts +0 -216
- package/src/tests/escalationHandoff.integration.test.ts +0 -356
- package/src/tests/executeBeforeMount.test.ts +0 -233
- package/src/tests/frictionlessResultGuard.test.ts +0 -179
- package/src/tests/manualStart.test.ts +0 -391
- package/src/tests/procaptchaFrictionless.test.ts +0 -468
- package/src/tests/sessionInvalidatedRecovery.test.ts +0 -181
- package/src/tests/sessionInvalidatedRemint.test.ts +0 -272
- package/tsconfig.cjs.json +0 -41
- package/tsconfig.json +0 -49
- package/tsconfig.tsbuildinfo +0 -1
- package/tsconfig.types.json +0 -9
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import type { Ti18n } from "@prosopo/locale";
|
|
16
|
-
import {
|
|
17
|
-
type Account,
|
|
18
|
-
type BotDetectionFunction,
|
|
19
|
-
CaptchaType,
|
|
20
|
-
ModeEnum,
|
|
21
|
-
type ProcaptchaClientConfigOutput,
|
|
22
|
-
type ProcaptchaProps,
|
|
23
|
-
type RandomProvider,
|
|
24
|
-
} from "@prosopo/types";
|
|
25
|
-
import {
|
|
26
|
-
type Mock,
|
|
27
|
-
afterEach,
|
|
28
|
-
beforeEach,
|
|
29
|
-
describe,
|
|
30
|
-
expect,
|
|
31
|
-
it,
|
|
32
|
-
vi,
|
|
33
|
-
} from "vitest";
|
|
34
|
-
import { MAX_SESSION_INVALIDATED_RETRIES } from "../sessionInvalidatedRecovery.js";
|
|
35
|
-
|
|
36
|
-
const mocks = vi.hoisted(() => {
|
|
37
|
-
const mounts: { props: ProcaptchaProps }[] = [];
|
|
38
|
-
const stub = (host: HTMLElement, props: ProcaptchaProps) => {
|
|
39
|
-
mounts.push({ props });
|
|
40
|
-
const element = host.ownerDocument.createElement("div");
|
|
41
|
-
element.setAttribute("data-widget", "image");
|
|
42
|
-
host.appendChild(element);
|
|
43
|
-
return { destroy: () => element.remove() };
|
|
44
|
-
};
|
|
45
|
-
return { mounts, stub };
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
vi.mock("@prosopo/procaptcha-react", () => ({
|
|
49
|
-
mountProcaptchaImageWidget: mocks.stub,
|
|
50
|
-
}));
|
|
51
|
-
vi.mock("@prosopo/procaptcha-pow", () => ({
|
|
52
|
-
mountProcaptchaPowWidget: mocks.stub,
|
|
53
|
-
}));
|
|
54
|
-
vi.mock("@prosopo/procaptcha-puzzle", () => ({
|
|
55
|
-
mountProcaptchaPuzzleWidget: mocks.stub,
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
// jsdom serves the suite over http, so the widget's own HTTPS guard would
|
|
59
|
-
// short-circuit every test before detection ran.
|
|
60
|
-
vi.mock("@prosopo/procaptcha-common", async (importOriginal) => ({
|
|
61
|
-
...(await importOriginal<typeof import("@prosopo/procaptcha-common")>()),
|
|
62
|
-
isSecureBrowserContext: () => true,
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
const { mountProcaptchaFrictionless } = await import(
|
|
66
|
-
"../procaptchaFrictionless.js"
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const SITE_KEY = "5siteKey";
|
|
70
|
-
|
|
71
|
-
const config = (): ProcaptchaClientConfigOutput =>
|
|
72
|
-
({
|
|
73
|
-
account: { address: SITE_KEY },
|
|
74
|
-
userAccountAddress: "",
|
|
75
|
-
web2: true,
|
|
76
|
-
theme: "light",
|
|
77
|
-
mode: ModeEnum.visible,
|
|
78
|
-
}) as unknown as ProcaptchaClientConfigOutput;
|
|
79
|
-
|
|
80
|
-
const i18nStub = {
|
|
81
|
-
isInitialized: true,
|
|
82
|
-
language: "en",
|
|
83
|
-
t: (key: string) => key,
|
|
84
|
-
changeLanguage: vi.fn(),
|
|
85
|
-
} as unknown as Ti18n;
|
|
86
|
-
|
|
87
|
-
const provider: RandomProvider = {
|
|
88
|
-
providerAccount: "provider-account",
|
|
89
|
-
provider: { url: "https://provider.test" },
|
|
90
|
-
} as unknown as RandomProvider;
|
|
91
|
-
|
|
92
|
-
const userAccount: Account = {
|
|
93
|
-
account: { address: "user-address" },
|
|
94
|
-
} as unknown as Account;
|
|
95
|
-
|
|
96
|
-
// Each /frictionless run mints a new session, exactly as the provider does.
|
|
97
|
-
let sessionCounter = 0;
|
|
98
|
-
const detectBot: Mock<BotDetectionFunction> = vi.fn(async () => {
|
|
99
|
-
sessionCounter += 1;
|
|
100
|
-
return {
|
|
101
|
-
captchaType: CaptchaType.image,
|
|
102
|
-
sessionId: `provider-session-${sessionCounter}`,
|
|
103
|
-
status: "ok",
|
|
104
|
-
provider,
|
|
105
|
-
userAccount,
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
let container: HTMLDivElement;
|
|
110
|
-
let widget: { destroy: () => void } | undefined;
|
|
111
|
-
let restart: Mock<() => void>;
|
|
112
|
-
let onError: Mock<(error: Error) => void>;
|
|
113
|
-
|
|
114
|
-
const settle = async (): Promise<void> => {
|
|
115
|
-
await new Promise<void>((resolve: () => void) => setTimeout(resolve, 0));
|
|
116
|
-
await Promise.resolve();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const lastMount = () => {
|
|
120
|
-
const mount = mocks.mounts.at(-1);
|
|
121
|
-
if (!mount) throw new Error("expected the image widget to have mounted");
|
|
122
|
-
return mount;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/** The inner widget reporting `CAPTCHA.NO_SESSION_FOUND` on its challenge fetch. */
|
|
126
|
-
const reportSessionInvalidated = async (): Promise<void> => {
|
|
127
|
-
const { onSessionInvalidated } = lastMount().props;
|
|
128
|
-
onSessionInvalidated?.(120, 340);
|
|
129
|
-
await settle();
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const isCheckboxPlaceholder = (): boolean =>
|
|
133
|
-
container.querySelector('[data-widget="image"]') === null;
|
|
134
|
-
|
|
135
|
-
beforeEach(async () => {
|
|
136
|
-
mocks.mounts.length = 0;
|
|
137
|
-
sessionCounter = 0;
|
|
138
|
-
detectBot.mockClear();
|
|
139
|
-
restart = vi.fn<() => void>();
|
|
140
|
-
onError = vi.fn<(error: Error) => void>();
|
|
141
|
-
container = document.createElement("div");
|
|
142
|
-
document.body.appendChild(container);
|
|
143
|
-
widget = mountProcaptchaFrictionless(container, {
|
|
144
|
-
config: config(),
|
|
145
|
-
callbacks: { onError },
|
|
146
|
-
restart,
|
|
147
|
-
i18n: i18nStub,
|
|
148
|
-
detectBot,
|
|
149
|
-
});
|
|
150
|
-
await settle();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
afterEach(() => {
|
|
154
|
-
widget?.destroy();
|
|
155
|
-
widget = undefined;
|
|
156
|
-
container.remove();
|
|
157
|
-
vi.clearAllMocks();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Production, 2026-09-07: the widget re-sent an already-consumed sessionId to
|
|
161
|
-
// /captcha/image, the provider answered 400 CAPTCHA.NO_SESSION_FOUND, and the
|
|
162
|
-
// user was left staring at a checkbox reading "No session found" with nothing
|
|
163
|
-
// behind it. The outer recovery guard was one-shot per widget lifetime and the
|
|
164
|
-
// inner widget always returns through this handler, so the second failure was
|
|
165
|
-
// handled by nobody at all.
|
|
166
|
-
describe("NO_SESSION_FOUND recovery in the frictionless widget", () => {
|
|
167
|
-
it("re-mints a session and re-mounts the widget on the first failure", async () => {
|
|
168
|
-
expect(detectBot).toHaveBeenCalledTimes(1);
|
|
169
|
-
expect(lastMount().props.frictionlessState?.sessionId).toBe(
|
|
170
|
-
"provider-session-1",
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
await reportSessionInvalidated();
|
|
174
|
-
|
|
175
|
-
expect(detectBot).toHaveBeenCalledTimes(2);
|
|
176
|
-
expect(lastMount().props.frictionlessState?.sessionId).toBe(
|
|
177
|
-
"provider-session-2",
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("resumes with autoStart and the original click coords, so the user needn't click twice", async () => {
|
|
182
|
-
await reportSessionInvalidated();
|
|
183
|
-
|
|
184
|
-
expect(lastMount().props.autoStart).toBe(true);
|
|
185
|
-
expect(lastMount().props.startCoords).toEqual({ x: 120, y: 340 });
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("keeps recovering past the first failure rather than dead-ending", async () => {
|
|
189
|
-
for (let i = 0; i < MAX_SESSION_INVALIDATED_RETRIES; i++) {
|
|
190
|
-
await reportSessionInvalidated();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// One initial run plus one re-mint per failure.
|
|
194
|
-
expect(detectBot).toHaveBeenCalledTimes(
|
|
195
|
-
MAX_SESSION_INVALIDATED_RETRIES + 1,
|
|
196
|
-
);
|
|
197
|
-
expect(isCheckboxPlaceholder()).toBe(false);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("falls back to the placeholder once the retry budget is spent, without showing the error", async () => {
|
|
201
|
-
for (let i = 0; i <= MAX_SESSION_INVALIDATED_RETRIES; i++) {
|
|
202
|
-
await reportSessionInvalidated();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// The budget-exceeding failure must not silently do nothing: the error
|
|
206
|
-
// still reaches the host page and the widget renders the placeholder,
|
|
207
|
-
// whose NO_SESSION_FOUND branch schedules the full restart.
|
|
208
|
-
expect(onError).toHaveBeenCalled();
|
|
209
|
-
expect(isCheckboxPlaceholder()).toBe(true);
|
|
210
|
-
expect(detectBot).toHaveBeenCalledTimes(
|
|
211
|
-
MAX_SESSION_INVALIDATED_RETRIES + 1,
|
|
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
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// `resetState(0)` used to be `0 || state.attemptCount`, so the counter never
|
|
240
|
-
// went back to zero and `start()`'s own `attemptCount >= 5` fall-over fired
|
|
241
|
-
// after five cumulative runs — five successful reload presses were enough to
|
|
242
|
-
// strand the user on the error placeholder.
|
|
243
|
-
it("does not fall over after repeated successful reloads", async () => {
|
|
244
|
-
for (let i = 0; i < 8; i++) {
|
|
245
|
-
const { onReload } = lastMount().props;
|
|
246
|
-
onReload?.(10, 20);
|
|
247
|
-
await settle();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
expect(isCheckboxPlaceholder()).toBe(false);
|
|
251
|
-
expect(onError).not.toHaveBeenCalled();
|
|
252
|
-
expect(detectBot).toHaveBeenCalledTimes(9);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("gives a reload press a fresh retry budget — it mints a genuinely new session", async () => {
|
|
256
|
-
for (let i = 0; i < MAX_SESSION_INVALIDATED_RETRIES; i++) {
|
|
257
|
-
await reportSessionInvalidated();
|
|
258
|
-
}
|
|
259
|
-
const beforeReload = detectBot.mock.calls.length;
|
|
260
|
-
|
|
261
|
-
const { onReload } = lastMount().props;
|
|
262
|
-
onReload?.(10, 20);
|
|
263
|
-
await settle();
|
|
264
|
-
expect(detectBot).toHaveBeenCalledTimes(beforeReload + 1);
|
|
265
|
-
|
|
266
|
-
// Without the reset this failure would land on the exhausted branch.
|
|
267
|
-
await reportSessionInvalidated();
|
|
268
|
-
|
|
269
|
-
expect(detectBot).toHaveBeenCalledTimes(beforeReload + 2);
|
|
270
|
-
expect(isCheckboxPlaceholder()).toBe(false);
|
|
271
|
-
});
|
|
272
|
-
});
|
package/tsconfig.cjs.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.cjs.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist/cjs",
|
|
6
|
-
"lib": ["es6", "dom"]
|
|
7
|
-
},
|
|
8
|
-
"include": ["src/index.ts", "src/index.html"],
|
|
9
|
-
"references": [
|
|
10
|
-
{
|
|
11
|
-
"path": "../../dev/config/tsconfig.cjs.json"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"path": "../locale/tsconfig.cjs.json"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"path": "../procaptcha-pow/tsconfig.cjs.json"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"path": "../procaptcha-puzzle/tsconfig.cjs.json"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"path": "../procaptcha-react/tsconfig.cjs.json"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"path": "../types/tsconfig.cjs.json"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"path": "../widget-skeleton/tsconfig.cjs.json"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"path": "../api/tsconfig.cjs.json"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"path": "../common/tsconfig.cjs.json"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"path": "../procaptcha-common/tsconfig.cjs.json"
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.esm.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"lib": ["es6", "dom"],
|
|
7
|
-
"allowJs": true
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"src",
|
|
11
|
-
"src/**/*.json",
|
|
12
|
-
"src/index.html",
|
|
13
|
-
"src/**/*.ts",
|
|
14
|
-
"src/**/*.tsx",
|
|
15
|
-
"src/**/*.d.ts"
|
|
16
|
-
],
|
|
17
|
-
"references": [
|
|
18
|
-
{
|
|
19
|
-
"path": "../../dev/config/tsconfig.json"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"path": "../locale"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"path": "../procaptcha-pow"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"path": "../procaptcha-puzzle"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"path": "../procaptcha-react"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"path": "../types"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"path": "../widget-skeleton"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"path": "../api"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"path": "../common"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"path": "../procaptcha-common"
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|