@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,66 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return parsed;
|
|
1
|
+
let _prosopo_logger = require("@prosopo/logger");
|
|
2
|
+
let _prosopo_api_express_router = require("@prosopo/api-express-router");
|
|
3
|
+
//#region src/api/handshakeTimingMiddleware.ts
|
|
4
|
+
var HEADER_TCP_TO_CHELLO = "x-tls-tcp-to-chello-us";
|
|
5
|
+
var HEADER_CHELLO_TO_HANDSHAKE = "x-tls-chello-to-handshake-us";
|
|
6
|
+
var parseTimingHeader = (raw, logger, headerName) => {
|
|
7
|
+
if (raw === void 0) return;
|
|
8
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
9
|
+
if (value === void 0) return;
|
|
10
|
+
const parsed = Number.parseInt(value, 10);
|
|
11
|
+
if (Number.isNaN(parsed) || parsed < 0) {
|
|
12
|
+
logger.debug(() => ({
|
|
13
|
+
msg: "Ignoring malformed handshake timing header",
|
|
14
|
+
data: {
|
|
15
|
+
header: headerName,
|
|
16
|
+
raw: value
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return parsed;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
HEADER_TCP_TO_CHELLO
|
|
32
|
-
),
|
|
33
|
-
chelloToHandshakeUs: parseTimingHeader(
|
|
34
|
-
headers[HEADER_CHELLO_TO_HANDSHAKE],
|
|
35
|
-
log,
|
|
36
|
-
HEADER_CHELLO_TO_HANDSHAKE
|
|
37
|
-
)
|
|
38
|
-
};
|
|
23
|
+
var getHandshakeTiming = (headers, logger) => {
|
|
24
|
+
const log = logger ?? (0, _prosopo_logger.getLogger)("info", "provider:handshake-timing");
|
|
25
|
+
return {
|
|
26
|
+
tcpToChelloUs: parseTimingHeader(headers[HEADER_TCP_TO_CHELLO], log, HEADER_TCP_TO_CHELLO),
|
|
27
|
+
chelloToHandshakeUs: parseTimingHeader(headers[HEADER_CHELLO_TO_HANDSHAKE], log, HEADER_CHELLO_TO_HANDSHAKE)
|
|
28
|
+
};
|
|
39
29
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
"handshakeTiming"
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
next();
|
|
60
|
-
} catch (err) {
|
|
61
|
-
return apiExpressRouter.handleErrors(err, req, res, next);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
30
|
+
var handshakeTimingMiddleware = (env) => {
|
|
31
|
+
return async (req, res, next) => {
|
|
32
|
+
try {
|
|
33
|
+
const timing = getHandshakeTiming(req.headers, req.logger);
|
|
34
|
+
if (timing.tcpToChelloUs !== void 0) req.tcpToChelloUs = timing.tcpToChelloUs;
|
|
35
|
+
if (timing.chelloToHandshakeUs !== void 0) req.chelloToHandshakeUs = timing.chelloToHandshakeUs;
|
|
36
|
+
if (timing.tcpToChelloUs !== void 0 || timing.chelloToHandshakeUs !== void 0) req.logger = req.logger.with({
|
|
37
|
+
tcpToChelloUs: timing.tcpToChelloUs,
|
|
38
|
+
chelloToHandshakeUs: timing.chelloToHandshakeUs
|
|
39
|
+
}, "handshakeTiming");
|
|
40
|
+
next();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return (0, _prosopo_api_express_router.handleErrors)(err, req, res, next);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
64
45
|
};
|
|
46
|
+
//#endregion
|
|
65
47
|
exports.getHandshakeTiming = getHandshakeTiming;
|
|
66
48
|
exports.handshakeTimingMiddleware = handshakeTimingMiddleware;
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
const hardBlockCacheKey = (clientId, userScope, blockOnly) => {
|
|
99
|
-
const bo = blockOnly ? "1" : "0";
|
|
100
|
-
const parts = [
|
|
101
|
-
clientId ?? "",
|
|
102
|
-
userScope.numericIp === void 0 ? "" : userScope.numericIp.toString(),
|
|
103
|
-
userScope.numericIpMaskMin === void 0 ? "" : userScope.numericIpMaskMin.toString(),
|
|
104
|
-
userScope.numericIpMaskMax === void 0 ? "" : userScope.numericIpMaskMax.toString(),
|
|
105
|
-
userScope.userId ?? "",
|
|
106
|
-
userScope.ja4Hash ?? "",
|
|
107
|
-
userScope.headersHash ?? "",
|
|
108
|
-
userScope.userAgentHash ?? "",
|
|
109
|
-
userScope.headHash ?? "",
|
|
110
|
-
userScope.coords ?? "",
|
|
111
|
-
userScope.countryCode ?? "",
|
|
112
|
-
userScope.asn === void 0 ? "" : String(userScope.asn)
|
|
113
|
-
];
|
|
114
|
-
return `${bo}|${parts.join("|")}`;
|
|
1
|
+
//#region src/api/hardBlockVerdictCache.ts
|
|
2
|
+
var DEFAULT_VERDICT_CACHE_TTL_MS = 1e4;
|
|
3
|
+
var DEFAULT_VERDICT_CACHE_MAX_ENTRIES = 5e4;
|
|
4
|
+
/**
|
|
5
|
+
* Bounded LRU + TTL cache for hard-block verdicts, with singleflight
|
|
6
|
+
* dedupe of concurrent misses.
|
|
7
|
+
*
|
|
8
|
+
* Eviction is real LRU: `get()` moves the hit entry to the tail of the
|
|
9
|
+
* Map's iteration order (Map iteration = insertion order in JS), so
|
|
10
|
+
* `set()` drops the least-recently-used entry once the cap is reached.
|
|
11
|
+
* Absolute TTL is preserved on hit — `expiresAt` is set at insert and
|
|
12
|
+
* never refreshed, so a hot key can't stay stale beyond ttlMs no matter
|
|
13
|
+
* how often it's accessed.
|
|
14
|
+
*
|
|
15
|
+
* `getOrCompute()` is the singleflight entry point: if a concurrent
|
|
16
|
+
* caller is already computing the value for `key`, joiners return the
|
|
17
|
+
* same in-flight Promise instead of racing to the underlying storage.
|
|
18
|
+
* Kills the wave-1 stampede where N identical concurrent requests all
|
|
19
|
+
* miss the cache simultaneously and all hit Redis before the first has
|
|
20
|
+
* populated the entry.
|
|
21
|
+
*/
|
|
22
|
+
var HardBlockVerdictCache = class {
|
|
23
|
+
constructor(ttlMs = DEFAULT_VERDICT_CACHE_TTL_MS, maxEntries = DEFAULT_VERDICT_CACHE_MAX_ENTRIES) {
|
|
24
|
+
this.ttlMs = ttlMs;
|
|
25
|
+
this.maxEntries = maxEntries;
|
|
26
|
+
this.store = /* @__PURE__ */ new Map();
|
|
27
|
+
this.inflight = /* @__PURE__ */ new Map();
|
|
28
|
+
}
|
|
29
|
+
get(key) {
|
|
30
|
+
const entry = this.store.get(key);
|
|
31
|
+
if (entry === void 0) return;
|
|
32
|
+
if (entry.expiresAt <= Date.now()) {
|
|
33
|
+
this.store.delete(key);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.store.delete(key);
|
|
37
|
+
this.store.set(key, entry);
|
|
38
|
+
return entry.value;
|
|
39
|
+
}
|
|
40
|
+
set(key, value) {
|
|
41
|
+
this.store.delete(key);
|
|
42
|
+
if (this.store.size >= this.maxEntries) {
|
|
43
|
+
const oldest = this.store.keys().next().value;
|
|
44
|
+
if (oldest !== void 0) this.store.delete(oldest);
|
|
45
|
+
}
|
|
46
|
+
this.store.set(key, {
|
|
47
|
+
value,
|
|
48
|
+
expiresAt: Date.now() + this.ttlMs
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Cache lookup with singleflight dedupe of concurrent misses.
|
|
53
|
+
*
|
|
54
|
+
* Fast path: cache hit → return immediately (with LRU move-to-tail
|
|
55
|
+
* via `get()`).
|
|
56
|
+
*
|
|
57
|
+
* Slow path: cache miss →
|
|
58
|
+
* 1. If an in-flight Promise exists for this key, join it. This
|
|
59
|
+
* is the coalescing behaviour — N concurrent identical misses
|
|
60
|
+
* all await the same underlying storage call.
|
|
61
|
+
* 2. Otherwise, invoke `compute()`, register the Promise, and
|
|
62
|
+
* populate the cache with the result on resolve. The Promise
|
|
63
|
+
* is removed from the in-flight map in a `finally` so a
|
|
64
|
+
* rejection doesn't wedge future callers.
|
|
65
|
+
*
|
|
66
|
+
* Rejection semantics: if `compute()` throws, all joined waiters
|
|
67
|
+
* see the same rejection. Callers should handle it — the underlying
|
|
68
|
+
* `getPrioritisedAccessRule` catches its own storage errors and
|
|
69
|
+
* returns `[]` (fail-open), so in practice this never propagates.
|
|
70
|
+
*/
|
|
71
|
+
async getOrCompute(key, compute) {
|
|
72
|
+
const cached = this.get(key);
|
|
73
|
+
if (cached !== void 0) return cached;
|
|
74
|
+
const existing = this.inflight.get(key);
|
|
75
|
+
if (existing !== void 0) return existing;
|
|
76
|
+
const promise = (async () => {
|
|
77
|
+
const value = await compute();
|
|
78
|
+
this.set(key, value);
|
|
79
|
+
return value;
|
|
80
|
+
})();
|
|
81
|
+
this.inflight.set(key, promise);
|
|
82
|
+
try {
|
|
83
|
+
return await promise;
|
|
84
|
+
} finally {
|
|
85
|
+
if (this.inflight.get(key) === promise) this.inflight.delete(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
clear() {
|
|
89
|
+
this.store.clear();
|
|
90
|
+
this.inflight.clear();
|
|
91
|
+
}
|
|
92
|
+
size() {
|
|
93
|
+
return this.store.size;
|
|
94
|
+
}
|
|
95
|
+
inflightSize() {
|
|
96
|
+
return this.inflight.size;
|
|
97
|
+
}
|
|
115
98
|
};
|
|
99
|
+
var hardBlockCacheKey = (clientId, userScope, blockOnly) => {
|
|
100
|
+
return `${blockOnly ? "1" : "0"}|${[
|
|
101
|
+
clientId ?? "",
|
|
102
|
+
userScope.numericIp === void 0 ? "" : userScope.numericIp.toString(),
|
|
103
|
+
userScope.numericIpMaskMin === void 0 ? "" : userScope.numericIpMaskMin.toString(),
|
|
104
|
+
userScope.numericIpMaskMax === void 0 ? "" : userScope.numericIpMaskMax.toString(),
|
|
105
|
+
userScope.userId ?? "",
|
|
106
|
+
userScope.ja4Hash ?? "",
|
|
107
|
+
userScope.headersHash ?? "",
|
|
108
|
+
userScope.userAgentHash ?? "",
|
|
109
|
+
userScope.headHash ?? "",
|
|
110
|
+
userScope.coords ?? "",
|
|
111
|
+
userScope.countryCode ?? "",
|
|
112
|
+
userScope.asn === void 0 ? "" : String(userScope.asn)
|
|
113
|
+
].join("|")}`;
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
116
|
exports.DEFAULT_VERDICT_CACHE_MAX_ENTRIES = DEFAULT_VERDICT_CACHE_MAX_ENTRIES;
|
|
117
117
|
exports.DEFAULT_VERDICT_CACHE_TTL_MS = DEFAULT_VERDICT_CACHE_TTL_MS;
|
|
118
118
|
exports.HardBlockVerdictCache = HardBlockVerdictCache;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} catch (err) {
|
|
31
|
-
return apiExpressRouter.handleErrors(err, req, res, next);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
1
|
+
const require_validateAddress = require("./validateAddress.cjs");
|
|
2
|
+
let _prosopo_api_express_router = require("@prosopo/api-express-router");
|
|
3
|
+
//#region src/api/headerCheckMiddleware.ts
|
|
4
|
+
var headerCheckMiddleware = (env) => {
|
|
5
|
+
return async (req, res, next) => {
|
|
6
|
+
try {
|
|
7
|
+
const user = req.headers["prosopo-user"];
|
|
8
|
+
const siteKey = req.headers["prosopo-site-key"];
|
|
9
|
+
if (!user) {
|
|
10
|
+
unauthorised(res);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!siteKey) {
|
|
14
|
+
unauthorised(res);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
require_validateAddress.validateSiteKey(siteKey, req.logger);
|
|
18
|
+
require_validateAddress.validateAddr(user, void 0, req.logger);
|
|
19
|
+
req.user = user;
|
|
20
|
+
req.siteKey = siteKey;
|
|
21
|
+
req.logger = req.logger.with({
|
|
22
|
+
user,
|
|
23
|
+
siteKey
|
|
24
|
+
}, "header-check");
|
|
25
|
+
next();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return (0, _prosopo_api_express_router.handleErrors)(err, req, res, next);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
34
30
|
};
|
|
35
|
-
|
|
31
|
+
var unauthorised = (res) => res.status(401).json({
|
|
32
|
+
error: "Unauthorized",
|
|
33
|
+
message: "Unauthorized"
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
36
|
exports.headerCheckMiddleware = headerCheckMiddleware;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const types = require("@prosopo/types");
|
|
1
|
+
let _prosopo_types = require("@prosopo/types");
|
|
2
|
+
//#region src/api/ignoreMiddleware.ts
|
|
4
3
|
function ignoreMiddleware() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
next();
|
|
15
|
-
};
|
|
4
|
+
return (req, res, next) => {
|
|
5
|
+
if (req.originalUrl.indexOf(_prosopo_types.PublicApiPaths.Healthz) !== -1) return next();
|
|
6
|
+
if (req.originalUrl.indexOf(_prosopo_types.ApiPrefix) === -1) {
|
|
7
|
+
res.statusCode = 404;
|
|
8
|
+
res.send("Not Found");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
16
13
|
}
|
|
14
|
+
//#endregion
|
|
17
15
|
exports.ignoreMiddleware = ignoreMiddleware;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
next();
|
|
17
|
-
}
|
|
18
|
-
};
|
|
1
|
+
//#region src/api/ipInfoMiddleware.ts
|
|
2
|
+
var ipInfoMiddleware = (env) => {
|
|
3
|
+
return async (req, _res, next) => {
|
|
4
|
+
try {
|
|
5
|
+
const ip = req.ip;
|
|
6
|
+
if (ip && env.ipInfoService.isAvailable()) req.ipInfo = await env.ipInfoService.lookup(ip);
|
|
7
|
+
next();
|
|
8
|
+
} catch (err) {
|
|
9
|
+
req.logger?.warn?.(() => ({
|
|
10
|
+
msg: "IP info middleware failed",
|
|
11
|
+
err
|
|
12
|
+
}));
|
|
13
|
+
next();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
19
16
|
};
|
|
17
|
+
//#endregion
|
|
20
18
|
exports.ipInfoMiddleware = ipInfoMiddleware;
|