perimeterx-js-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -0
- package/lib/activities/ActivityType.d.ts +6 -0
- package/lib/activities/ActivityType.js +10 -0
- package/lib/activities/HttpActivityClient.d.ts +12 -0
- package/lib/activities/HttpActivityClient.js +107 -0
- package/lib/activities/IActivityClient.d.ts +8 -0
- package/lib/activities/IActivityClient.js +2 -0
- package/lib/activities/constants.d.ts +1 -0
- package/lib/activities/constants.js +4 -0
- package/lib/activities/index.d.ts +5 -0
- package/lib/activities/index.js +7 -0
- package/lib/activities/model/Activity.d.ts +13 -0
- package/lib/activities/model/Activity.js +2 -0
- package/lib/activities/model/ActivityDetails.d.ts +41 -0
- package/lib/activities/model/ActivityDetails.js +2 -0
- package/lib/activities/utils.d.ts +10 -0
- package/lib/activities/utils.js +88 -0
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +3 -0
- package/lib/additional_activity_handler/AdditionalActivityHandler.js +2 -0
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +5 -0
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +64 -0
- package/lib/additional_activity_handler/index.d.ts +2 -0
- package/lib/additional_activity_handler/index.js +5 -0
- package/lib/block_handler/BlockAction.d.ts +6 -0
- package/lib/block_handler/BlockAction.js +21 -0
- package/lib/block_handler/BlockReason.d.ts +4 -0
- package/lib/block_handler/BlockReason.js +8 -0
- package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +14 -0
- package/lib/block_handler/DefaultBlockResponseGenerator.js +44 -0
- package/lib/block_handler/IBlockResponseGenerator.d.ts +14 -0
- package/lib/block_handler/IBlockResponseGenerator.js +2 -0
- package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.d.ts +14 -0
- package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.js +30 -0
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +10 -0
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +25 -0
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +10 -0
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +44 -0
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.d.ts +12 -0
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.js +36 -0
- package/lib/block_handler/index.d.ts +13 -0
- package/lib/block_handler/index.js +21 -0
- package/lib/block_handler/model/BlockData.d.ts +16 -0
- package/lib/block_handler/model/BlockData.js +2 -0
- package/lib/block_handler/model/JsonBlockPayload.d.ts +11 -0
- package/lib/block_handler/model/JsonBlockPayload.js +2 -0
- package/lib/block_handler/model/MobileBlockPayload.d.ts +8 -0
- package/lib/block_handler/model/MobileBlockPayload.js +2 -0
- package/lib/block_handler/templates/captcha_template.d.ts +1 -0
- package/lib/block_handler/templates/captcha_template.js +4 -0
- package/lib/block_handler/templates/rate_limit_template.d.ts +1 -0
- package/lib/block_handler/templates/rate_limit_template.js +4 -0
- package/lib/block_handler/utils.d.ts +5 -0
- package/lib/block_handler/utils.js +48 -0
- package/lib/config/ConfigurationParams.d.ts +65 -0
- package/lib/config/ConfigurationParams.js +2 -0
- package/lib/config/DefaultConfigurations.d.ts +2 -0
- package/lib/config/DefaultConfigurations.js +107 -0
- package/lib/config/IConfiguration.d.ts +172 -0
- package/lib/config/IConfiguration.js +2 -0
- package/lib/config/StaticConfigurationBase.d.ts +57 -0
- package/lib/config/StaticConfigurationBase.js +355 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +7 -0
- package/lib/context/ContextBase.d.ts +55 -0
- package/lib/context/ContextBase.js +206 -0
- package/lib/context/DefaultTokenV2Context.d.ts +13 -0
- package/lib/context/DefaultTokenV2Context.js +35 -0
- package/lib/context/DefaultTokenV3Context.d.ts +13 -0
- package/lib/context/DefaultTokenV3Context.js +35 -0
- package/lib/context/IContext.d.ts +256 -0
- package/lib/context/IContext.js +2 -0
- package/lib/context/index.d.ts +4 -0
- package/lib/context/index.js +9 -0
- package/lib/custom_parameters/CustomParameters.d.ts +12 -0
- package/lib/custom_parameters/CustomParameters.js +2 -0
- package/lib/custom_parameters/CustomParametersFunction.d.ts +4 -0
- package/lib/custom_parameters/CustomParametersFunction.js +2 -0
- package/lib/custom_parameters/CustomParametersUtils.d.ts +4 -0
- package/lib/custom_parameters/CustomParametersUtils.js +19 -0
- package/lib/custom_parameters/index.d.ts +3 -0
- package/lib/custom_parameters/index.js +5 -0
- package/lib/enforcer/EnforcerBase.d.ts +139 -0
- package/lib/enforcer/EnforcerBase.js +376 -0
- package/lib/enforcer/IEnforcer.d.ts +4 -0
- package/lib/enforcer/IEnforcer.js +2 -0
- package/lib/enforcer/index.d.ts +2 -0
- package/lib/enforcer/index.js +5 -0
- package/lib/filter/DefaultFilter.d.ts +16 -0
- package/lib/filter/DefaultFilter.js +59 -0
- package/lib/filter/FilterReason.d.ts +8 -0
- package/lib/filter/FilterReason.js +12 -0
- package/lib/filter/IFilter.d.ts +8 -0
- package/lib/filter/IFilter.js +2 -0
- package/lib/filter/index.d.ts +3 -0
- package/lib/filter/index.js +7 -0
- package/lib/first_party/DefaultFirstParty.d.ts +22 -0
- package/lib/first_party/DefaultFirstParty.js +215 -0
- package/lib/first_party/IFirstParty.d.ts +9 -0
- package/lib/first_party/IFirstParty.js +2 -0
- package/lib/first_party/constants.d.ts +32 -0
- package/lib/first_party/constants.js +39 -0
- package/lib/first_party/index.d.ts +4 -0
- package/lib/first_party/index.js +21 -0
- package/lib/first_party/utils.d.ts +8 -0
- package/lib/first_party/utils.js +27 -0
- package/lib/http/IHttpClient.d.ts +10 -0
- package/lib/http/IHttpClient.js +2 -0
- package/lib/http/body_reader/IBodyReader.d.ts +5 -0
- package/lib/http/body_reader/IBodyReader.js +2 -0
- package/lib/http/body_reader/StringBodyReader.d.ts +8 -0
- package/lib/http/body_reader/StringBodyReader.js +70 -0
- package/lib/http/index.d.ts +10 -0
- package/lib/http/index.js +28 -0
- package/lib/http/request/DefaultHttpRequest.d.ts +5 -0
- package/lib/http/request/DefaultHttpRequest.js +42 -0
- package/lib/http/request/HttpRequestBase.d.ts +24 -0
- package/lib/http/request/HttpRequestBase.js +77 -0
- package/lib/http/request/IHttpRequest.d.ts +31 -0
- package/lib/http/request/IHttpRequest.js +2 -0
- package/lib/http/response/DefaultHttpResponse.d.ts +5 -0
- package/lib/http/response/DefaultHttpResponse.js +32 -0
- package/lib/http/response/HttpResponseBase.d.ts +17 -0
- package/lib/http/response/HttpResponseBase.js +75 -0
- package/lib/http/response/IHttpResponse.d.ts +26 -0
- package/lib/http/response/IHttpResponse.js +2 -0
- package/lib/http/utils/ContentType.d.ts +9 -0
- package/lib/http/utils/ContentType.js +13 -0
- package/lib/http/utils/HttpBody.d.ts +4 -0
- package/lib/http/utils/HttpBody.js +2 -0
- package/lib/http/utils/HttpHeaders.d.ts +51 -0
- package/lib/http/utils/HttpHeaders.js +106 -0
- package/lib/http/utils/HttpMethod.d.ts +11 -0
- package/lib/http/utils/HttpMethod.js +15 -0
- package/lib/http/utils/constants.d.ts +9 -0
- package/lib/http/utils/constants.js +12 -0
- package/lib/http/utils/index.d.ts +5 -0
- package/lib/http/utils/index.js +24 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +33 -0
- package/lib/logger/DefaultLogger.d.ts +7 -0
- package/lib/logger/DefaultLogger.js +31 -0
- package/lib/logger/ILogger.d.ts +24 -0
- package/lib/logger/ILogger.js +2 -0
- package/lib/logger/LoggerBase.d.ts +11 -0
- package/lib/logger/LoggerBase.js +28 -0
- package/lib/logger/LoggerSeverity.d.ts +5 -0
- package/lib/logger/LoggerSeverity.js +9 -0
- package/lib/logger/index.d.ts +4 -0
- package/lib/logger/index.js +9 -0
- package/lib/pxde/DefaultDataEnrichment.d.ts +14 -0
- package/lib/pxde/DefaultDataEnrichment.js +133 -0
- package/lib/pxde/IDataEnrichment.d.ts +9 -0
- package/lib/pxde/IDataEnrichment.js +2 -0
- package/lib/pxde/constants.d.ts +4 -0
- package/lib/pxde/constants.js +7 -0
- package/lib/pxde/index.d.ts +4 -0
- package/lib/pxde/index.js +20 -0
- package/lib/pxde/model/PXDE.d.ts +9 -0
- package/lib/pxde/model/PXDE.js +2 -0
- package/lib/pxhd/PXHDUtils.d.ts +8 -0
- package/lib/pxhd/PXHDUtils.js +20 -0
- package/lib/pxhd/index.d.ts +1 -0
- package/lib/pxhd/index.js +5 -0
- package/lib/risk_api/PostRiskApiClient.d.ts +27 -0
- package/lib/risk_api/PostRiskApiClient.js +232 -0
- package/lib/risk_api/S2SCallReason.d.ts +12 -0
- package/lib/risk_api/S2SCallReason.js +16 -0
- package/lib/risk_api/S2SErrorHandler.d.ts +9 -0
- package/lib/risk_api/S2SErrorHandler.js +121 -0
- package/lib/risk_api/S2SErrorReason.d.ts +8 -0
- package/lib/risk_api/S2SErrorReason.js +12 -0
- package/lib/risk_api/constants.d.ts +1 -0
- package/lib/risk_api/constants.js +4 -0
- package/lib/risk_api/index.d.ts +13 -0
- package/lib/risk_api/index.js +34 -0
- package/lib/risk_api/model/RiskActivity.d.ts +50 -0
- package/lib/risk_api/model/RiskActivity.js +2 -0
- package/lib/risk_api/model/RiskResponseV2.d.ts +10 -0
- package/lib/risk_api/model/RiskResponseV2.js +2 -0
- package/lib/risk_api/model/RiskResponseV3.d.ts +12 -0
- package/lib/risk_api/model/RiskResponseV3.js +2 -0
- package/lib/risk_api/model/RiskStatus.d.ts +4 -0
- package/lib/risk_api/model/RiskStatus.js +8 -0
- package/lib/risk_api/risk_response_handler/IRiskResponseHandler.d.ts +5 -0
- package/lib/risk_api/risk_response_handler/IRiskResponseHandler.js +2 -0
- package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.d.ts +16 -0
- package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.js +73 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.d.ts +10 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +46 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.d.ts +10 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.js +47 -0
- package/lib/risk_token/MobileError.d.ts +6 -0
- package/lib/risk_token/MobileError.js +10 -0
- package/lib/risk_token/MobileErrorHandler.d.ts +9 -0
- package/lib/risk_token/MobileErrorHandler.js +100 -0
- package/lib/risk_token/RiskTokenScoreRetriever.d.ts +14 -0
- package/lib/risk_token/RiskTokenScoreRetriever.js +148 -0
- package/lib/risk_token/TokenOrigin.d.ts +4 -0
- package/lib/risk_token/TokenOrigin.js +8 -0
- package/lib/risk_token/TokenVerificationResult.d.ts +6 -0
- package/lib/risk_token/TokenVerificationResult.js +10 -0
- package/lib/risk_token/TokenVersion.d.ts +4 -0
- package/lib/risk_token/TokenVersion.js +8 -0
- package/lib/risk_token/constants.d.ts +9 -0
- package/lib/risk_token/constants.js +12 -0
- package/lib/risk_token/index.d.ts +9 -0
- package/lib/risk_token/index.js +32 -0
- package/lib/risk_token/token/BotDefenderTokenBase.d.ts +27 -0
- package/lib/risk_token/token/BotDefenderTokenBase.js +94 -0
- package/lib/risk_token/token/IBotDefenderToken.d.ts +54 -0
- package/lib/risk_token/token/IBotDefenderToken.js +2 -0
- package/lib/risk_token/token/index.d.ts +7 -0
- package/lib/risk_token/token/index.js +11 -0
- package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.d.ts +6 -0
- package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.js +2 -0
- package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.d.ts +28 -0
- package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.js +199 -0
- package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.d.ts +9 -0
- package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.js +2 -0
- package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.d.ts +31 -0
- package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.js +231 -0
- package/lib/risk_token/token/v3/TokenSignField.d.ts +4 -0
- package/lib/risk_token/token/v3/TokenSignField.js +8 -0
- package/lib/risk_token/utils.d.ts +2 -0
- package/lib/risk_token/utils.js +16 -0
- package/lib/telemetry/DefaultTelemetry.d.ts +19 -0
- package/lib/telemetry/DefaultTelemetry.js +176 -0
- package/lib/telemetry/ITelemetry.d.ts +13 -0
- package/lib/telemetry/ITelemetry.js +2 -0
- package/lib/telemetry/constants.d.ts +7 -0
- package/lib/telemetry/constants.js +10 -0
- package/lib/telemetry/index.d.ts +4 -0
- package/lib/telemetry/index.js +20 -0
- package/lib/telemetry/model/TelemetryActivity.d.ts +15 -0
- package/lib/telemetry/model/TelemetryActivity.js +2 -0
- package/lib/utils/Algorithm.d.ts +4 -0
- package/lib/utils/Algorithm.js +8 -0
- package/lib/utils/EnforcerException.d.ts +3 -0
- package/lib/utils/EnforcerException.js +26 -0
- package/lib/utils/IScoreRetriever.d.ts +14 -0
- package/lib/utils/IScoreRetriever.js +2 -0
- package/lib/utils/ModuleMode.d.ts +4 -0
- package/lib/utils/ModuleMode.js +8 -0
- package/lib/utils/PassReason.d.ts +6 -0
- package/lib/utils/PassReason.js +10 -0
- package/lib/utils/VidSource.d.ts +4 -0
- package/lib/utils/VidSource.js +8 -0
- package/lib/utils/base64/DefaultBase64Utils.d.ts +5 -0
- package/lib/utils/base64/DefaultBase64Utils.js +16 -0
- package/lib/utils/base64/IBase64Utils.d.ts +4 -0
- package/lib/utils/base64/IBase64Utils.js +2 -0
- package/lib/utils/base64/index.d.ts +2 -0
- package/lib/utils/base64/index.js +5 -0
- package/lib/utils/cipher/ICipherUtils.d.ts +7 -0
- package/lib/utils/cipher/ICipherUtils.js +2 -0
- package/lib/utils/cipher/index.d.ts +1 -0
- package/lib/utils/cipher/index.js +2 -0
- package/lib/utils/constants.d.ts +10 -0
- package/lib/utils/constants.js +13 -0
- package/lib/utils/cookie_parser/DefaultCookieParser.d.ts +4 -0
- package/lib/utils/cookie_parser/DefaultCookieParser.js +13 -0
- package/lib/utils/cookie_parser/ICookieParser.d.ts +3 -0
- package/lib/utils/cookie_parser/ICookieParser.js +2 -0
- package/lib/utils/cookie_parser/index.d.ts +2 -0
- package/lib/utils/cookie_parser/index.js +5 -0
- package/lib/utils/hash/DefaultHashUtils.d.ts +5 -0
- package/lib/utils/hash/DefaultHashUtils.js +19 -0
- package/lib/utils/hash/IHashUtils.d.ts +4 -0
- package/lib/utils/hash/IHashUtils.js +2 -0
- package/lib/utils/hash/index.d.ts +2 -0
- package/lib/utils/hash/index.js +5 -0
- package/lib/utils/index.d.ts +14 -0
- package/lib/utils/index.js +35 -0
- package/lib/utils/ip_range_checker/DefaultIpRangeChecker.d.ts +4 -0
- package/lib/utils/ip_range_checker/DefaultIpRangeChecker.js +13 -0
- package/lib/utils/ip_range_checker/IIpRangeChecker.d.ts +3 -0
- package/lib/utils/ip_range_checker/IIpRangeChecker.js +2 -0
- package/lib/utils/ip_range_checker/index.d.ts +2 -0
- package/lib/utils/ip_range_checker/index.js +5 -0
- package/lib/utils/utils.d.ts +13 -0
- package/lib/utils/utils.js +91 -0
- package/lib/utils/uuid_generator/DefaultUuidGenerator.d.ts +4 -0
- package/lib/utils/uuid_generator/DefaultUuidGenerator.js +13 -0
- package/lib/utils/uuid_generator/IUuidGenerator.d.ts +3 -0
- package/lib/utils/uuid_generator/IUuidGenerator.js +2 -0
- package/lib/utils/uuid_generator/index.d.ts +2 -0
- package/lib/utils/uuid_generator/index.js +5 -0
- package/package.json +52 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RiskResponseHandlerBase = void 0;
|
|
40
|
+
var block_handler_1 = require("../../block_handler");
|
|
41
|
+
var utils_1 = require("../../utils");
|
|
42
|
+
var RiskResponseHandlerBase = /** @class */ (function () {
|
|
43
|
+
function RiskResponseHandlerBase(config) {
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
RiskResponseHandlerBase.prototype.handleRiskResponse = function (context, response, riskResponse) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
if (!this.isRiskResponseValid(riskResponse)) {
|
|
50
|
+
throw new utils_1.EnforcerException('invalid risk response');
|
|
51
|
+
}
|
|
52
|
+
this.config.logger.debug("received risk response, rtt: ".concat(context.riskApiData.riskRtt));
|
|
53
|
+
this.handleValidRiskResponse(context, riskResponse);
|
|
54
|
+
return [2 /*return*/];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
RiskResponseHandlerBase.prototype.handleValidRiskResponse = function (context, riskResponse) {
|
|
59
|
+
var score = this.extractScoreFromRiskResponse(riskResponse);
|
|
60
|
+
this.setRiskResponseContextFields(context, riskResponse);
|
|
61
|
+
if (this.shouldBlock(score)) {
|
|
62
|
+
context.blockReason = block_handler_1.BlockReason.S2S_HIGH_SCORE;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
context.passReason = utils_1.PassReason.S2S;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
RiskResponseHandlerBase.prototype.shouldBlock = function (score) {
|
|
69
|
+
return score >= this.config.blockingScore;
|
|
70
|
+
};
|
|
71
|
+
return RiskResponseHandlerBase;
|
|
72
|
+
}());
|
|
73
|
+
exports.RiskResponseHandlerBase = RiskResponseHandlerBase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IConfiguration } from '../../config';
|
|
2
|
+
import { IContext } from '../../context';
|
|
3
|
+
import { RiskResponseHandlerBase } from './RiskResponseHandlerBase';
|
|
4
|
+
import { RiskResponseV2 } from '../model/RiskResponseV2';
|
|
5
|
+
export declare class RiskResponseV2Handler extends RiskResponseHandlerBase<RiskResponseV2> {
|
|
6
|
+
constructor(config: IConfiguration);
|
|
7
|
+
protected isRiskResponseValid(riskResponse: RiskResponseV2): boolean;
|
|
8
|
+
protected extractScoreFromRiskResponse(riskResponse: RiskResponseV2): number;
|
|
9
|
+
protected setRiskResponseContextFields(context: IContext, riskResponse: RiskResponseV2): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.RiskResponseV2Handler = void 0;
|
|
19
|
+
var utils_1 = require("../../utils");
|
|
20
|
+
var RiskStatus_1 = require("../model/RiskStatus");
|
|
21
|
+
var RiskResponseHandlerBase_1 = require("./RiskResponseHandlerBase");
|
|
22
|
+
var RiskResponseV2Handler = /** @class */ (function (_super) {
|
|
23
|
+
__extends(RiskResponseV2Handler, _super);
|
|
24
|
+
function RiskResponseV2Handler(config) {
|
|
25
|
+
return _super.call(this, config) || this;
|
|
26
|
+
}
|
|
27
|
+
RiskResponseV2Handler.prototype.isRiskResponseValid = function (riskResponse) {
|
|
28
|
+
return (riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.status) === RiskStatus_1.RiskStatus.SUCCESS && !!(riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.cookie_cfg_block_result);
|
|
29
|
+
};
|
|
30
|
+
RiskResponseV2Handler.prototype.extractScoreFromRiskResponse = function (riskResponse) {
|
|
31
|
+
return riskResponse.cookie_cfg_block_result === '1' ? 100 : 0;
|
|
32
|
+
};
|
|
33
|
+
RiskResponseV2Handler.prototype.setRiskResponseContextFields = function (context, riskResponse) {
|
|
34
|
+
context.score = this.extractScoreFromRiskResponse(riskResponse);
|
|
35
|
+
(0, utils_1.transferExistingProperties)(riskResponse, context, {
|
|
36
|
+
uuid: 'uuid',
|
|
37
|
+
pxhd: 'pxhd',
|
|
38
|
+
data_enrichment: 'pxde',
|
|
39
|
+
});
|
|
40
|
+
if (riskResponse.data_enrichment) {
|
|
41
|
+
context.pxdeVerified = true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return RiskResponseV2Handler;
|
|
45
|
+
}(RiskResponseHandlerBase_1.RiskResponseHandlerBase));
|
|
46
|
+
exports.RiskResponseV2Handler = RiskResponseV2Handler;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IConfiguration } from '../../config';
|
|
2
|
+
import { IContext } from '../../context';
|
|
3
|
+
import { RiskResponseHandlerBase } from './RiskResponseHandlerBase';
|
|
4
|
+
import { RiskResponseV3 } from '../model/RiskResponseV3';
|
|
5
|
+
export declare class RiskResponseV3Handler extends RiskResponseHandlerBase<RiskResponseV3> {
|
|
6
|
+
constructor(config: IConfiguration);
|
|
7
|
+
protected isRiskResponseValid(riskResponse: RiskResponseV3): boolean;
|
|
8
|
+
protected extractScoreFromRiskResponse(riskResponse: RiskResponseV3): number;
|
|
9
|
+
protected setRiskResponseContextFields(context: IContext, riskResponse: RiskResponseV3): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.RiskResponseV3Handler = void 0;
|
|
19
|
+
var utils_1 = require("../../utils");
|
|
20
|
+
var RiskStatus_1 = require("../model/RiskStatus");
|
|
21
|
+
var RiskResponseHandlerBase_1 = require("./RiskResponseHandlerBase");
|
|
22
|
+
var RiskResponseV3Handler = /** @class */ (function (_super) {
|
|
23
|
+
__extends(RiskResponseV3Handler, _super);
|
|
24
|
+
function RiskResponseV3Handler(config) {
|
|
25
|
+
return _super.call(this, config) || this;
|
|
26
|
+
}
|
|
27
|
+
RiskResponseV3Handler.prototype.isRiskResponseValid = function (riskResponse) {
|
|
28
|
+
return (riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.status) === RiskStatus_1.RiskStatus.SUCCESS && typeof (riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.score) === 'number';
|
|
29
|
+
};
|
|
30
|
+
RiskResponseV3Handler.prototype.extractScoreFromRiskResponse = function (riskResponse) {
|
|
31
|
+
return riskResponse.score;
|
|
32
|
+
};
|
|
33
|
+
RiskResponseV3Handler.prototype.setRiskResponseContextFields = function (context, riskResponse) {
|
|
34
|
+
(0, utils_1.transferExistingProperties)(riskResponse, context, {
|
|
35
|
+
score: 'score',
|
|
36
|
+
uuid: 'uuid',
|
|
37
|
+
action: 'blockAction',
|
|
38
|
+
pxhd: 'pxhd',
|
|
39
|
+
data_enrichment: 'pxde',
|
|
40
|
+
});
|
|
41
|
+
if (riskResponse.data_enrichment) {
|
|
42
|
+
context.pxdeVerified = true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return RiskResponseV3Handler;
|
|
46
|
+
}(RiskResponseHandlerBase_1.RiskResponseHandlerBase));
|
|
47
|
+
exports.RiskResponseV3Handler = RiskResponseV3Handler;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobileError = void 0;
|
|
4
|
+
var MobileError;
|
|
5
|
+
(function (MobileError) {
|
|
6
|
+
MobileError["NO_COOKIE"] = "1";
|
|
7
|
+
MobileError["CONNECTION_ERROR"] = "2";
|
|
8
|
+
MobileError["CERTIFICATE_PINNING_ERROR"] = "3";
|
|
9
|
+
MobileError["BYPASS"] = "4";
|
|
10
|
+
})(MobileError = exports.MobileError || (exports.MobileError = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IConfiguration } from '../config';
|
|
2
|
+
import { IContext } from '../context';
|
|
3
|
+
export declare class MobileErrorHandler {
|
|
4
|
+
private readonly config;
|
|
5
|
+
constructor(config: IConfiguration);
|
|
6
|
+
handleMobileError(context: IContext): Promise<void>;
|
|
7
|
+
private getS2SCallReasonFromMobileError;
|
|
8
|
+
private handleFailure;
|
|
9
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.MobileErrorHandler = void 0;
|
|
40
|
+
var risk_api_1 = require("../risk_api");
|
|
41
|
+
var MobileError_1 = require("./MobileError");
|
|
42
|
+
var TokenVerificationResult_1 = require("./TokenVerificationResult");
|
|
43
|
+
var MobileErrorHandler = /** @class */ (function () {
|
|
44
|
+
function MobileErrorHandler(config) {
|
|
45
|
+
this.config = config;
|
|
46
|
+
}
|
|
47
|
+
MobileErrorHandler.prototype.handleMobileError = function (context) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var _a, originalToken, mobileError, result, e_1;
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
_b.trys.push([0, 3, , 4]);
|
|
54
|
+
_a = context.mobileData, originalToken = _a.originalToken, mobileError = _a.mobileError;
|
|
55
|
+
context.riskApiData.s2sCallReason = this.getS2SCallReasonFromMobileError(mobileError);
|
|
56
|
+
if (!originalToken) return [3 /*break*/, 2];
|
|
57
|
+
return [4 /*yield*/, originalToken.verify(context)];
|
|
58
|
+
case 1:
|
|
59
|
+
result = _b.sent();
|
|
60
|
+
if (result === TokenVerificationResult_1.TokenVerificationResult.DECRYPTION_FAILED) {
|
|
61
|
+
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_DECRYPTION_FAILED)];
|
|
62
|
+
}
|
|
63
|
+
context.mobileData.decodedOriginalToken = originalToken.getPayloadString();
|
|
64
|
+
context.uuid = originalToken.uuid;
|
|
65
|
+
context.vid = originalToken.vid;
|
|
66
|
+
if (result === TokenVerificationResult_1.TokenVerificationResult.VALIDATION_FAILED) {
|
|
67
|
+
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_VALIDATION_FAILED)];
|
|
68
|
+
}
|
|
69
|
+
_b.label = 2;
|
|
70
|
+
case 2: return [3 /*break*/, 4];
|
|
71
|
+
case 3:
|
|
72
|
+
e_1 = _b.sent();
|
|
73
|
+
this.config.logger.debug("caught exception in mobile error handler - ".concat(e_1));
|
|
74
|
+
return [3 /*break*/, 4];
|
|
75
|
+
case 4: return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
MobileErrorHandler.prototype.getS2SCallReasonFromMobileError = function (mobileError) {
|
|
81
|
+
switch (mobileError) {
|
|
82
|
+
case MobileError_1.MobileError.NO_COOKIE:
|
|
83
|
+
return risk_api_1.S2SCallReason.MOBILE_ERROR_NO_COOKIE;
|
|
84
|
+
case MobileError_1.MobileError.CONNECTION_ERROR:
|
|
85
|
+
return risk_api_1.S2SCallReason.MOBILE_ERROR_CONNECTION_ERROR;
|
|
86
|
+
case MobileError_1.MobileError.CERTIFICATE_PINNING_ERROR:
|
|
87
|
+
return risk_api_1.S2SCallReason.MOBILE_ERROR_CERTIFICATE_PINNING_ERROR;
|
|
88
|
+
case MobileError_1.MobileError.BYPASS:
|
|
89
|
+
return risk_api_1.S2SCallReason.MOBILE_ERROR_BYPASS;
|
|
90
|
+
default:
|
|
91
|
+
return "mobile_error_".concat(mobileError);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
MobileErrorHandler.prototype.handleFailure = function (context, s2sCallReason) {
|
|
95
|
+
this.config.logger.debug("could not retrieve original token info - ".concat(s2sCallReason));
|
|
96
|
+
context.mobileData.originalTokenError = s2sCallReason;
|
|
97
|
+
};
|
|
98
|
+
return MobileErrorHandler;
|
|
99
|
+
}());
|
|
100
|
+
exports.MobileErrorHandler = MobileErrorHandler;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IConfiguration } from '../config';
|
|
2
|
+
import { IContext } from '../context';
|
|
3
|
+
import { IScoreRetriever } from '../utils';
|
|
4
|
+
export declare class RiskTokenScoreRetriever implements IScoreRetriever {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly mobileErrorHandler;
|
|
7
|
+
constructor(config: IConfiguration);
|
|
8
|
+
shouldRetrieveScore(context: IContext): boolean;
|
|
9
|
+
retrieveScore(context: IContext): Promise<boolean>;
|
|
10
|
+
private verifyToken;
|
|
11
|
+
private handleMobileErrorIfNeeded;
|
|
12
|
+
private handleFailure;
|
|
13
|
+
private acceptToken;
|
|
14
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RiskTokenScoreRetriever = void 0;
|
|
40
|
+
var utils_1 = require("../utils");
|
|
41
|
+
var risk_api_1 = require("../risk_api");
|
|
42
|
+
var block_handler_1 = require("../block_handler");
|
|
43
|
+
var MobileErrorHandler_1 = require("./MobileErrorHandler");
|
|
44
|
+
var TokenVerificationResult_1 = require("./TokenVerificationResult");
|
|
45
|
+
var RiskTokenScoreRetriever = /** @class */ (function () {
|
|
46
|
+
function RiskTokenScoreRetriever(config) {
|
|
47
|
+
this.config = config;
|
|
48
|
+
this.mobileErrorHandler = new MobileErrorHandler_1.MobileErrorHandler(config);
|
|
49
|
+
}
|
|
50
|
+
RiskTokenScoreRetriever.prototype.shouldRetrieveScore = function (context) {
|
|
51
|
+
return !!context.riskToken || !!context.mobileData.mobileError;
|
|
52
|
+
};
|
|
53
|
+
RiskTokenScoreRetriever.prototype.retrieveScore = function (context) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var token, e_1, s2sCallReason;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
token = context.riskToken;
|
|
60
|
+
_a.label = 1;
|
|
61
|
+
case 1:
|
|
62
|
+
_a.trys.push([1, 5, , 6]);
|
|
63
|
+
if (!!token) return [3 /*break*/, 3];
|
|
64
|
+
this.handleFailure(context, risk_api_1.S2SCallReason.NO_COOKIE);
|
|
65
|
+
return [4 /*yield*/, this.handleMobileErrorIfNeeded(context)];
|
|
66
|
+
case 2:
|
|
67
|
+
_a.sent();
|
|
68
|
+
return [2 /*return*/, false];
|
|
69
|
+
case 3: return [4 /*yield*/, this.verifyToken(token, context)];
|
|
70
|
+
case 4:
|
|
71
|
+
if (!(_a.sent())) {
|
|
72
|
+
return [2 /*return*/, false];
|
|
73
|
+
}
|
|
74
|
+
if (token.isHighScore()) {
|
|
75
|
+
context.blockReason = block_handler_1.BlockReason.COOKIE_HIGH_SCORE;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
context.passReason = utils_1.PassReason.COOKIE;
|
|
79
|
+
}
|
|
80
|
+
this.config.logger.debug("".concat(token.isHighScore() ? 'high' : 'low', " score cookie found"));
|
|
81
|
+
return [2 /*return*/, true];
|
|
82
|
+
case 5:
|
|
83
|
+
e_1 = _a.sent();
|
|
84
|
+
this.config.logger.debug("caught exception in cookie score service - ".concat(e_1));
|
|
85
|
+
s2sCallReason = token ? risk_api_1.S2SCallReason.COOKIE_DECRYPTION_FAILED : risk_api_1.S2SCallReason.NO_COOKIE;
|
|
86
|
+
return [2 /*return*/, this.handleFailure(context, s2sCallReason)];
|
|
87
|
+
case 6: return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
RiskTokenScoreRetriever.prototype.verifyToken = function (token, context) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var result;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, token.verify(context)];
|
|
98
|
+
case 1:
|
|
99
|
+
result = _a.sent();
|
|
100
|
+
if (result === TokenVerificationResult_1.TokenVerificationResult.DECRYPTION_FAILED) {
|
|
101
|
+
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_DECRYPTION_FAILED)];
|
|
102
|
+
}
|
|
103
|
+
if (result === TokenVerificationResult_1.TokenVerificationResult.VALIDATION_FAILED) {
|
|
104
|
+
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_VALIDATION_FAILED)];
|
|
105
|
+
}
|
|
106
|
+
this.acceptToken(context, token);
|
|
107
|
+
if (token.isExpired()) {
|
|
108
|
+
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_EXPIRED)];
|
|
109
|
+
}
|
|
110
|
+
return [2 /*return*/, true];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
RiskTokenScoreRetriever.prototype.handleMobileErrorIfNeeded = function (context) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
if (!context.mobileData.mobileError) return [3 /*break*/, 2];
|
|
121
|
+
return [4 /*yield*/, this.mobileErrorHandler.handleMobileError(context)];
|
|
122
|
+
case 1:
|
|
123
|
+
_a.sent();
|
|
124
|
+
_a.label = 2;
|
|
125
|
+
case 2: return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
RiskTokenScoreRetriever.prototype.handleFailure = function (context, s2sCallReason) {
|
|
131
|
+
this.config.logger.debug("could not retrieve cookie score - ".concat(s2sCallReason));
|
|
132
|
+
context.riskApiData.s2sCallReason = s2sCallReason;
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
135
|
+
RiskTokenScoreRetriever.prototype.acceptToken = function (context, token) {
|
|
136
|
+
(0, utils_1.transferExistingProperties)(token, context, {
|
|
137
|
+
vid: 'vid',
|
|
138
|
+
uuid: 'uuid',
|
|
139
|
+
action: 'blockAction',
|
|
140
|
+
score: 'score',
|
|
141
|
+
});
|
|
142
|
+
if (token.vid) {
|
|
143
|
+
context.vidSource = utils_1.VidSource.RISK_COOKIE;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return RiskTokenScoreRetriever;
|
|
147
|
+
}());
|
|
148
|
+
exports.RiskTokenScoreRetriever = RiskTokenScoreRetriever;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenOrigin = void 0;
|
|
4
|
+
var TokenOrigin;
|
|
5
|
+
(function (TokenOrigin) {
|
|
6
|
+
TokenOrigin["COOKIE"] = "cookie";
|
|
7
|
+
TokenOrigin["HEADER"] = "header";
|
|
8
|
+
})(TokenOrigin = exports.TokenOrigin || (exports.TokenOrigin = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenVerificationResult = void 0;
|
|
4
|
+
var TokenVerificationResult;
|
|
5
|
+
(function (TokenVerificationResult) {
|
|
6
|
+
TokenVerificationResult[TokenVerificationResult["CANNOT_VERIFY"] = -1] = "CANNOT_VERIFY";
|
|
7
|
+
TokenVerificationResult[TokenVerificationResult["SUCCESSFUL"] = 0] = "SUCCESSFUL";
|
|
8
|
+
TokenVerificationResult[TokenVerificationResult["DECRYPTION_FAILED"] = 1] = "DECRYPTION_FAILED";
|
|
9
|
+
TokenVerificationResult[TokenVerificationResult["VALIDATION_FAILED"] = 2] = "VALIDATION_FAILED";
|
|
10
|
+
})(TokenVerificationResult = exports.TokenVerificationResult || (exports.TokenVerificationResult = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenVersion = void 0;
|
|
4
|
+
var TokenVersion;
|
|
5
|
+
(function (TokenVersion) {
|
|
6
|
+
TokenVersion["V2"] = "2";
|
|
7
|
+
TokenVersion["V3"] = "3";
|
|
8
|
+
})(TokenVersion = exports.TokenVersion || (exports.TokenVersion = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const COOKIE_SPLIT_DELIMITER = ":";
|
|
2
|
+
export declare const COOKIE_V2_NAME = "_px2";
|
|
3
|
+
export declare const COOKIE_V3_NAME = "_px3";
|
|
4
|
+
export declare const COOKIE_V3_HMAC_INDEX = 0;
|
|
5
|
+
export declare const COOKIE_V3_SALT_INDEX = 1;
|
|
6
|
+
export declare const COOKIE_V3_ITERATIONS_INDEX = 2;
|
|
7
|
+
export declare const COOKIE_V3_PAYLOAD_INDEX = 3;
|
|
8
|
+
export declare const COOKIE_V3_PARTS_COUNT = 4;
|
|
9
|
+
export declare const COOKIE_V3_MAXIMUM_SALT_LENGTH = 100;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COOKIE_V3_MAXIMUM_SALT_LENGTH = exports.COOKIE_V3_PARTS_COUNT = exports.COOKIE_V3_PAYLOAD_INDEX = exports.COOKIE_V3_ITERATIONS_INDEX = exports.COOKIE_V3_SALT_INDEX = exports.COOKIE_V3_HMAC_INDEX = exports.COOKIE_V3_NAME = exports.COOKIE_V2_NAME = exports.COOKIE_SPLIT_DELIMITER = void 0;
|
|
4
|
+
exports.COOKIE_SPLIT_DELIMITER = ':';
|
|
5
|
+
exports.COOKIE_V2_NAME = '_px2';
|
|
6
|
+
exports.COOKIE_V3_NAME = '_px3';
|
|
7
|
+
exports.COOKIE_V3_HMAC_INDEX = 0;
|
|
8
|
+
exports.COOKIE_V3_SALT_INDEX = 1;
|
|
9
|
+
exports.COOKIE_V3_ITERATIONS_INDEX = 2;
|
|
10
|
+
exports.COOKIE_V3_PAYLOAD_INDEX = 3;
|
|
11
|
+
exports.COOKIE_V3_PARTS_COUNT = 4;
|
|
12
|
+
exports.COOKIE_V3_MAXIMUM_SALT_LENGTH = 100;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './utils';
|
|
3
|
+
export * from './token';
|
|
4
|
+
export { RiskTokenScoreRetriever } from './RiskTokenScoreRetriever';
|
|
5
|
+
export { MobileErrorHandler } from './MobileErrorHandler';
|
|
6
|
+
export { MobileError } from './MobileError';
|
|
7
|
+
export { TokenOrigin } from './TokenOrigin';
|
|
8
|
+
export { TokenVerificationResult } from './TokenVerificationResult';
|
|
9
|
+
export { TokenVersion } from './TokenVersion';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TokenVersion = exports.TokenVerificationResult = exports.TokenOrigin = exports.MobileError = exports.MobileErrorHandler = exports.RiskTokenScoreRetriever = void 0;
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./token"), exports);
|
|
21
|
+
var RiskTokenScoreRetriever_1 = require("./RiskTokenScoreRetriever");
|
|
22
|
+
Object.defineProperty(exports, "RiskTokenScoreRetriever", { enumerable: true, get: function () { return RiskTokenScoreRetriever_1.RiskTokenScoreRetriever; } });
|
|
23
|
+
var MobileErrorHandler_1 = require("./MobileErrorHandler");
|
|
24
|
+
Object.defineProperty(exports, "MobileErrorHandler", { enumerable: true, get: function () { return MobileErrorHandler_1.MobileErrorHandler; } });
|
|
25
|
+
var MobileError_1 = require("./MobileError");
|
|
26
|
+
Object.defineProperty(exports, "MobileError", { enumerable: true, get: function () { return MobileError_1.MobileError; } });
|
|
27
|
+
var TokenOrigin_1 = require("./TokenOrigin");
|
|
28
|
+
Object.defineProperty(exports, "TokenOrigin", { enumerable: true, get: function () { return TokenOrigin_1.TokenOrigin; } });
|
|
29
|
+
var TokenVerificationResult_1 = require("./TokenVerificationResult");
|
|
30
|
+
Object.defineProperty(exports, "TokenVerificationResult", { enumerable: true, get: function () { return TokenVerificationResult_1.TokenVerificationResult; } });
|
|
31
|
+
var TokenVersion_1 = require("./TokenVersion");
|
|
32
|
+
Object.defineProperty(exports, "TokenVersion", { enumerable: true, get: function () { return TokenVersion_1.TokenVersion; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IBotDefenderToken } from './IBotDefenderToken';
|
|
2
|
+
import { TokenVerificationResult } from '../TokenVerificationResult';
|
|
3
|
+
import { IContext } from '../../context';
|
|
4
|
+
import { BlockAction } from '../../block_handler';
|
|
5
|
+
import { IConfiguration } from '../../config';
|
|
6
|
+
export declare abstract class BotDefenderTokenBase<PayloadType> implements IBotDefenderToken {
|
|
7
|
+
abstract readonly action: BlockAction;
|
|
8
|
+
abstract readonly hmac: string;
|
|
9
|
+
abstract readonly score: number;
|
|
10
|
+
abstract readonly timestamp: number;
|
|
11
|
+
abstract readonly uuid: string;
|
|
12
|
+
abstract readonly vid: string;
|
|
13
|
+
abstract isExpired(): boolean;
|
|
14
|
+
abstract isHighScore(): boolean;
|
|
15
|
+
protected abstract decrypt(context: IContext): Promise<PayloadType>;
|
|
16
|
+
protected abstract validate(context: IContext): Promise<boolean>;
|
|
17
|
+
protected payload: PayloadType;
|
|
18
|
+
protected cookieString: string;
|
|
19
|
+
protected cookieSecret: string;
|
|
20
|
+
protected cookieMaxLength: number;
|
|
21
|
+
protected isValidated: boolean;
|
|
22
|
+
protected constructor(config: IConfiguration, cookieString: string);
|
|
23
|
+
verify(context: IContext): Promise<TokenVerificationResult>;
|
|
24
|
+
isValid(): boolean;
|
|
25
|
+
getCookieString(): string;
|
|
26
|
+
getPayloadString(): string;
|
|
27
|
+
}
|