@prosopo/provider 4.15.14 → 4.15.15
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 +106 -106
- package/.turbo/turbo-build$colon$tsc.log +24 -24
- package/.turbo/turbo-build.log +107 -104
- package/CHANGELOG.md +49 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/api/admin/apiAdminRoutesProvider.js +27 -46
- package/dist/api/admin/apiClearAllCountersEndpoint.js +62 -57
- package/dist/api/admin/apiDnsEventEndpoint.js +79 -92
- package/dist/api/admin/apiGetAllDecisionMachinesEndpoint.js +43 -45
- package/dist/api/admin/apiGetDecisionMachineEndpoint.js +40 -40
- package/dist/api/admin/apiRegisterSiteKeyEndpoint.js +23 -22
- package/dist/api/admin/apiRegisterSiteKeysEndpoint.js +26 -30
- package/dist/api/admin/apiRemoveAllDecisionMachinesEndpoint.js +35 -37
- package/dist/api/admin/apiRemoveDecisionMachineEndpoint.js +40 -40
- package/dist/api/admin/apiRemoveDetectorKeyEndpoint.d.ts.map +1 -1
- package/dist/api/admin/apiRemoveDetectorKeyEndpoint.js +29 -31
- package/dist/api/admin/apiRemoveSiteKeyEndpoint.js +33 -29
- package/dist/api/admin/apiRemoveSiteKeysEndpoint.js +32 -31
- package/dist/api/admin/apiToggleMaintenanceModeEndpoint.js +43 -35
- package/dist/api/admin/apiUpdateDecisionMachineEndpoint.js +43 -63
- package/dist/api/admin/apiUpdateDetectorKeyEndpoint.js +36 -35
- package/dist/api/admin/createApiAdminRoutesProvider.js +6 -8
- package/dist/api/blacklistRequestInspector.js +285 -377
- package/dist/api/block.js +17 -30
- package/dist/api/captcha/checkSpamEmail.js +88 -98
- package/dist/api/captcha/contextAwareValidation.js +21 -15
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.js +126 -140
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/constants.js +11 -12
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/decisionMachine.js +236 -299
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/decryptSimdReadings.js +10 -13
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/handler.js +336 -462
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/honeypotResponse.js +17 -14
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/sessionDedup.js +27 -27
- package/dist/api/captcha/getFrictionlessCaptchaChallenge/shortCircuit.js +42 -63
- package/dist/api/captcha/getFrictionlessCaptchaChallenge.js +2 -4
- package/dist/api/captcha/getImageCaptchaChallenge.js +136 -207
- package/dist/api/captcha/getPoWCaptchaChallenge.js +128 -198
- package/dist/api/captcha/getPuzzleCaptchaChallenge.js +132 -201
- package/dist/api/captcha/maintenanceModeResponses.js +38 -47
- package/dist/api/captcha/submitImageCaptchaSolution.js +75 -101
- package/dist/api/captcha/submitPoWCaptchaSolution.js +137 -207
- package/dist/api/captcha/submitPuzzleCaptchaSolution.js +73 -105
- package/dist/api/captcha.js +76 -58
- package/dist/api/dnsEventUrl.js +20 -22
- package/dist/api/domainMiddleware.js +104 -115
- package/dist/api/forwardVerify.js +62 -48
- package/dist/api/handshakeTimingMiddleware.js +43 -62
- package/dist/api/hardBlockVerdictCache.js +114 -117
- package/dist/api/headerCheckMiddleware.js +34 -34
- package/dist/api/ignoreMiddleware.js +13 -15
- package/dist/api/ipInfoMiddleware.js +17 -19
- package/dist/api/ja4.js +149 -188
- package/dist/api/ja4Middleware.js +39 -54
- package/dist/api/metrics.js +245 -257
- package/dist/api/public.js +52 -54
- package/dist/api/robotsMiddleware.js +10 -10
- package/dist/api/startProviderApi.js +205 -232
- package/dist/api/testSiteKey.js +16 -16
- package/dist/api/validateAddress.js +23 -21
- package/dist/api/verify.js +334 -377
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/api/admin/apiAdminRoutesProvider.cjs +40 -59
- package/dist/cjs/api/admin/apiClearAllCountersEndpoint.cjs +63 -58
- package/dist/cjs/api/admin/apiDnsEventEndpoint.cjs +82 -93
- package/dist/cjs/api/admin/apiGetAllDecisionMachinesEndpoint.cjs +46 -48
- package/dist/cjs/api/admin/apiGetDecisionMachineEndpoint.cjs +41 -41
- package/dist/cjs/api/admin/apiRegisterSiteKeyEndpoint.cjs +25 -24
- package/dist/cjs/api/admin/apiRegisterSiteKeysEndpoint.cjs +28 -32
- package/dist/cjs/api/admin/apiRemoveAllDecisionMachinesEndpoint.cjs +38 -40
- package/dist/cjs/api/admin/apiRemoveDecisionMachineEndpoint.cjs +41 -41
- package/dist/cjs/api/admin/apiRemoveDetectorKeyEndpoint.cjs +31 -33
- package/dist/cjs/api/admin/apiRemoveSiteKeyEndpoint.cjs +35 -31
- package/dist/cjs/api/admin/apiRemoveSiteKeysEndpoint.cjs +34 -33
- package/dist/cjs/api/admin/apiToggleMaintenanceModeEndpoint.cjs +45 -35
- package/dist/cjs/api/admin/apiUpdateDecisionMachineEndpoint.cjs +45 -65
- package/dist/cjs/api/admin/apiUpdateDetectorKeyEndpoint.cjs +38 -37
- package/dist/cjs/api/admin/createApiAdminRoutesProvider.cjs +7 -8
- package/dist/cjs/api/blacklistRequestInspector.cjs +288 -376
- package/dist/cjs/api/block.cjs +18 -30
- package/dist/cjs/api/captcha/checkSpamEmail.cjs +90 -100
- package/dist/cjs/api/captcha/contextAwareValidation.cjs +21 -14
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/accessPolicy.cjs +125 -140
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/constants.cjs +10 -10
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/decisionMachine.cjs +238 -301
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/decryptSimdReadings.cjs +9 -12
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/handler.cjs +349 -473
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/honeypotResponse.cjs +18 -14
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/sessionDedup.cjs +26 -26
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge/shortCircuit.cjs +42 -63
- package/dist/cjs/api/captcha/getFrictionlessCaptchaChallenge.cjs +2 -3
- package/dist/cjs/api/captcha/getImageCaptchaChallenge.cjs +138 -208
- package/dist/cjs/api/captcha/getPoWCaptchaChallenge.cjs +131 -200
- package/dist/cjs/api/captcha/getPuzzleCaptchaChallenge.cjs +135 -203
- package/dist/cjs/api/captcha/maintenanceModeResponses.cjs +38 -44
- package/dist/cjs/api/captcha/submitImageCaptchaSolution.cjs +77 -102
- package/dist/cjs/api/captcha/submitPoWCaptchaSolution.cjs +140 -209
- package/dist/cjs/api/captcha/submitPuzzleCaptchaSolution.cjs +76 -107
- package/dist/cjs/api/captcha.cjs +79 -58
- package/dist/cjs/api/dnsEventUrl.cjs +20 -21
- package/dist/cjs/api/domainMiddleware.cjs +106 -117
- package/dist/cjs/api/forwardVerify.cjs +63 -49
- package/dist/cjs/api/handshakeTimingMiddleware.cjs +43 -61
- package/dist/cjs/api/hardBlockVerdictCache.cjs +114 -114
- package/dist/cjs/api/headerCheckMiddleware.cjs +34 -34
- package/dist/cjs/api/ignoreMiddleware.cjs +12 -14
- package/dist/cjs/api/ipInfoMiddleware.cjs +16 -18
- package/dist/cjs/api/ja4.cjs +149 -187
- package/dist/cjs/api/ja4Middleware.cjs +40 -53
- package/dist/cjs/api/metrics.cjs +229 -228
- package/dist/cjs/api/public.cjs +57 -57
- package/dist/cjs/api/robotsMiddleware.cjs +9 -9
- package/dist/cjs/api/startProviderApi.cjs +219 -237
- package/dist/cjs/api/testSiteKey.cjs +15 -14
- package/dist/cjs/api/validateAddress.cjs +24 -21
- package/dist/cjs/api/verify.cjs +338 -379
- package/dist/cjs/compositeIpAddress.cjs +40 -47
- package/dist/cjs/index.cjs +65 -71
- package/dist/cjs/pairs.cjs +31 -35
- package/dist/cjs/rules/lang.cjs +10 -14
- package/dist/cjs/schedulers/captchaScheduler.cjs +26 -32
- package/dist/cjs/schedulers/getClientList.cjs +35 -33
- package/dist/cjs/schedulers/setClientEntropy.cjs +35 -33
- package/dist/cjs/schedulers/updateSpamEmailDomains.cjs +39 -43
- package/dist/cjs/services/ipComparison.cjs +122 -119
- package/dist/cjs/tasks/captchaManager.cjs +407 -486
- package/dist/cjs/tasks/client/clientTasks.cjs +347 -470
- package/dist/cjs/tasks/dataset/datasetTasks.cjs +25 -29
- package/dist/cjs/tasks/dataset/datasetTasksUtils.cjs +16 -32
- package/dist/cjs/tasks/decisionMachine/decisionMachineRunner.cjs +220 -307
- package/dist/cjs/tasks/detection/decodeBehavior.cjs +408 -317
- package/dist/cjs/tasks/detection/decodePayload.cjs +686 -468
- package/dist/cjs/tasks/detection/decodeSimd.cjs +462 -304
- package/dist/cjs/tasks/detection/getBotScore.cjs +37 -43
- package/dist/cjs/tasks/dnsEvent/enrichDnsEvent.cjs +88 -71
- package/dist/cjs/tasks/frictionless/frictionlessTasks.cjs +348 -486
- package/dist/cjs/tasks/frictionless/frictionlessTasksUtils.cjs +13 -30
- package/dist/cjs/tasks/frictionless/routingMachine.cjs +71 -55
- package/dist/cjs/tasks/imgCaptcha/imgCaptchaTasks.cjs +555 -806
- package/dist/cjs/tasks/imgCaptcha/imgCaptchaTasksUtils.cjs +22 -23
- package/dist/cjs/tasks/index.cjs +2 -4
- package/dist/cjs/tasks/powCaptcha/powTasks.cjs +491 -687
- package/dist/cjs/tasks/powCaptcha/powTasksUtils.cjs +17 -29
- package/dist/cjs/tasks/puzzleCaptcha/puzzleTasks.cjs +422 -591
- package/dist/cjs/tasks/puzzleCaptcha/puzzleTasksUtils.cjs +8 -5
- package/dist/cjs/tasks/spam/checkSpamEmail.cjs +133 -141
- package/dist/cjs/tasks/spam/checkTrafficFilter.cjs +118 -76
- package/dist/cjs/tasks/spam/evaluateEmailSpamRules.cjs +75 -84
- package/dist/cjs/tasks/spam/updateSpamEmailDomains.cjs +40 -56
- package/dist/cjs/tasks/tasks.cjs +107 -158
- package/dist/cjs/util/usageCounters.cjs +220 -211
- package/dist/cjs/util.cjs +329 -359
- package/dist/cjs/utils/devicePlatform.cjs +14 -8
- package/dist/cjs/utils/dns.cjs +68 -93
- package/dist/cjs/utils/hashUserAgent.cjs +14 -7
- package/dist/cjs/utils/hashUserIp.cjs +14 -6
- package/dist/cjs/utils/honeypot/encoders.cjs +74 -80
- package/dist/cjs/utils/honeypot/phraseBank.cjs +51 -44
- package/dist/cjs/utils/normalizeRequestIp.cjs +33 -25
- package/dist/compositeIpAddress.js +38 -46
- package/dist/index.js +12 -56
- package/dist/pairs.js +31 -37
- package/dist/rules/lang.js +11 -15
- package/dist/schedulers/captchaScheduler.js +25 -31
- package/dist/schedulers/getClientList.js +34 -32
- package/dist/schedulers/setClientEntropy.js +34 -32
- package/dist/schedulers/updateSpamEmailDomains.js +38 -42
- package/dist/services/ipComparison.js +122 -119
- package/dist/tasks/captchaManager.js +403 -483
- package/dist/tasks/client/clientTasks.js +343 -467
- package/dist/tasks/dataset/datasetTasks.js +24 -28
- package/dist/tasks/dataset/datasetTasksUtils.js +15 -31
- package/dist/tasks/decisionMachine/decisionMachineRunner.js +217 -306
- package/dist/tasks/detection/getBotScore.js +37 -43
- package/dist/tasks/dnsEvent/enrichDnsEvent.d.ts.map +1 -1
- package/dist/tasks/dnsEvent/enrichDnsEvent.js +88 -74
- package/dist/tasks/dnsEvent/enrichDnsEvent.js.map +1 -1
- package/dist/tasks/frictionless/frictionlessTasks.js +342 -479
- package/dist/tasks/frictionless/frictionlessTasksUtils.js +14 -32
- package/dist/tasks/frictionless/routingMachine.js +72 -56
- package/dist/tasks/imgCaptcha/imgCaptchaTasks.js +550 -801
- package/dist/tasks/imgCaptcha/imgCaptchaTasksUtils.js +21 -22
- package/dist/tasks/index.js +1 -3
- package/dist/tasks/powCaptcha/powTasks.d.ts.map +1 -1
- package/dist/tasks/powCaptcha/powTasks.js +486 -682
- package/dist/tasks/powCaptcha/powTasks.js.map +1 -1
- package/dist/tasks/powCaptcha/powTasksUtils.js +15 -28
- package/dist/tasks/puzzleCaptcha/puzzleTasks.d.ts.map +1 -1
- package/dist/tasks/puzzleCaptcha/puzzleTasks.js +417 -586
- package/dist/tasks/puzzleCaptcha/puzzleTasks.js.map +1 -1
- package/dist/tasks/puzzleCaptcha/puzzleTasksUtils.js +9 -6
- package/dist/tasks/spam/checkSpamEmail.js +133 -141
- package/dist/tasks/spam/checkTrafficFilter.d.ts +1 -0
- package/dist/tasks/spam/checkTrafficFilter.d.ts.map +1 -1
- package/dist/tasks/spam/checkTrafficFilter.js +117 -77
- package/dist/tasks/spam/checkTrafficFilter.js.map +1 -1
- package/dist/tasks/spam/evaluateEmailSpamRules.js +75 -86
- package/dist/tasks/spam/updateSpamEmailDomains.js +36 -54
- package/dist/tasks/tasks.js +98 -150
- package/dist/tests/integration/api/blacklistRequestInspector.integration.test.js +4 -1
- package/dist/tests/integration/api/blacklistRequestInspector.integration.test.js.map +1 -1
- package/dist/tests/unit/api/block.unit.test.js +8 -4
- package/dist/tests/unit/api/block.unit.test.js.map +1 -1
- package/dist/tests/unit/api/captcha/maintenanceModeShortCircuit.unit.test.js +8 -6
- package/dist/tests/unit/api/captcha/maintenanceModeShortCircuit.unit.test.js.map +1 -1
- package/dist/tests/unit/api/forwardVerify.unit.test.js +3 -1
- package/dist/tests/unit/api/forwardVerify.unit.test.js.map +1 -1
- package/dist/tests/unit/api/getFrictionlessCaptchaChallenge.unit.test.js +15 -7
- package/dist/tests/unit/api/getFrictionlessCaptchaChallenge.unit.test.js.map +1 -1
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.js +24 -18
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.js.map +1 -1
- package/dist/tests/unit/schedulers/getClientList.unit.test.js +19 -13
- package/dist/tests/unit/schedulers/getClientList.unit.test.js.map +1 -1
- package/dist/tests/unit/schedulers/setClientEntropy.unit.test.js +19 -13
- package/dist/tests/unit/schedulers/setClientEntropy.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/client/clientTasks.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.js +22 -16
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.js.map +1 -1
- package/dist/tests/unit/tasks/spam/checkTrafficFilter.unit.test.js +140 -0
- package/dist/tests/unit/tasks/spam/checkTrafficFilter.unit.test.js.map +1 -1
- package/dist/tests/unit/testUtils/mockProviderEnv.d.ts +7 -7
- package/dist/util/usageCounters.js +220 -212
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +327 -364
- package/dist/util.js.map +1 -1
- package/dist/utils/devicePlatform.js +15 -9
- package/dist/utils/dns.js +64 -77
- package/dist/utils/hashUserAgent.js +14 -7
- package/dist/utils/hashUserIp.js +14 -6
- package/dist/utils/honeypot/encoders.js +74 -80
- package/dist/utils/honeypot/phraseBank.js +49 -44
- package/dist/utils/normalizeRequestIp.js +34 -26
- package/package.json +24 -24
|
@@ -1,305 +1,242 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { compareBinaryStrings } from "@prosopo/util";
|
|
4
|
-
import { FrictionlessManager } from "../../../tasks/frictionless/frictionlessTasks.js";
|
|
1
|
+
import { recordFrictionlessDecision } from "../../metrics.js";
|
|
2
|
+
import { FrictionlessManager, FrictionlessReason as FrictionlessReason$1 } from "../../../tasks/frictionless/frictionlessTasks.js";
|
|
5
3
|
import { timestampDecayFunction } from "../../../tasks/frictionless/frictionlessTasksUtils.js";
|
|
6
4
|
import { hashUserAgent } from "../../../utils/hashUserAgent.js";
|
|
7
|
-
import { recordFrictionlessDecision } from "../../metrics.js";
|
|
8
|
-
import { determineContextType, getContextThreshold } from "../contextAwareValidation.js";
|
|
9
|
-
import { getRoundsFromSimScore } from "./constants.js";
|
|
10
5
|
import { attachHoneypot } from "./honeypotResponse.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
captchaType: CaptchaType.image,
|
|
163
|
-
token: input.token
|
|
164
|
-
}
|
|
165
|
-
}));
|
|
166
|
-
recordFrictionlessDecision("missing_current_url");
|
|
167
|
-
attachHoneypot(res, clientRecord);
|
|
168
|
-
return res.json(
|
|
169
|
-
await tasks.frictionlessManager.sendImageCaptcha({
|
|
170
|
-
solvedImagesCount: Math.min(
|
|
171
|
-
env.config.captchas.solved.count,
|
|
172
|
-
clientRecord.settings.imageMaxRounds
|
|
173
|
-
),
|
|
174
|
-
userSitekeyIpHash,
|
|
175
|
-
reason: FrictionlessReason.MISSING_CURRENT_URL,
|
|
176
|
-
siteKey: dapp,
|
|
177
|
-
ipInfo,
|
|
178
|
-
headers: flatHeaders
|
|
179
|
-
})
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
req.logger.info(() => ({
|
|
183
|
-
msg: "Frictionless decision",
|
|
184
|
-
data: {
|
|
185
|
-
decision: "default_pow",
|
|
186
|
-
captchaType: CaptchaType.pow
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
189
|
-
recordFrictionlessDecision("default_pow");
|
|
190
|
-
attachHoneypot(res, clientRecord);
|
|
191
|
-
return res.json(
|
|
192
|
-
await tasks.frictionlessManager.sendPowCaptcha({
|
|
193
|
-
userSitekeyIpHash,
|
|
194
|
-
siteKey: dapp,
|
|
195
|
-
ipInfo,
|
|
196
|
-
headers: flatHeaders
|
|
197
|
-
})
|
|
198
|
-
);
|
|
199
|
-
};
|
|
200
|
-
const runUserAgentMismatchCheck = async (input, handle) => {
|
|
201
|
-
const { req, res } = handle;
|
|
202
|
-
const headersUserAgent = req.headers["user-agent"];
|
|
203
|
-
const headersProsopoUser = req.headers["prosopo-user"];
|
|
204
|
-
const hashedHeadersUserAgent = headersUserAgent ? hashUserAgent(headersUserAgent) : "";
|
|
205
|
-
if (hashedHeadersUserAgent === input.userAgent && headersProsopoUser === input.userId) {
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
req.logger.info(() => ({
|
|
209
|
-
msg: "User agent or user id does not match",
|
|
210
|
-
data: {
|
|
211
|
-
headersUserAgent,
|
|
212
|
-
hashedHeadersUserAgent,
|
|
213
|
-
userAgent: input.userAgent,
|
|
214
|
-
headersProsopoUser,
|
|
215
|
-
userId: input.userId
|
|
216
|
-
}
|
|
217
|
-
}));
|
|
218
|
-
req.logger.info(() => ({
|
|
219
|
-
msg: "Frictionless decision",
|
|
220
|
-
data: {
|
|
221
|
-
decision: "user_agent_mismatch",
|
|
222
|
-
captchaType: CaptchaType.image
|
|
223
|
-
}
|
|
224
|
-
}));
|
|
225
|
-
recordFrictionlessDecision("user_agent_mismatch");
|
|
226
|
-
attachHoneypot(res, input.clientRecord);
|
|
227
|
-
return res.json(
|
|
228
|
-
await input.tasks.frictionlessManager.sendImageCaptcha({
|
|
229
|
-
solvedImagesCount: timestampDecayFunction(
|
|
230
|
-
input.timestamp,
|
|
231
|
-
input.decryptionFailed,
|
|
232
|
-
input.clientRecord.settings.imageMaxRounds
|
|
233
|
-
),
|
|
234
|
-
userSitekeyIpHash: input.userSitekeyIpHash,
|
|
235
|
-
reason: FrictionlessReason.USER_AGENT_MISMATCH,
|
|
236
|
-
siteKey: input.dapp,
|
|
237
|
-
ipInfo: input.ipInfo,
|
|
238
|
-
headers: input.flatHeaders
|
|
239
|
-
})
|
|
240
|
-
);
|
|
6
|
+
import { getRoundsFromSimScore } from "./constants.js";
|
|
7
|
+
import { determineContextType, getContextThreshold } from "../contextAwareValidation.js";
|
|
8
|
+
import { ProsopoApiError } from "@prosopo/common";
|
|
9
|
+
import { CaptchaType, ContextType } from "@prosopo/types";
|
|
10
|
+
import { compareBinaryStrings } from "@prosopo/util";
|
|
11
|
+
//#region src/api/captcha/getFrictionlessCaptchaChallenge/decisionMachine.ts
|
|
12
|
+
var runDecisionMachine = async (input, handle) => {
|
|
13
|
+
const { tasks, env, clientRecord, dapp, userSitekeyIpHash, flatHeaders, ipInfo } = input;
|
|
14
|
+
const { req, res } = handle;
|
|
15
|
+
let { botScore, scoreComponents } = input;
|
|
16
|
+
const userAgentMismatchResponse = await runUserAgentMismatchCheck(input, handle);
|
|
17
|
+
if (userAgentMismatchResponse) return userAgentMismatchResponse;
|
|
18
|
+
const contextResponse = await runContextAwareValidation(input, handle);
|
|
19
|
+
if (contextResponse) return contextResponse;
|
|
20
|
+
const webViewTripped = clientRecord.settings.disallowWebView === true && input.webView === true;
|
|
21
|
+
if (webViewTripped) {
|
|
22
|
+
tasks.logger.info(() => ({ msg: "WebView detected" }));
|
|
23
|
+
const scoreUpdate = tasks.frictionlessManager.scoreIncreaseWebView(input.baseBotScore, botScore, scoreComponents);
|
|
24
|
+
botScore = scoreUpdate.score;
|
|
25
|
+
scoreComponents = scoreUpdate.scoreComponents;
|
|
26
|
+
tasks.frictionlessManager.updateScore(botScore, scoreComponents);
|
|
27
|
+
}
|
|
28
|
+
const timestampTripped = FrictionlessManager.timestampTooOld(input.timestamp);
|
|
29
|
+
if (timestampTripped) {
|
|
30
|
+
const scoreUpdate = tasks.frictionlessManager.scoreIncreaseTimestamp(input.timestamp, input.baseBotScore, botScore, scoreComponents);
|
|
31
|
+
botScore = scoreUpdate.score;
|
|
32
|
+
scoreComponents = scoreUpdate.scoreComponents;
|
|
33
|
+
tasks.frictionlessManager.updateScore(botScore, scoreComponents);
|
|
34
|
+
}
|
|
35
|
+
const autoBanThreshold = clientRecord.settings.autoBanScoreThreshold;
|
|
36
|
+
if (autoBanThreshold !== void 0 && Number(botScore) >= autoBanThreshold) {
|
|
37
|
+
req.logger.info(() => ({
|
|
38
|
+
msg: "Frictionless decision",
|
|
39
|
+
data: {
|
|
40
|
+
decision: "auto_ban_score",
|
|
41
|
+
botScore,
|
|
42
|
+
autoBanThreshold,
|
|
43
|
+
token: input.token
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
recordFrictionlessDecision("auto_ban_score");
|
|
47
|
+
await tasks.frictionlessManager.registerBlockedSession({
|
|
48
|
+
solvedImagesCount: clientRecord.settings.imageMaxRounds,
|
|
49
|
+
userSitekeyIpHash,
|
|
50
|
+
reason: FrictionlessReason$1.AUTO_BAN_SCORE,
|
|
51
|
+
siteKey: dapp,
|
|
52
|
+
ipInfo,
|
|
53
|
+
headers: flatHeaders
|
|
54
|
+
});
|
|
55
|
+
return res.status(401).json({ error: "Unauthorized" });
|
|
56
|
+
}
|
|
57
|
+
if (webViewTripped) {
|
|
58
|
+
req.logger.info(() => ({
|
|
59
|
+
msg: "Frictionless decision",
|
|
60
|
+
data: {
|
|
61
|
+
decision: "webview_detected",
|
|
62
|
+
captchaType: CaptchaType.image
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
recordFrictionlessDecision("webview_detected");
|
|
66
|
+
attachHoneypot(res, clientRecord);
|
|
67
|
+
return res.json(await tasks.frictionlessManager.sendImageCaptcha({
|
|
68
|
+
solvedImagesCount: Math.min(env.config.captchas.solved.count * 2, clientRecord.settings.imageMaxRounds),
|
|
69
|
+
userSitekeyIpHash,
|
|
70
|
+
reason: FrictionlessReason$1.WEBVIEW_DETECTED,
|
|
71
|
+
siteKey: dapp,
|
|
72
|
+
ipInfo,
|
|
73
|
+
headers: flatHeaders
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
if (timestampTripped) {
|
|
77
|
+
req.logger.info(() => ({
|
|
78
|
+
msg: "Frictionless decision",
|
|
79
|
+
data: {
|
|
80
|
+
decision: "timestamp_too_old",
|
|
81
|
+
captchaType: CaptchaType.image
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
recordFrictionlessDecision("timestamp_too_old");
|
|
85
|
+
attachHoneypot(res, clientRecord);
|
|
86
|
+
return res.json(await tasks.frictionlessManager.sendImageCaptcha({
|
|
87
|
+
solvedImagesCount: timestampDecayFunction(input.timestamp, input.decryptionFailed, clientRecord.settings.imageMaxRounds),
|
|
88
|
+
userSitekeyIpHash,
|
|
89
|
+
reason: FrictionlessReason$1.OLD_TIMESTAMP,
|
|
90
|
+
siteKey: dapp,
|
|
91
|
+
ipInfo,
|
|
92
|
+
headers: flatHeaders
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
if (Number(botScore) > input.botThreshold) {
|
|
96
|
+
req.logger.info(() => ({
|
|
97
|
+
msg: "Bot score is greater than threshold",
|
|
98
|
+
data: {
|
|
99
|
+
botScore,
|
|
100
|
+
botThreshold: input.botThreshold,
|
|
101
|
+
token: input.token
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
req.logger.info(() => ({
|
|
105
|
+
msg: "Frictionless decision",
|
|
106
|
+
data: {
|
|
107
|
+
decision: "bot_score_above_threshold",
|
|
108
|
+
captchaType: CaptchaType.image
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
recordFrictionlessDecision("bot_score_above_threshold");
|
|
112
|
+
attachHoneypot(res, clientRecord);
|
|
113
|
+
return res.json(await tasks.frictionlessManager.sendImageCaptcha({
|
|
114
|
+
solvedImagesCount: Math.min(env.config.captchas.solved.count, clientRecord.settings.imageMaxRounds),
|
|
115
|
+
userSitekeyIpHash,
|
|
116
|
+
reason: FrictionlessReason$1.BOT_SCORE_ABOVE_THRESHOLD,
|
|
117
|
+
siteKey: dapp,
|
|
118
|
+
ipInfo,
|
|
119
|
+
headers: flatHeaders
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
if (!input.currentUrl) {
|
|
123
|
+
req.logger.info(() => ({
|
|
124
|
+
msg: "Frictionless decision",
|
|
125
|
+
data: {
|
|
126
|
+
decision: "missing_current_url",
|
|
127
|
+
captchaType: CaptchaType.image,
|
|
128
|
+
token: input.token
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
recordFrictionlessDecision("missing_current_url");
|
|
132
|
+
attachHoneypot(res, clientRecord);
|
|
133
|
+
return res.json(await tasks.frictionlessManager.sendImageCaptcha({
|
|
134
|
+
solvedImagesCount: Math.min(env.config.captchas.solved.count, clientRecord.settings.imageMaxRounds),
|
|
135
|
+
userSitekeyIpHash,
|
|
136
|
+
reason: FrictionlessReason$1.MISSING_CURRENT_URL,
|
|
137
|
+
siteKey: dapp,
|
|
138
|
+
ipInfo,
|
|
139
|
+
headers: flatHeaders
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
req.logger.info(() => ({
|
|
143
|
+
msg: "Frictionless decision",
|
|
144
|
+
data: {
|
|
145
|
+
decision: "default_pow",
|
|
146
|
+
captchaType: CaptchaType.pow
|
|
147
|
+
}
|
|
148
|
+
}));
|
|
149
|
+
recordFrictionlessDecision("default_pow");
|
|
150
|
+
attachHoneypot(res, clientRecord);
|
|
151
|
+
return res.json(await tasks.frictionlessManager.sendPowCaptcha({
|
|
152
|
+
userSitekeyIpHash,
|
|
153
|
+
siteKey: dapp,
|
|
154
|
+
ipInfo,
|
|
155
|
+
headers: flatHeaders
|
|
156
|
+
}));
|
|
241
157
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const threshold = getContextThreshold(clientRecord.settings, contextType);
|
|
276
|
-
const sim = compareBinaryStrings(input.decryptedHeadHash, clientEntropy);
|
|
277
|
-
if (sim >= threshold) return null;
|
|
278
|
-
req.logger.info(() => ({
|
|
279
|
-
msg: "Frictionless decision",
|
|
280
|
-
data: {
|
|
281
|
-
decision: "context_aware_failed",
|
|
282
|
-
captchaType: CaptchaType.image,
|
|
283
|
-
sim,
|
|
284
|
-
threshold
|
|
285
|
-
}
|
|
286
|
-
}));
|
|
287
|
-
recordFrictionlessDecision("context_aware_failed");
|
|
288
|
-
attachHoneypot(res, clientRecord);
|
|
289
|
-
return res.json(
|
|
290
|
-
await tasks.frictionlessManager.sendImageCaptcha({
|
|
291
|
-
solvedImagesCount: Math.min(
|
|
292
|
-
getRoundsFromSimScore(sim),
|
|
293
|
-
clientRecord.settings.imageMaxRounds
|
|
294
|
-
),
|
|
295
|
-
userSitekeyIpHash: input.userSitekeyIpHash,
|
|
296
|
-
reason: FrictionlessReason.CONTEXT_AWARE_VALIDATION_FAILED,
|
|
297
|
-
siteKey: dapp,
|
|
298
|
-
ipInfo: input.ipInfo,
|
|
299
|
-
headers: input.flatHeaders
|
|
300
|
-
})
|
|
301
|
-
);
|
|
158
|
+
var runUserAgentMismatchCheck = async (input, handle) => {
|
|
159
|
+
const { req, res } = handle;
|
|
160
|
+
const headersUserAgent = req.headers["user-agent"];
|
|
161
|
+
const headersProsopoUser = req.headers["prosopo-user"];
|
|
162
|
+
const hashedHeadersUserAgent = headersUserAgent ? hashUserAgent(headersUserAgent) : "";
|
|
163
|
+
if (hashedHeadersUserAgent === input.userAgent && headersProsopoUser === input.userId) return null;
|
|
164
|
+
req.logger.info(() => ({
|
|
165
|
+
msg: "User agent or user id does not match",
|
|
166
|
+
data: {
|
|
167
|
+
headersUserAgent,
|
|
168
|
+
hashedHeadersUserAgent,
|
|
169
|
+
userAgent: input.userAgent,
|
|
170
|
+
headersProsopoUser,
|
|
171
|
+
userId: input.userId
|
|
172
|
+
}
|
|
173
|
+
}));
|
|
174
|
+
req.logger.info(() => ({
|
|
175
|
+
msg: "Frictionless decision",
|
|
176
|
+
data: {
|
|
177
|
+
decision: "user_agent_mismatch",
|
|
178
|
+
captchaType: CaptchaType.image
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
recordFrictionlessDecision("user_agent_mismatch");
|
|
182
|
+
attachHoneypot(res, input.clientRecord);
|
|
183
|
+
return res.json(await input.tasks.frictionlessManager.sendImageCaptcha({
|
|
184
|
+
solvedImagesCount: timestampDecayFunction(input.timestamp, input.decryptionFailed, input.clientRecord.settings.imageMaxRounds),
|
|
185
|
+
userSitekeyIpHash: input.userSitekeyIpHash,
|
|
186
|
+
reason: FrictionlessReason$1.USER_AGENT_MISMATCH,
|
|
187
|
+
siteKey: input.dapp,
|
|
188
|
+
ipInfo: input.ipInfo,
|
|
189
|
+
headers: input.flatHeaders
|
|
190
|
+
}));
|
|
302
191
|
};
|
|
303
|
-
|
|
304
|
-
|
|
192
|
+
var runContextAwareValidation = async (input, handle) => {
|
|
193
|
+
const { tasks, clientRecord, dapp, user } = input;
|
|
194
|
+
const { req, res, next } = handle;
|
|
195
|
+
if (!clientRecord.settings.contextAware?.enabled) return null;
|
|
196
|
+
const contexts = clientRecord.settings.contextAware?.contexts || {};
|
|
197
|
+
const hasDefault = contexts[ContextType.Default] !== void 0;
|
|
198
|
+
const hasWebview = contexts[ContextType.Webview] !== void 0;
|
|
199
|
+
let contextType;
|
|
200
|
+
if (hasDefault && hasWebview) contextType = determineContextType(input.webView);
|
|
201
|
+
else if (hasDefault) contextType = ContextType.Default;
|
|
202
|
+
else if (hasWebview) contextType = ContextType.Webview;
|
|
203
|
+
if (!contextType) return null;
|
|
204
|
+
const clientEntropy = await tasks.frictionlessManager.getClientContextEntropy(clientRecord.account, contextType);
|
|
205
|
+
if (!clientEntropy) return null;
|
|
206
|
+
if (!input.decryptedHeadHash) {
|
|
207
|
+
tasks.logger.info(() => ({ msg: "No decryptedHeadHash in session for context aware client" }));
|
|
208
|
+
return next(new ProsopoApiError("API.BAD_REQUEST", {
|
|
209
|
+
context: {
|
|
210
|
+
code: 400,
|
|
211
|
+
siteKey: dapp,
|
|
212
|
+
user
|
|
213
|
+
},
|
|
214
|
+
i18n: req.i18n,
|
|
215
|
+
logger: req.logger
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
const threshold = getContextThreshold(clientRecord.settings, contextType);
|
|
219
|
+
const sim = compareBinaryStrings(input.decryptedHeadHash, clientEntropy);
|
|
220
|
+
if (sim >= threshold) return null;
|
|
221
|
+
req.logger.info(() => ({
|
|
222
|
+
msg: "Frictionless decision",
|
|
223
|
+
data: {
|
|
224
|
+
decision: "context_aware_failed",
|
|
225
|
+
captchaType: CaptchaType.image,
|
|
226
|
+
sim,
|
|
227
|
+
threshold
|
|
228
|
+
}
|
|
229
|
+
}));
|
|
230
|
+
recordFrictionlessDecision("context_aware_failed");
|
|
231
|
+
attachHoneypot(res, clientRecord);
|
|
232
|
+
return res.json(await tasks.frictionlessManager.sendImageCaptcha({
|
|
233
|
+
solvedImagesCount: Math.min(getRoundsFromSimScore(sim), clientRecord.settings.imageMaxRounds),
|
|
234
|
+
userSitekeyIpHash: input.userSitekeyIpHash,
|
|
235
|
+
reason: FrictionlessReason$1.CONTEXT_AWARE_VALIDATION_FAILED,
|
|
236
|
+
siteKey: dapp,
|
|
237
|
+
ipInfo: input.ipInfo,
|
|
238
|
+
headers: input.flatHeaders
|
|
239
|
+
}));
|
|
305
240
|
};
|
|
241
|
+
//#endregion
|
|
242
|
+
export { runDecisionMachine };
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { timestamp: _ignored, ...readings } = decrypted;
|
|
10
|
-
return readings;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
decryptIncomingSimdReadings
|
|
1
|
+
//#region src/api/captcha/getFrictionlessCaptchaChallenge/decryptSimdReadings.ts
|
|
2
|
+
var decryptIncomingSimdReadings = async (manager, encrypted) => {
|
|
3
|
+
if (!encrypted) return void 0;
|
|
4
|
+
const decryptKeys = [...await manager.getDetectorKeys(), process.env.BOT_DECRYPTION_KEY];
|
|
5
|
+
const decrypted = await manager.decryptSimdReadings(encrypted, decryptKeys);
|
|
6
|
+
if (!decrypted) return void 0;
|
|
7
|
+
const { timestamp: _ignored, ...readings } = decrypted;
|
|
8
|
+
return readings;
|
|
14
9
|
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { decryptIncomingSimdReadings };
|