@prosopo/provider 5.6.2 → 5.6.3
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 +12 -9
- package/.turbo/turbo-build$colon$tsc.log +25 -25
- package/.turbo/turbo-build.log +12 -9
- package/CHANGELOG.md +28 -0
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.d.ts.map +1 -1
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.js +4 -1
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.js.map +1 -1
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/handler.d.ts.map +1 -1
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/handler.js +2 -0
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/handler.js.map +1 -1
- package/dist/api/captcha/submitPoWCaptchaSolution.d.ts +4 -1
- package/dist/api/captcha/submitPoWCaptchaSolution.d.ts.map +1 -1
- package/dist/api/captcha/submitPoWCaptchaSolution.js +23 -6
- package/dist/api/captcha/submitPoWCaptchaSolution.js.map +1 -1
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.cjs +4 -1
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/handler.cjs +2 -0
- package/dist/cjs/api/captcha/submitPoWCaptchaSolution.cjs +22 -5
- package/dist/cjs/tasks/captchaTypeSelection.cjs +53 -0
- package/dist/cjs/tasks/frictionless/frictionlessTasks.cjs +19 -8
- package/dist/cjs/tasks/puzzle/puzzleDifficulty.cjs +208 -0
- package/dist/cjs/tasks/puzzle/puzzleRenderer.cjs +13 -61
- package/dist/cjs/tasks/puzzle/stratifiedSampler.cjs +61 -0
- package/dist/tasks/captchaTypeSelection.d.ts +5 -0
- package/dist/tasks/captchaTypeSelection.d.ts.map +1 -0
- package/dist/tasks/captchaTypeSelection.js +53 -0
- package/dist/tasks/captchaTypeSelection.js.map +1 -0
- package/dist/tasks/frictionless/frictionlessTasks.d.ts.map +1 -1
- package/dist/tasks/frictionless/frictionlessTasks.js +20 -9
- package/dist/tasks/frictionless/frictionlessTasks.js.map +1 -1
- package/dist/tasks/frictionless/routingMachine.d.ts +3 -1
- package/dist/tasks/frictionless/routingMachine.d.ts.map +1 -1
- package/dist/tasks/frictionless/routingMachine.js.map +1 -1
- package/dist/tasks/puzzle/puzzleDifficulty.d.ts +25 -0
- package/dist/tasks/puzzle/puzzleDifficulty.d.ts.map +1 -0
- package/dist/tasks/puzzle/puzzleDifficulty.js +204 -0
- package/dist/tasks/puzzle/puzzleDifficulty.js.map +1 -0
- package/dist/tasks/puzzle/puzzleRenderer.d.ts +1 -3
- package/dist/tasks/puzzle/puzzleRenderer.d.ts.map +1 -1
- package/dist/tasks/puzzle/puzzleRenderer.js +15 -62
- package/dist/tasks/puzzle/puzzleRenderer.js.map +1 -1
- package/dist/tasks/puzzle/stratifiedSampler.d.ts +7 -0
- package/dist/tasks/puzzle/stratifiedSampler.d.ts.map +1 -0
- package/dist/tasks/puzzle/stratifiedSampler.js +61 -0
- package/dist/tasks/puzzle/stratifiedSampler.js.map +1 -0
- package/dist/tests/integration/api/admin/apiRegisterSiteKeyEndpoint.integration.test.js +2 -0
- package/dist/tests/integration/api/admin/apiRegisterSiteKeyEndpoint.integration.test.js.map +1 -1
- package/dist/tests/integration/clientSettingsPersistence.integration.test.js +1 -0
- package/dist/tests/integration/clientSettingsPersistence.integration.test.js.map +1 -1
- package/dist/tests/unit/api/admin/apiRegisterSiteKeyEndpoint.unit.test.js +1 -0
- package/dist/tests/unit/api/admin/apiRegisterSiteKeyEndpoint.unit.test.js.map +1 -1
- package/dist/tests/unit/api/captcha/submitPoWCaptchaSolution.escalation.unit.test.js +3 -0
- package/dist/tests/unit/api/captcha/submitPoWCaptchaSolution.escalation.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/captchaManager.unit.test.js +1 -0
- package/dist/tests/unit/tasks/captchaManager.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/captchaTypeSelection.unit.test.d.ts +2 -0
- package/dist/tests/unit/tasks/captchaTypeSelection.unit.test.d.ts.map +1 -0
- package/dist/tests/unit/tasks/captchaTypeSelection.unit.test.js +54 -0
- package/dist/tests/unit/tasks/captchaTypeSelection.unit.test.js.map +1 -0
- package/dist/tests/unit/tasks/frictionless/routerImageRoundsClamp.unit.test.js +3 -3
- package/dist/tests/unit/tasks/frictionless/routerImageRoundsClamp.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/puzzleDifficulty.unit.test.d.ts +2 -0
- package/dist/tests/unit/tasks/puzzleDifficulty.unit.test.d.ts.map +1 -0
- package/dist/tests/unit/tasks/puzzleDifficulty.unit.test.js +137 -0
- package/dist/tests/unit/tasks/puzzleDifficulty.unit.test.js.map +1 -0
- package/package.json +13 -13
|
@@ -316,6 +316,8 @@ var handler_default = (env, userAccessRulesStorage) => async (req, res, next) =>
|
|
|
316
316
|
countryCode,
|
|
317
317
|
score: botScore,
|
|
318
318
|
imageMaxRounds: clientRecord.settings.imageMaxRounds,
|
|
319
|
+
frictionlessTypes: clientRecord.settings.frictionlessTypes,
|
|
320
|
+
baseImageRounds: env.config.captchas.solved.count,
|
|
319
321
|
platform: require_devicePlatform.derivePlatform(safeUserAgent, webView, { ...typeof ipInfoMobile === "boolean" && { isMobile: ipInfoMobile } }),
|
|
320
322
|
raw: {
|
|
321
323
|
headers: flatHeaders,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_validateAddress = require("../validateAddress.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_puzzleDifficulty = require("../../tasks/puzzle/puzzleDifficulty.cjs");
|
|
3
|
+
const require_captchaTypeSelection = require("../../tasks/captchaTypeSelection.cjs");
|
|
3
4
|
const require_devicePlatform = require("../../utils/devicePlatform.cjs");
|
|
4
5
|
const require_tasks = require("../../tasks/tasks.cjs");
|
|
5
6
|
const require_apiToggleMaintenanceModeEndpoint = require("../admin/apiToggleMaintenanceModeEndpoint.cjs");
|
|
@@ -8,6 +9,7 @@ const require_rawTlsSignalsMiddleware = require("../rawTlsSignalsMiddleware.cjs"
|
|
|
8
9
|
let _prosopo_common = require("@prosopo/common");
|
|
9
10
|
let _prosopo_types = require("@prosopo/types");
|
|
10
11
|
let _prosopo_util = require("@prosopo/util");
|
|
12
|
+
let _prosopo_puzzle_assets = require("@prosopo/puzzle-assets");
|
|
11
13
|
//#region src/api/captcha/submitPoWCaptchaSolution.ts
|
|
12
14
|
var submitPoWCaptchaSolution_default = (env) => async (req, res, next) => {
|
|
13
15
|
if (require_apiToggleMaintenanceModeEndpoint.getMaintenanceMode()) {
|
|
@@ -95,6 +97,9 @@ var submitPoWCaptchaSolution_default = (env) => async (req, res, next) => {
|
|
|
95
97
|
tcpToChelloUs: req.tcpToChelloUs,
|
|
96
98
|
chelloToHandshakeUs: req.chelloToHandshakeUs,
|
|
97
99
|
...require_rawTlsSignalsMiddleware.rawTlsSignalsForSession(req)
|
|
100
|
+
}, {
|
|
101
|
+
frictionlessTypes: clientRecord.settings?.frictionlessTypes,
|
|
102
|
+
imageMaxRounds: clientRecord.settings?.imageMaxRounds
|
|
98
103
|
});
|
|
99
104
|
const response = {
|
|
100
105
|
status: "ok",
|
|
@@ -128,7 +133,7 @@ var submitPoWCaptchaSolution_default = (env) => async (req, res, next) => {
|
|
|
128
133
|
* Exported for unit testing only — the handler above is the production entry
|
|
129
134
|
* point.
|
|
130
135
|
*/
|
|
131
|
-
var buildEscalation = async (tasks, result, challenge, perConnectionSignals) => {
|
|
136
|
+
var buildEscalation = async (tasks, result, challenge, perConnectionSignals, siteConstraints) => {
|
|
132
137
|
if (!result.verified || !result.routingOutput) return void 0;
|
|
133
138
|
const routedType = result.routingOutput.captchaType;
|
|
134
139
|
if (routedType !== _prosopo_types.CaptchaType.image && routedType !== _prosopo_types.CaptchaType.puzzle) return;
|
|
@@ -137,9 +142,21 @@ var buildEscalation = async (tasks, result, challenge, perConnectionSignals) =>
|
|
|
137
142
|
const originSession = await tasks.db.getSessionRecordBySessionId(powRecord.sessionId);
|
|
138
143
|
if (!originSession) return void 0;
|
|
139
144
|
const routed = result.routingOutput;
|
|
140
|
-
const escalatedType =
|
|
145
|
+
const escalatedType = require_captchaTypeSelection.coerceToEnabledCaptchaType(routed.captchaType, siteConstraints?.frictionlessTypes);
|
|
146
|
+
if (escalatedType === _prosopo_types.CaptchaType.pow) return void 0;
|
|
147
|
+
const imageMaxRounds = siteConstraints?.imageMaxRounds ?? _prosopo_types.imageMaxRoundsDefault;
|
|
148
|
+
const escalationPuzzleOverrides = (() => {
|
|
149
|
+
if (escalatedType !== _prosopo_types.CaptchaType.puzzle) return void 0;
|
|
150
|
+
const level = require_puzzleDifficulty.severityToPuzzleDifficulty(routed.solvedImagesCount ?? originSession.solvedImagesCount, tasks.config.captchas.solved.count);
|
|
151
|
+
if (level === 0) return void 0;
|
|
152
|
+
const difficulty = require_puzzleDifficulty.samplePuzzleDifficulty(level, _prosopo_puzzle_assets.DEFAULT_RENDER_SETTINGS.holeDarken);
|
|
153
|
+
return {
|
|
154
|
+
puzzleTolerance: difficulty.tolerance,
|
|
155
|
+
puzzle: difficulty.puzzle
|
|
156
|
+
};
|
|
157
|
+
})();
|
|
141
158
|
const selectionReason = routed.reason ?? originSession.reason;
|
|
142
|
-
const newSession = await tasks.frictionlessManager.createSession(originSession.token, originSession.score, originSession.threshold, originSession.scoreComponents, originSession.ipAddress, escalatedType, originSession.siteKey ?? powRecord.dappAccount, escalatedType === _prosopo_types.CaptchaType.image ? routed.solvedImagesCount ?? originSession.solvedImagesCount : void 0, void 0, originSession.userSitekeyIpHash, originSession.webView, originSession.iFrame, originSession.decryptedHeadHash, selectionReason, void 0, void 0, originSession.ipInfo, originSession.headers, originSession.mode, originSession.simdReadings, originSession.entropyMathRandomFingerprint, originSession.entropyCryptoFingerprint, originSession.entropyWallClockOffsetMs, originSession.entropyMathRandomFirst, originSession.bundleId, originSession.currentUrl, perConnectionSignals?.tcpToChelloUs, perConnectionSignals?.chelloToHandshakeUs, true, originSession.iframeUrl, originSession.isProtect, originSession.sessionId, originSession.g, void 0, originSession.i, originSession.sw, originSession.md, originSession.bn, originSession.fs, perConnectionSignals && {
|
|
159
|
+
const newSession = await tasks.frictionlessManager.createSession(originSession.token, originSession.score, originSession.threshold, originSession.scoreComponents, originSession.ipAddress, escalatedType, originSession.siteKey ?? powRecord.dappAccount, escalatedType === _prosopo_types.CaptchaType.image ? Math.min(routed.solvedImagesCount ?? originSession.solvedImagesCount ?? tasks.config.captchas.solved.count, imageMaxRounds) : void 0, void 0, originSession.userSitekeyIpHash, originSession.webView, originSession.iFrame, originSession.decryptedHeadHash, selectionReason, void 0, void 0, originSession.ipInfo, originSession.headers, originSession.mode, originSession.simdReadings, originSession.entropyMathRandomFingerprint, originSession.entropyCryptoFingerprint, originSession.entropyWallClockOffsetMs, originSession.entropyMathRandomFirst, originSession.bundleId, originSession.currentUrl, perConnectionSignals?.tcpToChelloUs, perConnectionSignals?.chelloToHandshakeUs, true, originSession.iframeUrl, originSession.isProtect, originSession.sessionId, originSession.g, void 0, originSession.i, originSession.sw, originSession.md, originSession.bn, originSession.fs, perConnectionSignals && {
|
|
143
160
|
synNs: perConnectionSignals.synNs,
|
|
144
161
|
synackNs: perConnectionSignals.synackNs,
|
|
145
162
|
ackNs: perConnectionSignals.ackNs,
|
|
@@ -149,7 +166,7 @@ var buildEscalation = async (tasks, result, challenge, perConnectionSignals) =>
|
|
|
149
166
|
tcpOptsFlags: perConnectionSignals.tcpOptsFlags,
|
|
150
167
|
tcpOptsOrder: perConnectionSignals.tcpOptsOrder,
|
|
151
168
|
tcpWindow: perConnectionSignals.tcpWindow
|
|
152
|
-
});
|
|
169
|
+
}, escalationPuzzleOverrides);
|
|
153
170
|
if (tasks.writeQueue) await tasks.writeQueue.cacheSessionEscalation(powRecord.sessionId, newSession.sessionId);
|
|
154
171
|
return {
|
|
155
172
|
captchaType: escalatedType,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const require_puzzleRenderer = require("./puzzle/puzzleRenderer.cjs");
|
|
2
|
+
let _prosopo_types = require("@prosopo/types");
|
|
3
|
+
//#region src/tasks/captchaTypeSelection.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a requested captcha type against what the site permits and what
|
|
6
|
+
* this provider can render.
|
|
7
|
+
*
|
|
8
|
+
* Call this at every point a session's captchaType is DECIDED, never at the
|
|
9
|
+
* point one is served: `/captcha/puzzle` answers with a puzzle-shaped
|
|
10
|
+
* response and nothing else, so a session minted as a type we cannot fulfil
|
|
11
|
+
* strands the user on INCORRECT_CAPTCHA_TYPE. There are two such mint sites —
|
|
12
|
+
* `sendCaptcha` in frictionlessTasks (which every frictionless path funnels
|
|
13
|
+
* through, after the routing machine has had its say) and `buildEscalation`
|
|
14
|
+
* in submitPoWCaptchaSolution.
|
|
15
|
+
*
|
|
16
|
+
* Because it sits after routing, this covers every upstream selector
|
|
17
|
+
* transitively: the score ladder, the no-measurement gates, access-policy
|
|
18
|
+
* Restrict rules, traffic-filter category policies, routing-machine actions
|
|
19
|
+
* and detector-generated rules.
|
|
20
|
+
*
|
|
21
|
+
* Coercion only ever narrows. A disabled type falls back to the other
|
|
22
|
+
* interactive type if that is permitted, and to PoW otherwise — never the
|
|
23
|
+
* reverse, so this can't hand a user a harder challenge than was asked for.
|
|
24
|
+
*/
|
|
25
|
+
var coerceToEnabledCaptchaType = (requested, frictionlessTypes, logger) => {
|
|
26
|
+
const types = (0, _prosopo_types.resolveFrictionlessTypes)(frictionlessTypes);
|
|
27
|
+
const puzzleAllowed = types.puzzle && require_puzzleRenderer.isPuzzleRenderAvailable();
|
|
28
|
+
const imageAllowed = types.image;
|
|
29
|
+
const resolved = (() => {
|
|
30
|
+
switch (requested) {
|
|
31
|
+
case _prosopo_types.CaptchaType.pow: return _prosopo_types.CaptchaType.pow;
|
|
32
|
+
case _prosopo_types.CaptchaType.puzzle:
|
|
33
|
+
if (puzzleAllowed) return _prosopo_types.CaptchaType.puzzle;
|
|
34
|
+
return imageAllowed ? _prosopo_types.CaptchaType.image : _prosopo_types.CaptchaType.pow;
|
|
35
|
+
case _prosopo_types.CaptchaType.image:
|
|
36
|
+
if (imageAllowed) return _prosopo_types.CaptchaType.image;
|
|
37
|
+
return puzzleAllowed ? _prosopo_types.CaptchaType.puzzle : _prosopo_types.CaptchaType.pow;
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
if (resolved !== requested) logger?.info(() => ({
|
|
41
|
+
msg: "Captcha type coerced to an enabled type",
|
|
42
|
+
data: {
|
|
43
|
+
requested,
|
|
44
|
+
served: resolved,
|
|
45
|
+
imageEnabled: types.image,
|
|
46
|
+
puzzleEnabled: types.puzzle,
|
|
47
|
+
puzzleRenderable: require_puzzleRenderer.isPuzzleRenderAvailable()
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return resolved;
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.coerceToEnabledCaptchaType = coerceToEnabledCaptchaType;
|
|
@@ -3,10 +3,12 @@ const require_decisionMachineRunner = require("../decisionMachine/decisionMachin
|
|
|
3
3
|
const require_dnsEventUrl = require("../../api/dnsEventUrl.cjs");
|
|
4
4
|
const require_lang = require("../../rules/lang.cjs");
|
|
5
5
|
const require_captchaManager = require("../captchaManager.cjs");
|
|
6
|
+
const require_puzzleDifficulty = require("../puzzle/puzzleDifficulty.cjs");
|
|
7
|
+
const require_captchaTypeSelection = require("../captchaTypeSelection.cjs");
|
|
6
8
|
const require_getBotScore = require("../detection/getBotScore.cjs");
|
|
7
|
-
const require_puzzleRenderer = require("../puzzle/puzzleRenderer.cjs");
|
|
8
9
|
const require_routingMachine = require("./routingMachine.cjs");
|
|
9
10
|
let _prosopo_types = require("@prosopo/types");
|
|
11
|
+
let _prosopo_puzzle_assets = require("@prosopo/puzzle-assets");
|
|
10
12
|
let uuid = require("uuid");
|
|
11
13
|
//#region src/tasks/frictionless/frictionlessTasks.ts
|
|
12
14
|
var DEFAULT_MAX_TIMESTAMP_AGE = 600 * 1e3;
|
|
@@ -190,15 +192,24 @@ var FrictionlessManager = class extends require_captchaManager.CaptchaManager {
|
|
|
190
192
|
powDifficulty: captchaType === _prosopo_types.CaptchaType.pow ? effectiveParams.powDifficulty : void 0
|
|
191
193
|
};
|
|
192
194
|
const routed = this.routingContext ? await require_routingMachine.applyRouter(this.decisionMachineRunner, this.usageCounters, baseline, this.routingContext, this.logger) : baseline;
|
|
193
|
-
const finalCaptchaType =
|
|
195
|
+
const finalCaptchaType = require_captchaTypeSelection.coerceToEnabledCaptchaType(routed.captchaType, this.routingContext?.frictionlessTypes, this.logger);
|
|
194
196
|
const requestedSolvedImagesCount = routed.solvedImagesCount ?? effectiveParams.solvedImagesCount;
|
|
195
|
-
const imageRoundsCeiling = this.routingContext?.imageMaxRounds;
|
|
196
|
-
const finalSolvedImagesCount = finalCaptchaType === _prosopo_types.CaptchaType.image ? requestedSolvedImagesCount !== void 0
|
|
197
|
+
const imageRoundsCeiling = this.routingContext?.imageMaxRounds ?? _prosopo_types.imageMaxRoundsDefault;
|
|
198
|
+
const finalSolvedImagesCount = finalCaptchaType === _prosopo_types.CaptchaType.image ? requestedSolvedImagesCount !== void 0 ? Math.min(requestedSolvedImagesCount, imageRoundsCeiling) : requestedSolvedImagesCount : void 0;
|
|
197
199
|
const finalPowDifficulty = finalCaptchaType === _prosopo_types.CaptchaType.pow ? routed.powDifficulty ?? effectiveParams.powDifficulty : void 0;
|
|
198
|
-
const finalPuzzleOverrides = finalCaptchaType === _prosopo_types.CaptchaType.puzzle ? {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
const finalPuzzleOverrides = finalCaptchaType === _prosopo_types.CaptchaType.puzzle ? (() => {
|
|
201
|
+
const level = require_puzzleDifficulty.severityToPuzzleDifficulty(requestedSolvedImagesCount, this.routingContext?.baseImageRounds ?? this.config.captchas.solved.count);
|
|
202
|
+
const difficulty = level > 0 ? require_puzzleDifficulty.samplePuzzleDifficulty(level, _prosopo_puzzle_assets.DEFAULT_RENDER_SETTINGS.holeDarken) : void 0;
|
|
203
|
+
const tolerance = routed.puzzleTolerance ?? difficulty?.tolerance;
|
|
204
|
+
const puzzle = routed.puzzle || difficulty ? {
|
|
205
|
+
...difficulty?.puzzle ?? {},
|
|
206
|
+
...routed.puzzle ?? {}
|
|
207
|
+
} : void 0;
|
|
208
|
+
return {
|
|
209
|
+
...tolerance !== void 0 && { puzzleTolerance: tolerance },
|
|
210
|
+
...puzzle !== void 0 && { puzzle }
|
|
211
|
+
};
|
|
212
|
+
})() : {};
|
|
202
213
|
const finalReason = routed.reason ?? effectiveParams.reason;
|
|
203
214
|
const blocked = finalCaptchaType === _prosopo_types.CaptchaType.image ? effectiveParams.blocked : void 0;
|
|
204
215
|
const sessionRecord = await this.createSession(effectiveParams.token, effectiveParams.score, effectiveParams.threshold, effectiveParams.scoreComponents, effectiveParams.ipAddress, finalCaptchaType, effectiveParams.siteKey, finalSolvedImagesCount, finalPowDifficulty, effectiveParams.userSitekeyIpHash, effectiveParams.webView ?? false, effectiveParams.iFrame ?? false, effectiveParams.decryptedHeadHash, finalReason, blocked, void 0, effectiveParams.ipInfo, effectiveParams.headers, effectiveParams.mode, effectiveParams.simdReadings, effectiveParams.entropyMathRandomFingerprint, effectiveParams.entropyCryptoFingerprint, effectiveParams.entropyWallClockOffsetMs, effectiveParams.entropyMathRandomFirst, effectiveParams.bundleId, effectiveParams.currentUrl, effectiveParams.tcpToChelloUs, effectiveParams.chelloToHandshakeUs, void 0, effectiveParams.iframeUrl, effectiveParams.isProtect, void 0, effectiveParams.g, effectiveParams.matchedRule, effectiveParams.i, effectiveParams.sw, effectiveParams.md, effectiveParams.bn, effectiveParams.fs, {
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const require_stratifiedSampler = require("./stratifiedSampler.cjs");
|
|
2
|
+
//#region src/tasks/puzzle/puzzleDifficulty.ts
|
|
3
|
+
/**
|
|
4
|
+
* Minimum gap that must remain between `decoyHoleDarken` and `holeDarken`.
|
|
5
|
+
*
|
|
6
|
+
* The real cutout has to stay the deepest region on the frame or a human
|
|
7
|
+
* cannot tell target from decoy at all. But pushed too far apart, a solver
|
|
8
|
+
* simply thresholds on brightness and ignores shape. The ladder walks
|
|
9
|
+
* `decoyHoleDarken` down toward `holeDarken` as difficulty rises; this floor
|
|
10
|
+
* is what stops it crossing over. Enforced by clamping every sampled value,
|
|
11
|
+
* not by trusting the band table to be authored correctly.
|
|
12
|
+
*/
|
|
13
|
+
var MIN_DECOY_HOLE_DARKEN_MARGIN = .04;
|
|
14
|
+
/**
|
|
15
|
+
* L0 reproduces the shipped defaults (decoyCount 5, decoyEdgeDarkness 20,
|
|
16
|
+
* decoyHoleDarken 0.7, tolerance 15, pieceScale 0.15-0.45) so a site that
|
|
17
|
+
* never escalates sees no change in behaviour.
|
|
18
|
+
*
|
|
19
|
+
* The numbers above L0 are STARTING POINTS, not calibrated values. They need
|
|
20
|
+
* validating against observed human first-attempt solve rate per level,
|
|
21
|
+
* segmented by device class — see the shadow-calibration note on
|
|
22
|
+
* `severityToPuzzleDifficulty`.
|
|
23
|
+
*/
|
|
24
|
+
var PUZZLE_DIFFICULTY_LEVELS = [
|
|
25
|
+
{
|
|
26
|
+
level: 0,
|
|
27
|
+
tolerance: {
|
|
28
|
+
min: 14,
|
|
29
|
+
max: 16
|
|
30
|
+
},
|
|
31
|
+
decoyCount: {
|
|
32
|
+
min: 4,
|
|
33
|
+
max: 6
|
|
34
|
+
},
|
|
35
|
+
decoyHoleDarken: {
|
|
36
|
+
min: .68,
|
|
37
|
+
max: .72
|
|
38
|
+
},
|
|
39
|
+
decoyEdgeDarkness: {
|
|
40
|
+
min: 18,
|
|
41
|
+
max: 22
|
|
42
|
+
},
|
|
43
|
+
pieceScale: {
|
|
44
|
+
min: .15,
|
|
45
|
+
max: .45
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
level: 1,
|
|
50
|
+
tolerance: {
|
|
51
|
+
min: 12,
|
|
52
|
+
max: 15
|
|
53
|
+
},
|
|
54
|
+
decoyCount: {
|
|
55
|
+
min: 6,
|
|
56
|
+
max: 10
|
|
57
|
+
},
|
|
58
|
+
decoyHoleDarken: {
|
|
59
|
+
min: .66,
|
|
60
|
+
max: .7
|
|
61
|
+
},
|
|
62
|
+
decoyEdgeDarkness: {
|
|
63
|
+
min: 20,
|
|
64
|
+
max: 24
|
|
65
|
+
},
|
|
66
|
+
pieceScale: {
|
|
67
|
+
min: .14,
|
|
68
|
+
max: .4
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
level: 2,
|
|
73
|
+
tolerance: {
|
|
74
|
+
min: 10,
|
|
75
|
+
max: 13
|
|
76
|
+
},
|
|
77
|
+
decoyCount: {
|
|
78
|
+
min: 10,
|
|
79
|
+
max: 16
|
|
80
|
+
},
|
|
81
|
+
decoyHoleDarken: {
|
|
82
|
+
min: .64,
|
|
83
|
+
max: .68
|
|
84
|
+
},
|
|
85
|
+
decoyEdgeDarkness: {
|
|
86
|
+
min: 22,
|
|
87
|
+
max: 27
|
|
88
|
+
},
|
|
89
|
+
pieceScale: {
|
|
90
|
+
min: .12,
|
|
91
|
+
max: .34
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
level: 3,
|
|
96
|
+
tolerance: {
|
|
97
|
+
min: 8,
|
|
98
|
+
max: 11
|
|
99
|
+
},
|
|
100
|
+
decoyCount: {
|
|
101
|
+
min: 16,
|
|
102
|
+
max: 26
|
|
103
|
+
},
|
|
104
|
+
decoyHoleDarken: {
|
|
105
|
+
min: .62,
|
|
106
|
+
max: .66
|
|
107
|
+
},
|
|
108
|
+
decoyEdgeDarkness: {
|
|
109
|
+
min: 25,
|
|
110
|
+
max: 30
|
|
111
|
+
},
|
|
112
|
+
pieceScale: {
|
|
113
|
+
min: .1,
|
|
114
|
+
max: .28
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
level: 4,
|
|
119
|
+
tolerance: {
|
|
120
|
+
min: 6,
|
|
121
|
+
max: 9
|
|
122
|
+
},
|
|
123
|
+
decoyCount: {
|
|
124
|
+
min: 26,
|
|
125
|
+
max: 40
|
|
126
|
+
},
|
|
127
|
+
decoyHoleDarken: {
|
|
128
|
+
min: .6,
|
|
129
|
+
max: .64
|
|
130
|
+
},
|
|
131
|
+
decoyEdgeDarkness: {
|
|
132
|
+
min: 28,
|
|
133
|
+
max: 34
|
|
134
|
+
},
|
|
135
|
+
pieceScale: {
|
|
136
|
+
min: .09,
|
|
137
|
+
max: .22
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
var toleranceSampler = require_stratifiedSampler.createStratifiedSampler();
|
|
142
|
+
var decoyCountSampler = require_stratifiedSampler.createStratifiedSampler();
|
|
143
|
+
var decoyHoleDarkenSampler = require_stratifiedSampler.createStratifiedSampler();
|
|
144
|
+
var decoyEdgeDarknessSampler = require_stratifiedSampler.createStratifiedSampler();
|
|
145
|
+
var clampDifficultyLevel = (level, maxLevel = 3) => {
|
|
146
|
+
const ceiling = Math.min(maxLevel, PUZZLE_DIFFICULTY_LEVELS.length - 1);
|
|
147
|
+
if (!Number.isFinite(level)) return 0;
|
|
148
|
+
return Math.max(0, Math.min(Math.floor(level), ceiling));
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Map the severity currency every existing call-site already speaks — image
|
|
152
|
+
* rounds — onto a difficulty level.
|
|
153
|
+
*
|
|
154
|
+
* Severity is expressed as rounds ABOVE the site's ordinary count rather than
|
|
155
|
+
* an absolute, because the baseline (`env.config.captchas.solved.count`, or a
|
|
156
|
+
* rule's own `solvedImagesCount`) varies per site. "Two more rounds than
|
|
157
|
+
* normal" means the same thing everywhere; "four rounds" does not.
|
|
158
|
+
*
|
|
159
|
+
* Keeping one ordering here means the score ladder, the no-measurement gates,
|
|
160
|
+
* detector rules and traffic-filter policies cannot drift apart on what
|
|
161
|
+
* counts as more severe.
|
|
162
|
+
*/
|
|
163
|
+
var severityToPuzzleDifficulty = (requestedImageRounds, baseImageRounds, maxLevel = 3) => {
|
|
164
|
+
if (requestedImageRounds === void 0) return 0;
|
|
165
|
+
const excess = requestedImageRounds - baseImageRounds;
|
|
166
|
+
if (!Number.isFinite(excess) || excess <= 0) return clampDifficultyLevel(0, maxLevel);
|
|
167
|
+
if (excess <= 2) return clampDifficultyLevel(1, maxLevel);
|
|
168
|
+
if (excess <= 4) return clampDifficultyLevel(2, maxLevel);
|
|
169
|
+
if (excess <= 6) return clampDifficultyLevel(3, maxLevel);
|
|
170
|
+
return clampDifficultyLevel(4, maxLevel);
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Draw a concrete puzzle config from a level's bands.
|
|
174
|
+
*
|
|
175
|
+
* Sampling is server-side and per-challenge, and is deliberately NOT derived
|
|
176
|
+
* from anything the client supplies (sessionId, token, ip, timestamp). A
|
|
177
|
+
* client-derived seed would let a bot replay a request to obtain the same
|
|
178
|
+
* render, or precompute one offline.
|
|
179
|
+
*
|
|
180
|
+
* `pieceScale` is passed through as a range rather than drawn here: the
|
|
181
|
+
* renderer's own stratified piece-size draw consumes it in
|
|
182
|
+
* `resolvePuzzlePieceSize`, and sampling twice would narrow the distribution.
|
|
183
|
+
*/
|
|
184
|
+
var samplePuzzleDifficulty = (level, holeDarken, maxLevel = 3) => {
|
|
185
|
+
const index = clampDifficultyLevel(level, maxLevel);
|
|
186
|
+
const band = PUZZLE_DIFFICULTY_LEVELS[index];
|
|
187
|
+
const decoyHoleDarkenFloor = holeDarken + MIN_DECOY_HOLE_DARKEN_MARGIN;
|
|
188
|
+
const sampledDecoyHoleDarken = decoyHoleDarkenSampler.sample(band.decoyHoleDarken.min, band.decoyHoleDarken.max);
|
|
189
|
+
return {
|
|
190
|
+
level: index,
|
|
191
|
+
tolerance: toleranceSampler.sampleInt(band.tolerance.min, band.tolerance.max),
|
|
192
|
+
puzzle: {
|
|
193
|
+
decoyCount: decoyCountSampler.sampleInt(band.decoyCount.min, band.decoyCount.max),
|
|
194
|
+
decoyEdgeDarkness: decoyEdgeDarknessSampler.sampleInt(band.decoyEdgeDarkness.min, band.decoyEdgeDarkness.max),
|
|
195
|
+
decoyHoleDarken: Math.min(1, Math.max(decoyHoleDarkenFloor, sampledDecoyHoleDarken)),
|
|
196
|
+
pieceScale: {
|
|
197
|
+
min: band.pieceScale.min,
|
|
198
|
+
max: band.pieceScale.max
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
//#endregion
|
|
204
|
+
exports.MIN_DECOY_HOLE_DARKEN_MARGIN = MIN_DECOY_HOLE_DARKEN_MARGIN;
|
|
205
|
+
exports.PUZZLE_DIFFICULTY_LEVELS = PUZZLE_DIFFICULTY_LEVELS;
|
|
206
|
+
exports.clampDifficultyLevel = clampDifficultyLevel;
|
|
207
|
+
exports.samplePuzzleDifficulty = samplePuzzleDifficulty;
|
|
208
|
+
exports.severityToPuzzleDifficulty = severityToPuzzleDifficulty;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const require_backgroundBuffer = require("./backgroundBuffer.cjs");
|
|
2
|
+
const require_stratifiedSampler = require("./stratifiedSampler.cjs");
|
|
3
|
+
const require_puzzleDifficulty = require("./puzzleDifficulty.cjs");
|
|
2
4
|
let _prosopo_types = require("@prosopo/types");
|
|
3
5
|
let _prosopo_puzzle_assets = require("@prosopo/puzzle-assets");
|
|
4
6
|
//#region src/tasks/puzzle/puzzleRenderer.ts
|
|
@@ -33,46 +35,21 @@ var resolvePuzzleRenderSettings = (...overrides) => {
|
|
|
33
35
|
decoyHoleDarken: override.decoyHoleDarken
|
|
34
36
|
};
|
|
35
37
|
}
|
|
38
|
+
const floor = resolved.holeDarken + require_puzzleDifficulty.MIN_DECOY_HOLE_DARKEN_MARGIN;
|
|
39
|
+
if (resolved.decoyHoleDarken < floor) resolved = {
|
|
40
|
+
...resolved,
|
|
41
|
+
decoyHoleDarken: Math.min(1, floor)
|
|
42
|
+
};
|
|
36
43
|
return resolved;
|
|
37
44
|
};
|
|
38
|
-
|
|
39
|
-
* Number of size buckets used for stratified sampling. The scale range is
|
|
40
|
-
* split into this many equal windows; every window is visited once per
|
|
41
|
-
* cycle before the sequence repeats, so a short run of challenges is
|
|
42
|
-
* guaranteed to span the full range rather than clustering by chance.
|
|
43
|
-
*/
|
|
44
|
-
var PIECE_SIZE_BUCKETS = 8;
|
|
45
|
-
var pieceSizeBucketOrder = [];
|
|
46
|
-
var pieceSizeBucketCursor = 0;
|
|
47
|
-
var shuffleArray = (input) => {
|
|
48
|
-
const out = [...input];
|
|
49
|
-
for (let i = out.length - 1; i > 0; i--) {
|
|
50
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
51
|
-
const tmp = out[i];
|
|
52
|
-
out[i] = out[j];
|
|
53
|
-
out[j] = tmp;
|
|
54
|
-
}
|
|
55
|
-
return out;
|
|
56
|
-
};
|
|
57
|
-
var buildBucketOrder = () => {
|
|
58
|
-
const half = PIECE_SIZE_BUCKETS >> 1;
|
|
59
|
-
const smallHalf = shuffleArray(Array.from({ length: half }, (_, i) => i));
|
|
60
|
-
const largeHalf = shuffleArray(Array.from({ length: half }, (_, i) => i + half));
|
|
61
|
-
const [first, second] = Math.random() < .5 ? [smallHalf, largeHalf] : [largeHalf, smallHalf];
|
|
62
|
-
const order = [];
|
|
63
|
-
for (let i = 0; i < half; i++) {
|
|
64
|
-
order.push(first[i]);
|
|
65
|
-
order.push(second[i]);
|
|
66
|
-
}
|
|
67
|
-
return order;
|
|
68
|
-
};
|
|
45
|
+
var pieceSizeSampler = require_stratifiedSampler.createStratifiedSampler();
|
|
69
46
|
/**
|
|
70
47
|
* Resolve the effective piece scale range from the same layered
|
|
71
48
|
* client-settings / traffic-filter overrides used for render settings, and
|
|
72
|
-
* draw a per-challenge piece size in pixels. Stratified
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
49
|
+
* draw a per-challenge piece size in pixels. Stratified so the distribution
|
|
50
|
+
* is evenly spread across the range even for short bursts of requests.
|
|
51
|
+
* Rounded to an integer because the pixel buffer is allocated as
|
|
52
|
+
* `size * size * 4`.
|
|
76
53
|
*/
|
|
77
54
|
var resolvePuzzlePieceSize = (...overrides) => {
|
|
78
55
|
let min = _prosopo_types.puzzlePieceScaleMinDefault;
|
|
@@ -83,14 +60,7 @@ var resolvePuzzlePieceSize = (...overrides) => {
|
|
|
83
60
|
if (override.pieceScale.max !== void 0) max = override.pieceScale.max;
|
|
84
61
|
}
|
|
85
62
|
if (min > max) min = max;
|
|
86
|
-
|
|
87
|
-
pieceSizeBucketOrder = buildBucketOrder();
|
|
88
|
-
pieceSizeBucketCursor = 0;
|
|
89
|
-
}
|
|
90
|
-
const bucket = pieceSizeBucketOrder[pieceSizeBucketCursor];
|
|
91
|
-
pieceSizeBucketCursor++;
|
|
92
|
-
const u = (bucket + Math.random()) / PIECE_SIZE_BUCKETS;
|
|
93
|
-
const scale = min + u * (max - min);
|
|
63
|
+
const scale = pieceSizeSampler.sample(min, max);
|
|
94
64
|
return Math.max(1, Math.round(_prosopo_puzzle_assets.DEFAULT_GEOMETRY.width * scale));
|
|
95
65
|
};
|
|
96
66
|
/**
|
|
@@ -106,23 +76,6 @@ var resolvePuzzlePieceSize = (...overrides) => {
|
|
|
106
76
|
var isPuzzleRenderAvailable = () => {
|
|
107
77
|
return true;
|
|
108
78
|
};
|
|
109
|
-
/**
|
|
110
|
-
* Substitute `image` for `puzzle` when this provider cannot render imagery.
|
|
111
|
-
*
|
|
112
|
-
* Call this at every point a session's captchaType is decided, never at the
|
|
113
|
-
* point one is served. Returns other types untouched.
|
|
114
|
-
*/
|
|
115
|
-
var downgradePuzzleIfUnavailable = (captchaType, logger) => {
|
|
116
|
-
if (captchaType !== _prosopo_types.CaptchaType.puzzle || isPuzzleRenderAvailable()) return captchaType;
|
|
117
|
-
logger?.warn(() => ({
|
|
118
|
-
msg: "Puzzle rendering unavailable - downgrading session to image",
|
|
119
|
-
data: {
|
|
120
|
-
requested: captchaType,
|
|
121
|
-
served: _prosopo_types.CaptchaType.image
|
|
122
|
-
}
|
|
123
|
-
}));
|
|
124
|
-
return _prosopo_types.CaptchaType.image;
|
|
125
|
-
};
|
|
126
79
|
var renderPuzzleImages = async (placement, settings = _prosopo_puzzle_assets.DEFAULT_RENDER_SETTINGS, pieceSize) => {
|
|
127
80
|
const background = (require_backgroundBuffer.getPuzzleBackgroundBuffer() ?? require_backgroundBuffer.initPuzzleBackgroundBuffer()).take();
|
|
128
81
|
if (!background) throw new Error("puzzle renderer: no background available");
|
|
@@ -137,7 +90,6 @@ var renderPuzzleImages = async (placement, settings = _prosopo_puzzle_assets.DEF
|
|
|
137
90
|
};
|
|
138
91
|
};
|
|
139
92
|
//#endregion
|
|
140
|
-
exports.downgradePuzzleIfUnavailable = downgradePuzzleIfUnavailable;
|
|
141
93
|
exports.isPuzzleRenderAvailable = isPuzzleRenderAvailable;
|
|
142
94
|
exports.renderPuzzleImages = renderPuzzleImages;
|
|
143
95
|
exports.resolvePuzzlePieceSize = resolvePuzzlePieceSize;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
let node_crypto = require("node:crypto");
|
|
2
|
+
/**
|
|
3
|
+
* Uniform float in [0, 1), from the CSPRNG rather than `Math.random()`.
|
|
4
|
+
*
|
|
5
|
+
* V8 implements `Math.random()` as xorshift128+, whose internal state is
|
|
6
|
+
* recoverable from a short run of consecutive outputs. That matters here
|
|
7
|
+
* specifically: the point of sampling these knobs is that an automated solver
|
|
8
|
+
* cannot calibrate against a known render, and a predictable stream gives it
|
|
9
|
+
* exactly that — observe a few challenges, recover the state, and every
|
|
10
|
+
* subsequent draw is known in advance. The unpredictability IS the security
|
|
11
|
+
* property, so it has to come from a source built for it.
|
|
12
|
+
*
|
|
13
|
+
* 48 bits (6 bytes) is the most a float64 can hold without rounding, so the
|
|
14
|
+
* result is uniform with no modulo bias.
|
|
15
|
+
*/
|
|
16
|
+
var RANDOM_BYTES = 6;
|
|
17
|
+
var RANDOM_DENOMINATOR = 2 ** (RANDOM_BYTES * 8);
|
|
18
|
+
var secureUnitFloat = () => Number((0, node_crypto.randomBytes)(RANDOM_BYTES).readUIntBE(0, RANDOM_BYTES)) / RANDOM_DENOMINATOR;
|
|
19
|
+
var shuffleArray = (input) => {
|
|
20
|
+
const out = [...input];
|
|
21
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
22
|
+
const j = (0, node_crypto.randomInt)(0, i + 1);
|
|
23
|
+
const tmp = out[i];
|
|
24
|
+
out[i] = out[j];
|
|
25
|
+
out[j] = tmp;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
};
|
|
29
|
+
var createStratifiedSampler = (buckets = 8) => {
|
|
30
|
+
const bucketCount = buckets > 0 && buckets % 2 === 0 ? buckets : 8;
|
|
31
|
+
let order = [];
|
|
32
|
+
let cursor = 0;
|
|
33
|
+
const buildOrder = () => {
|
|
34
|
+
const half = bucketCount >> 1;
|
|
35
|
+
const lowHalf = shuffleArray(Array.from({ length: half }, (_, i) => i));
|
|
36
|
+
const highHalf = shuffleArray(Array.from({ length: half }, (_, i) => i + half));
|
|
37
|
+
const [first, second] = (0, node_crypto.randomInt)(0, 2) === 0 ? [lowHalf, highHalf] : [highHalf, lowHalf];
|
|
38
|
+
const next = [];
|
|
39
|
+
for (let i = 0; i < half; i++) {
|
|
40
|
+
next.push(first[i]);
|
|
41
|
+
next.push(second[i]);
|
|
42
|
+
}
|
|
43
|
+
return next;
|
|
44
|
+
};
|
|
45
|
+
const sample = (min, max) => {
|
|
46
|
+
if (!(max > min)) return min;
|
|
47
|
+
if (cursor >= order.length) {
|
|
48
|
+
order = buildOrder();
|
|
49
|
+
cursor = 0;
|
|
50
|
+
}
|
|
51
|
+
const bucket = order[cursor];
|
|
52
|
+
cursor++;
|
|
53
|
+
return min + (bucket + secureUnitFloat()) / bucketCount * (max - min);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
sample,
|
|
57
|
+
sampleInt: (min, max) => Math.round(sample(min, max))
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.createStratifiedSampler = createStratifiedSampler;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Logger } from "@prosopo/logger";
|
|
2
|
+
import { CaptchaType, type IFrictionlessTypes } from "@prosopo/types";
|
|
3
|
+
export type ConcreteCaptchaType = CaptchaType.pow | CaptchaType.image | CaptchaType.puzzle;
|
|
4
|
+
export declare const coerceToEnabledCaptchaType: (requested: ConcreteCaptchaType, frictionlessTypes: Partial<IFrictionlessTypes> | undefined, logger?: Logger) => ConcreteCaptchaType;
|
|
5
|
+
//# sourceMappingURL=captchaTypeSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captchaTypeSelection.d.ts","sourceRoot":"","sources":["../../src/tasks/captchaTypeSelection.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACN,WAAW,EACX,KAAK,kBAAkB,EAEvB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,MAAM,mBAAmB,GAC5B,WAAW,CAAC,GAAG,GACf,WAAW,CAAC,KAAK,GACjB,WAAW,CAAC,MAAM,CAAC;AAuBtB,eAAO,MAAM,0BAA0B,cAC3B,mBAAmB,qBACX,OAAO,CAAC,kBAAkB,CAAC,GAAG,SAAS,WACjD,MAAM,KACb,mBAsCF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isPuzzleRenderAvailable } from "./puzzle/puzzleRenderer.js";
|
|
2
|
+
import { CaptchaType, resolveFrictionlessTypes } from "@prosopo/types";
|
|
3
|
+
//#region src/tasks/captchaTypeSelection.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a requested captcha type against what the site permits and what
|
|
6
|
+
* this provider can render.
|
|
7
|
+
*
|
|
8
|
+
* Call this at every point a session's captchaType is DECIDED, never at the
|
|
9
|
+
* point one is served: `/captcha/puzzle` answers with a puzzle-shaped
|
|
10
|
+
* response and nothing else, so a session minted as a type we cannot fulfil
|
|
11
|
+
* strands the user on INCORRECT_CAPTCHA_TYPE. There are two such mint sites —
|
|
12
|
+
* `sendCaptcha` in frictionlessTasks (which every frictionless path funnels
|
|
13
|
+
* through, after the routing machine has had its say) and `buildEscalation`
|
|
14
|
+
* in submitPoWCaptchaSolution.
|
|
15
|
+
*
|
|
16
|
+
* Because it sits after routing, this covers every upstream selector
|
|
17
|
+
* transitively: the score ladder, the no-measurement gates, access-policy
|
|
18
|
+
* Restrict rules, traffic-filter category policies, routing-machine actions
|
|
19
|
+
* and detector-generated rules.
|
|
20
|
+
*
|
|
21
|
+
* Coercion only ever narrows. A disabled type falls back to the other
|
|
22
|
+
* interactive type if that is permitted, and to PoW otherwise — never the
|
|
23
|
+
* reverse, so this can't hand a user a harder challenge than was asked for.
|
|
24
|
+
*/
|
|
25
|
+
var coerceToEnabledCaptchaType = (requested, frictionlessTypes, logger) => {
|
|
26
|
+
const types = resolveFrictionlessTypes(frictionlessTypes);
|
|
27
|
+
const puzzleAllowed = types.puzzle && isPuzzleRenderAvailable();
|
|
28
|
+
const imageAllowed = types.image;
|
|
29
|
+
const resolved = (() => {
|
|
30
|
+
switch (requested) {
|
|
31
|
+
case CaptchaType.pow: return CaptchaType.pow;
|
|
32
|
+
case CaptchaType.puzzle:
|
|
33
|
+
if (puzzleAllowed) return CaptchaType.puzzle;
|
|
34
|
+
return imageAllowed ? CaptchaType.image : CaptchaType.pow;
|
|
35
|
+
case CaptchaType.image:
|
|
36
|
+
if (imageAllowed) return CaptchaType.image;
|
|
37
|
+
return puzzleAllowed ? CaptchaType.puzzle : CaptchaType.pow;
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
if (resolved !== requested) logger?.info(() => ({
|
|
41
|
+
msg: "Captcha type coerced to an enabled type",
|
|
42
|
+
data: {
|
|
43
|
+
requested,
|
|
44
|
+
served: resolved,
|
|
45
|
+
imageEnabled: types.image,
|
|
46
|
+
puzzleEnabled: types.puzzle,
|
|
47
|
+
puzzleRenderable: isPuzzleRenderAvailable()
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return resolved;
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { coerceToEnabledCaptchaType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captchaTypeSelection.js","sourceRoot":"","sources":["../../src/tasks/captchaTypeSelection.ts"],"names":[],"mappings":"AAeA,OAAO,EACN,WAAW,EAEX,wBAAwB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AA6BrE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACzC,SAA8B,EAC9B,iBAA0D,EAC1D,MAAe,EACO,EAAE;IACxB,MAAM,KAAK,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;IAK1D,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,IAAI,uBAAuB,EAAE,CAAC;IAChE,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC;IAEjC,MAAM,QAAQ,GAAG,CAAC,GAAwB,EAAE;QAC3C,QAAQ,SAAS,EAAE,CAAC;YACnB,KAAK,WAAW,CAAC,GAAG;gBAGnB,OAAO,WAAW,CAAC,GAAG,CAAC;YACxB,KAAK,WAAW,CAAC,MAAM;gBACtB,IAAI,aAAa;oBAAE,OAAO,WAAW,CAAC,MAAM,CAAC;gBAC7C,OAAO,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC;YAC3D,KAAK,WAAW,CAAC,KAAK;gBACrB,IAAI,YAAY;oBAAE,OAAO,WAAW,CAAC,KAAK,CAAC;gBAC3C,OAAO,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC;QAC9D,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YACnB,GAAG,EAAE,yCAAyC;YAC9C,IAAI,EAAE;gBACL,SAAS;gBACT,MAAM,EAAE,QAAQ;gBAChB,YAAY,EAAE,KAAK,CAAC,KAAK;gBACzB,aAAa,EAAE,KAAK,CAAC,MAAM;gBAC3B,gBAAgB,EAAE,uBAAuB,EAAE;aAC3C;SACD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frictionlessTasks.d.ts","sourceRoot":"","sources":["../../../src/tasks/frictionless/frictionlessTasks.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"frictionlessTasks.d.ts","sourceRoot":"","sources":["../../../src/tasks/frictionless/frictionlessTasks.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAEN,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,kBAAkB,EAClB,KAAK,8BAA8B,EACnC,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,OAAO,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE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