perimeterx-js-core 0.1.1 → 0.3.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/lib/activities/HttpActivityClient.d.ts +10 -2
- package/lib/activities/HttpActivityClient.js +10 -1
- package/lib/activities/HttpBatchedActivityClient.d.ts +21 -0
- package/lib/activities/HttpBatchedActivityClient.js +137 -0
- package/lib/activities/index.d.ts +1 -0
- package/lib/activities/index.js +3 -1
- package/lib/activities/model/ActivityDetails.d.ts +4 -2
- package/lib/activities/utils.js +2 -1
- package/lib/config/ConfigurationParams.d.ts +4 -0
- package/lib/config/DefaultConfigurations.js +6 -2
- package/lib/config/IConfiguration.d.ts +26 -0
- package/lib/config/StaticConfigurationBase.d.ts +6 -0
- package/lib/config/StaticConfigurationBase.js +42 -0
- package/lib/context/ContextBase.d.ts +3 -2
- package/lib/context/ContextBase.js +13 -77
- package/lib/context/IContext.d.ts +4 -3
- package/lib/custom_parameters/CustomParametersUtils.d.ts +3 -0
- package/lib/custom_parameters/CustomParametersUtils.js +59 -0
- package/lib/enforcer/EnforcerBase.d.ts +6 -1
- package/lib/enforcer/EnforcerBase.js +46 -8
- package/lib/first_party/DefaultFirstParty.js +1 -1
- package/lib/graphql/DefaultGraphQLParser.d.ts +19 -0
- package/lib/graphql/DefaultGraphQLParser.js +183 -0
- package/lib/graphql/IGraphQLParser.d.ts +5 -0
- package/lib/graphql/IGraphQLParser.js +2 -0
- package/lib/graphql/index.d.ts +5 -0
- package/lib/graphql/index.js +7 -0
- package/lib/graphql/model/GraphQLData.d.ts +7 -0
- package/lib/graphql/model/GraphQLData.js +2 -0
- package/lib/graphql/model/GraphQLOperation.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperation.js +2 -0
- package/lib/graphql/model/GraphQLOperationType.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperationType.js +9 -0
- package/lib/http/utils/HttpHeaders.d.ts +3 -1
- package/lib/http/utils/HttpHeaders.js +19 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/risk_api/PostRiskApiClient.d.ts +13 -0
- package/lib/risk_api/PostRiskApiClient.js +21 -3
- package/lib/risk_api/model/RiskActivity.d.ts +2 -0
- package/lib/risk_api/model/RiskResponseV2.d.ts +2 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +1 -0
- package/lib/risk_token/RiskTokenScoreRetriever.js +1 -1
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/utils.js +1 -1
- package/package.json +2 -3
|
@@ -10,6 +10,7 @@ import { ITelemetry } from '../telemetry';
|
|
|
10
10
|
import { IBlockResponseGenerator } from '../block_handler';
|
|
11
11
|
import { TokenVersion } from '../risk_token';
|
|
12
12
|
import { IActivityClient } from '../activities';
|
|
13
|
+
import { IGraphQLParser } from '../graphql';
|
|
13
14
|
export declare type EnforcerBaseOptions = {
|
|
14
15
|
tokenVersion?: TokenVersion;
|
|
15
16
|
dataEnrichment?: IDataEnrichment;
|
|
@@ -20,6 +21,7 @@ export declare type EnforcerBaseOptions = {
|
|
|
20
21
|
hashUtils?: IHashUtils;
|
|
21
22
|
cipherUtils?: ICipherUtils;
|
|
22
23
|
blockGenerator?: IBlockResponseGenerator;
|
|
24
|
+
graphqlParser?: IGraphQLParser;
|
|
23
25
|
} & ({
|
|
24
26
|
httpClient: IHttpClient;
|
|
25
27
|
firstParty?: IFirstParty;
|
|
@@ -43,6 +45,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
43
45
|
protected riskApiScoreRetriever: IScoreRetriever;
|
|
44
46
|
protected blockGenerator: IBlockResponseGenerator;
|
|
45
47
|
protected activityClient: IActivityClient;
|
|
48
|
+
protected graphQLParser?: IGraphQLParser;
|
|
46
49
|
/**
|
|
47
50
|
* Returns the original Req object in case the module is disabled or an error is thrown.
|
|
48
51
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
@@ -65,7 +68,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
65
68
|
* @returns IContext - The context for the request.
|
|
66
69
|
* @protected
|
|
67
70
|
*/
|
|
68
|
-
protected abstract retrieveContext(req: Req, res: Res, ...args: EnforceArgs): IContext;
|
|
71
|
+
protected abstract retrieveContext(req: Req, res: Res, ...args: EnforceArgs): IContext | null;
|
|
69
72
|
/**
|
|
70
73
|
* Converts the IHttpRequest object into the Req object.
|
|
71
74
|
* @param httpRequest - The IHttpRequest object.
|
|
@@ -118,6 +121,8 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
118
121
|
protected handleFirstParty(context: IContext): Promise<IHttpResponse>;
|
|
119
122
|
protected handleFilter(context: IContext): boolean;
|
|
120
123
|
protected handleCompleteContextInitialization(context: IContext): Promise<void>;
|
|
124
|
+
protected handleGraphQL(context: IContext): Promise<void>;
|
|
125
|
+
protected handleEnrichCustomParameters(context: IContext): Promise<void>;
|
|
121
126
|
protected handleTelemetryIfNeeded(context: IContext): Promise<void>;
|
|
122
127
|
protected handlePxde(context: IContext): Promise<void>;
|
|
123
128
|
protected handleCookieRetrieverIfNeeded(context: IContext): Promise<void>;
|
|
@@ -57,6 +57,8 @@ var block_handler_1 = require("../block_handler");
|
|
|
57
57
|
var risk_token_1 = require("../risk_token");
|
|
58
58
|
var risk_api_1 = require("../risk_api");
|
|
59
59
|
var activities_1 = require("../activities");
|
|
60
|
+
var graphql_1 = require("../graphql");
|
|
61
|
+
var custom_parameters_1 = require("../custom_parameters");
|
|
60
62
|
var EnforcerBase = /** @class */ (function () {
|
|
61
63
|
/**
|
|
62
64
|
* The EnforcerBase constructor.
|
|
@@ -72,10 +74,17 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
72
74
|
this.cookieScoreRetriever = options.cookieScoreRetriever || new risk_token_1.RiskTokenScoreRetriever(this.config);
|
|
73
75
|
this.blockGenerator = options.blockGenerator || new block_handler_1.DefaultBlockResponseGenerator(this.config, base64Utils);
|
|
74
76
|
this.dataEnrichment = options.dataEnrichment || new pxde_1.DefaultDataEnrichment(this.config, base64Utils, hashUtils);
|
|
77
|
+
this.graphQLParser = this.config.graphqlEnabled
|
|
78
|
+
? options.graphqlParser || new graphql_1.DefaultGraphQLParser(this.config)
|
|
79
|
+
: null;
|
|
75
80
|
var httpClient = options.httpClient;
|
|
76
81
|
this.firstParty = options.firstParty || new first_party_1.DefaultFirstParty(this.config, httpClient);
|
|
77
82
|
this.telemetry = options.telemetry || new telemetry_1.DefaultTelemetry(this.config, httpClient, base64Utils, hashUtils);
|
|
78
|
-
this.activityClient =
|
|
83
|
+
this.activityClient =
|
|
84
|
+
options.activityClient ||
|
|
85
|
+
(this.config.maxActivityBatchSize > 1
|
|
86
|
+
? new activities_1.HttpBatchedActivityClient(this.config, httpClient)
|
|
87
|
+
: new activities_1.HttpActivityClient(this.config, httpClient));
|
|
79
88
|
var riskResponseHandler = options.tokenVersion === risk_token_1.TokenVersion.V2
|
|
80
89
|
? new risk_api_1.RiskResponseV2Handler(this.config)
|
|
81
90
|
: new risk_api_1.RiskResponseV3Handler(this.config);
|
|
@@ -147,23 +156,29 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
147
156
|
case 3:
|
|
148
157
|
_a.sent();
|
|
149
158
|
this.config.logger.debug('context initialization complete');
|
|
150
|
-
return [4 /*yield*/, this.
|
|
159
|
+
return [4 /*yield*/, this.handleGraphQL(context)];
|
|
151
160
|
case 4:
|
|
152
161
|
_a.sent();
|
|
153
|
-
return [4 /*yield*/, this.
|
|
162
|
+
return [4 /*yield*/, this.handleEnrichCustomParameters(context)];
|
|
154
163
|
case 5:
|
|
155
164
|
_a.sent();
|
|
156
|
-
return [4 /*yield*/, this.
|
|
165
|
+
return [4 /*yield*/, this.handleTelemetryIfNeeded(context)];
|
|
157
166
|
case 6:
|
|
158
167
|
_a.sent();
|
|
159
|
-
return [4 /*yield*/, this.
|
|
168
|
+
return [4 /*yield*/, this.handlePxde(context)];
|
|
160
169
|
case 7:
|
|
161
170
|
_a.sent();
|
|
162
|
-
return [4 /*yield*/, this.
|
|
171
|
+
return [4 /*yield*/, this.handleCookieRetrieverIfNeeded(context)];
|
|
163
172
|
case 8:
|
|
164
173
|
_a.sent();
|
|
165
|
-
return [4 /*yield*/, this.
|
|
174
|
+
return [4 /*yield*/, this.handleRiskApiIfNeeded(context)];
|
|
166
175
|
case 9:
|
|
176
|
+
_a.sent();
|
|
177
|
+
return [4 /*yield*/, this.handleAdditionalActivityHandler(context)];
|
|
178
|
+
case 10:
|
|
179
|
+
_a.sent();
|
|
180
|
+
return [4 /*yield*/, this.handleBlockResponse(context)];
|
|
181
|
+
case 11:
|
|
167
182
|
httpResponse = _a.sent();
|
|
168
183
|
if (httpResponse) {
|
|
169
184
|
this.config.logger.debug("blocking request due to ".concat(context.blockReason));
|
|
@@ -200,10 +215,33 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
200
215
|
return this.filter.shouldFilter(context);
|
|
201
216
|
};
|
|
202
217
|
EnforcerBase.prototype.handleCompleteContextInitialization = function (context) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
EnforcerBase.prototype.handleGraphQL = function (context) {
|
|
225
|
+
var _a;
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
return __generator(this, function (_b) {
|
|
228
|
+
switch (_b.label) {
|
|
229
|
+
case 0:
|
|
230
|
+
if (!((_a = this.graphQLParser) === null || _a === void 0 ? void 0 : _a.isGraphQLRequest(context))) return [3 /*break*/, 2];
|
|
231
|
+
return [4 /*yield*/, this.graphQLParser.parseGraphQLRequest(context)];
|
|
232
|
+
case 1:
|
|
233
|
+
_b.sent();
|
|
234
|
+
_b.label = 2;
|
|
235
|
+
case 2: return [2 /*return*/];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
EnforcerBase.prototype.handleEnrichCustomParameters = function (context) {
|
|
203
241
|
return __awaiter(this, void 0, void 0, function () {
|
|
204
242
|
return __generator(this, function (_a) {
|
|
205
243
|
switch (_a.label) {
|
|
206
|
-
case 0: return [4 /*yield*/,
|
|
244
|
+
case 0: return [4 /*yield*/, custom_parameters_1.CustomParametersUtils.handleCustomParameters(this.config, context)];
|
|
207
245
|
case 1:
|
|
208
246
|
_a.sent();
|
|
209
247
|
return [2 /*return*/];
|
|
@@ -153,7 +153,7 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
153
153
|
case 1: return [2 /*return*/, _b.sent()];
|
|
154
154
|
case 2:
|
|
155
155
|
e_1 = _b.sent();
|
|
156
|
-
this.config.logger.debug("failed sending first party request to ".concat(url));
|
|
156
|
+
this.config.logger.debug("failed sending first party request to ".concat(url, ": ").concat(e_1));
|
|
157
157
|
return [2 /*return*/, null];
|
|
158
158
|
case 3: return [2 /*return*/];
|
|
159
159
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IContext } from '../context/IContext';
|
|
2
|
+
import { IConfiguration } from '../config';
|
|
3
|
+
import { IGraphQLParser } from './IGraphQLParser';
|
|
4
|
+
export declare class DefaultGraphQLParser implements IGraphQLParser {
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private readonly graphqlRoutes;
|
|
7
|
+
private readonly sensitiveOperationTypes;
|
|
8
|
+
private readonly sensitiveOperationNames;
|
|
9
|
+
constructor(config: IConfiguration);
|
|
10
|
+
isGraphQLRequest({ requestData }: IContext): boolean;
|
|
11
|
+
parseGraphQLRequest(context: IContext): Promise<boolean>;
|
|
12
|
+
private getGraphQLOperationsFromBody;
|
|
13
|
+
private parseGraphQLOperations;
|
|
14
|
+
private parseGraphQlOperation;
|
|
15
|
+
private getOperationNameToTypeMap;
|
|
16
|
+
private getGraphQLData;
|
|
17
|
+
private isSensitiveOperation;
|
|
18
|
+
private extractGraphQLVariableNames;
|
|
19
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
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.DefaultGraphQLParser = void 0;
|
|
40
|
+
var http_1 = require("../http");
|
|
41
|
+
var GraphQLOperationType_1 = require("./model/GraphQLOperationType");
|
|
42
|
+
var utils_1 = require("../utils");
|
|
43
|
+
var DefaultGraphQLParser = /** @class */ (function () {
|
|
44
|
+
function DefaultGraphQLParser(config) {
|
|
45
|
+
this.logger = config.logger;
|
|
46
|
+
this.graphqlRoutes = config.graphqlRoutes;
|
|
47
|
+
this.sensitiveOperationNames = config.sensitiveGraphqlOperationNames;
|
|
48
|
+
this.sensitiveOperationTypes = config.sensitiveGraphqlOperationTypes;
|
|
49
|
+
}
|
|
50
|
+
DefaultGraphQLParser.prototype.isGraphQLRequest = function (_a) {
|
|
51
|
+
var requestData = _a.requestData;
|
|
52
|
+
return (requestData.method === http_1.HttpMethod.POST && (0, utils_1.isRouteInPatterns)(requestData.url.pathname, this.graphqlRoutes));
|
|
53
|
+
};
|
|
54
|
+
DefaultGraphQLParser.prototype.parseGraphQLRequest = function (context) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var graphQLOperations, data, e_1;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
_a.trys.push([0, 2, , 3]);
|
|
61
|
+
return [4 /*yield*/, this.getGraphQLOperationsFromBody(context.requestData)];
|
|
62
|
+
case 1:
|
|
63
|
+
graphQLOperations = _a.sent();
|
|
64
|
+
if (!graphQLOperations) {
|
|
65
|
+
this.logger.debug('unable to get graphql operations from request body');
|
|
66
|
+
return [2 /*return*/, false];
|
|
67
|
+
}
|
|
68
|
+
data = this.parseGraphQLOperations(graphQLOperations);
|
|
69
|
+
if (!data || data.length === 0) {
|
|
70
|
+
this.logger.debug('unable to parse graphql operations');
|
|
71
|
+
return [2 /*return*/, false];
|
|
72
|
+
}
|
|
73
|
+
this.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
|
|
74
|
+
context.graphqlData = data;
|
|
75
|
+
context.isSensitiveRequest = context.isSensitiveRequest || data.some(function (operation) { return operation.sensitive; });
|
|
76
|
+
return [2 /*return*/, true];
|
|
77
|
+
case 2:
|
|
78
|
+
e_1 = _a.sent();
|
|
79
|
+
this.logger.debug("error parsing graphql request: ".concat(e_1));
|
|
80
|
+
return [2 /*return*/, false];
|
|
81
|
+
case 3: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
DefaultGraphQLParser.prototype.getGraphQLOperationsFromBody = function (_a) {
|
|
87
|
+
var request = _a.request;
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var body;
|
|
90
|
+
return __generator(this, function (_b) {
|
|
91
|
+
switch (_b.label) {
|
|
92
|
+
case 0: return [4 /*yield*/, request.readBody()];
|
|
93
|
+
case 1:
|
|
94
|
+
body = _b.sent();
|
|
95
|
+
if (typeof body === 'string') {
|
|
96
|
+
try {
|
|
97
|
+
body = JSON.parse(body);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
this.logger.debug("unable to parse string body: ".concat(e));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!body || typeof body !== 'object') {
|
|
104
|
+
return [2 /*return*/, null];
|
|
105
|
+
}
|
|
106
|
+
return [2 /*return*/, Array.isArray(body) ? body : [body]];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
DefaultGraphQLParser.prototype.parseGraphQLOperations = function (operations) {
|
|
112
|
+
var _this = this;
|
|
113
|
+
return operations.map(function (operation) { return _this.parseGraphQlOperation(operation); }).filter(function (x) { return x; });
|
|
114
|
+
};
|
|
115
|
+
DefaultGraphQLParser.prototype.parseGraphQlOperation = function (operation) {
|
|
116
|
+
if (!operation.query || typeof operation.query !== 'string') {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
var operationNameToTypeMap = this.getOperationNameToTypeMap(operation.query);
|
|
120
|
+
if (!operationNameToTypeMap) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return this.getGraphQLData(operationNameToTypeMap, operation);
|
|
124
|
+
};
|
|
125
|
+
DefaultGraphQLParser.prototype.getOperationNameToTypeMap = function (query) {
|
|
126
|
+
var operationTypesString = Object.values(GraphQLOperationType_1.GraphQLOperationType).join('|');
|
|
127
|
+
var pattern = new RegExp("\\s*(".concat(operationTypesString, ")\\s+(\\w+)"), 'gm');
|
|
128
|
+
var match;
|
|
129
|
+
var map = {};
|
|
130
|
+
while ((match = pattern.exec(query)) !== null) {
|
|
131
|
+
var operationType = match[1];
|
|
132
|
+
var operationName = match[2];
|
|
133
|
+
if (map[operationName]) {
|
|
134
|
+
// query contains two operations with the same name which is illegal
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
map[operationName] = operationType;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return map;
|
|
142
|
+
};
|
|
143
|
+
DefaultGraphQLParser.prototype.getGraphQLData = function (operationNameToTypeMap, operation) {
|
|
144
|
+
var name = operation.operationName ||
|
|
145
|
+
(Object.keys(operationNameToTypeMap).length === 1 ? Object.keys(operationNameToTypeMap)[0] : undefined);
|
|
146
|
+
var type = operationNameToTypeMap[name];
|
|
147
|
+
if (!type && /^\s*{/.test(operation.query)) {
|
|
148
|
+
type = GraphQLOperationType_1.GraphQLOperationType.QUERY;
|
|
149
|
+
}
|
|
150
|
+
if (!type) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
var data = { name: name, type: type };
|
|
154
|
+
if (this.isSensitiveOperation(name, type)) {
|
|
155
|
+
data.sensitive = true;
|
|
156
|
+
}
|
|
157
|
+
if (operation.variables && typeof operation.variables === 'object') {
|
|
158
|
+
data.variables = this.extractGraphQLVariableNames(operation.variables);
|
|
159
|
+
}
|
|
160
|
+
return data;
|
|
161
|
+
};
|
|
162
|
+
DefaultGraphQLParser.prototype.isSensitiveOperation = function (operationName, operationType) {
|
|
163
|
+
return (this.sensitiveOperationTypes.some(function (type) { return type === operationType; }) ||
|
|
164
|
+
this.sensitiveOperationNames.some(function (name) { return name === operationName; }));
|
|
165
|
+
};
|
|
166
|
+
DefaultGraphQLParser.prototype.extractGraphQLVariableNames = function (variables) {
|
|
167
|
+
var processVariables = function (variablesObj, prefix) {
|
|
168
|
+
return Object.entries(variablesObj).reduce(function (total, _a) {
|
|
169
|
+
var key = _a[0], value = _a[1];
|
|
170
|
+
if (!value || typeof value !== 'object' || Object.keys(value).length === 0) {
|
|
171
|
+
total.push(prefix + key);
|
|
172
|
+
return total;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return total.concat(processVariables(value, "".concat(prefix).concat(key, ".")));
|
|
176
|
+
}
|
|
177
|
+
}, []);
|
|
178
|
+
};
|
|
179
|
+
return processVariables(variables, '');
|
|
180
|
+
};
|
|
181
|
+
return DefaultGraphQLParser;
|
|
182
|
+
}());
|
|
183
|
+
exports.DefaultGraphQLParser = DefaultGraphQLParser;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GraphQLOperationType } from './model/GraphQLOperationType';
|
|
2
|
+
export { GraphQLOperation } from './model/GraphQLOperation';
|
|
3
|
+
export { GraphQLData } from './model/GraphQLData';
|
|
4
|
+
export { IGraphQLParser } from './IGraphQLParser';
|
|
5
|
+
export { DefaultGraphQLParser } from './DefaultGraphQLParser';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultGraphQLParser = exports.GraphQLOperationType = void 0;
|
|
4
|
+
var GraphQLOperationType_1 = require("./model/GraphQLOperationType");
|
|
5
|
+
Object.defineProperty(exports, "GraphQLOperationType", { enumerable: true, get: function () { return GraphQLOperationType_1.GraphQLOperationType; } });
|
|
6
|
+
var DefaultGraphQLParser_1 = require("./DefaultGraphQLParser");
|
|
7
|
+
Object.defineProperty(exports, "DefaultGraphQLParser", { enumerable: true, get: function () { return DefaultGraphQLParser_1.DefaultGraphQLParser; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLOperationType = void 0;
|
|
4
|
+
var GraphQLOperationType;
|
|
5
|
+
(function (GraphQLOperationType) {
|
|
6
|
+
GraphQLOperationType["QUERY"] = "query";
|
|
7
|
+
GraphQLOperationType["MUTATION"] = "mutation";
|
|
8
|
+
GraphQLOperationType["SUBSCRIPTION"] = "subscription";
|
|
9
|
+
})(GraphQLOperationType = exports.GraphQLOperationType || (exports.GraphQLOperationType = {}));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare type HttpHeadersInit = Record<string, string[]>;
|
|
2
2
|
export declare class HttpHeaders {
|
|
3
3
|
private readonly headers;
|
|
4
|
+
static from(headers: Headers): HttpHeaders;
|
|
4
5
|
/**
|
|
5
6
|
* Constructs a new instance of the HttpHeaders class.
|
|
6
7
|
* @param init - Optional header names and values with which to initialize the HttpHeaders instance.
|
|
@@ -41,11 +42,12 @@ export declare class HttpHeaders {
|
|
|
41
42
|
* @returns object - An object representing the current state of the HttpHeaders instance. The keys are the header
|
|
42
43
|
* names (all lowercase), and the values are arrays of all the associated header values.
|
|
43
44
|
*/
|
|
44
|
-
toObject(): Record<string, string[]>;
|
|
45
|
+
toObject(joinDelimiter?: string): Record<string, string | string[]>;
|
|
45
46
|
/**
|
|
46
47
|
* Iterates through all headers and applies a callback function to each one.
|
|
47
48
|
* @param callbackFn - The callback function to be applied on every header.
|
|
48
49
|
*/
|
|
49
50
|
forEach(callbackFn: (values: readonly string[], name: string) => void): void;
|
|
50
51
|
private toKey;
|
|
52
|
+
entries(delimiter?: string): [string, string][];
|
|
51
53
|
}
|
|
@@ -19,6 +19,13 @@ var HttpHeaders = /** @class */ (function () {
|
|
|
19
19
|
var _this = this;
|
|
20
20
|
this.headers = init ? new Map(Object.keys(init).map(function (name) { return [_this.toKey(name), init[name]]; })) : new Map();
|
|
21
21
|
}
|
|
22
|
+
HttpHeaders.from = function (headers) {
|
|
23
|
+
var ret = new HttpHeaders();
|
|
24
|
+
headers.forEach(function (value, key) {
|
|
25
|
+
ret.append(key, value);
|
|
26
|
+
});
|
|
27
|
+
return ret;
|
|
28
|
+
};
|
|
22
29
|
/**
|
|
23
30
|
* Retrieves the values associated with the provided header name. If no header exists, it returns undefined.
|
|
24
31
|
* @param name - The case-insensitive header name.
|
|
@@ -84,10 +91,10 @@ var HttpHeaders = /** @class */ (function () {
|
|
|
84
91
|
* @returns object - An object representing the current state of the HttpHeaders instance. The keys are the header
|
|
85
92
|
* names (all lowercase), and the values are arrays of all the associated header values.
|
|
86
93
|
*/
|
|
87
|
-
HttpHeaders.prototype.toObject = function () {
|
|
94
|
+
HttpHeaders.prototype.toObject = function (joinDelimiter) {
|
|
88
95
|
var obj = {};
|
|
89
96
|
this.forEach(function (values, name) {
|
|
90
|
-
obj[name] = __spreadArray([], values, true);
|
|
97
|
+
obj[name] = joinDelimiter ? values.join(joinDelimiter) : __spreadArray([], values, true);
|
|
91
98
|
});
|
|
92
99
|
return obj;
|
|
93
100
|
};
|
|
@@ -101,6 +108,16 @@ var HttpHeaders = /** @class */ (function () {
|
|
|
101
108
|
HttpHeaders.prototype.toKey = function (name) {
|
|
102
109
|
return name.toLowerCase();
|
|
103
110
|
};
|
|
111
|
+
HttpHeaders.prototype.entries = function (delimiter) {
|
|
112
|
+
if (delimiter === void 0) { delimiter = ','; }
|
|
113
|
+
var ret = [];
|
|
114
|
+
this.headers.forEach(function (values, headerName) {
|
|
115
|
+
if (values === null || values === void 0 ? void 0 : values.length) {
|
|
116
|
+
ret.push([headerName, values.join(delimiter)]);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return ret;
|
|
120
|
+
};
|
|
104
121
|
return HttpHeaders;
|
|
105
122
|
}());
|
|
106
123
|
exports.HttpHeaders = HttpHeaders;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./custom_parameters"), exports);
|
|
|
23
23
|
__exportStar(require("./enforcer"), exports);
|
|
24
24
|
__exportStar(require("./filter"), exports);
|
|
25
25
|
__exportStar(require("./first_party"), exports);
|
|
26
|
+
__exportStar(require("./graphql"), exports);
|
|
26
27
|
__exportStar(require("./http"), exports);
|
|
27
28
|
__exportStar(require("./logger"), exports);
|
|
28
29
|
__exportStar(require("./pxde"), exports);
|
|
@@ -15,7 +15,20 @@ export declare class PostRiskApiClient<RiskResponseType extends RiskResponseV2 |
|
|
|
15
15
|
shouldRetrieveScore(context: IContext): boolean;
|
|
16
16
|
private unsetScoreFields;
|
|
17
17
|
retrieveScore(context: IContext): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates the RiskActivity payload
|
|
20
|
+
* @param context
|
|
21
|
+
* @returns RiskActivity
|
|
22
|
+
* @protected
|
|
23
|
+
*/
|
|
18
24
|
protected createRiskActivity(context: IContext): RiskActivity;
|
|
25
|
+
/**
|
|
26
|
+
* Protected function in case expansions or alterations to the risk activity are needed for certain platforms.
|
|
27
|
+
* @param riskActivity
|
|
28
|
+
* @returns RiskActivity
|
|
29
|
+
* @protected
|
|
30
|
+
*/
|
|
31
|
+
protected finalizeRiskActivity(riskActivity: RiskActivity): RiskActivity;
|
|
19
32
|
private addOptionalRiskFields;
|
|
20
33
|
private addOptionalRiskFieldsToRoot;
|
|
21
34
|
private addOptionalRiskFieldsToAdditional;
|
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.PostRiskApiClient = void 0;
|
|
40
|
-
var
|
|
40
|
+
var risk_token_1 = require("../risk_token");
|
|
41
41
|
var http_1 = require("../http");
|
|
42
42
|
var utils_1 = require("../utils");
|
|
43
43
|
var S2SCallReason_1 = require("./S2SCallReason");
|
|
@@ -117,6 +117,12 @@ var PostRiskApiClient = /** @class */ (function () {
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Creates the RiskActivity payload
|
|
122
|
+
* @param context
|
|
123
|
+
* @returns RiskActivity
|
|
124
|
+
* @protected
|
|
125
|
+
*/
|
|
120
126
|
PostRiskApiClient.prototype.createRiskActivity = function (context) {
|
|
121
127
|
var riskActivity = {
|
|
122
128
|
request: {
|
|
@@ -130,12 +136,21 @@ var PostRiskApiClient = /** @class */ (function () {
|
|
|
130
136
|
http_method: context.requestData.method,
|
|
131
137
|
http_version: context.requestData.httpVersion,
|
|
132
138
|
risk_mode: context.isMonitoredRequest ? utils_1.ModuleMode.MONITOR : utils_1.ModuleMode.ACTIVE_BLOCKING,
|
|
133
|
-
cookie_origin: context.tokenOrigin ||
|
|
139
|
+
cookie_origin: context.tokenOrigin || risk_token_1.TokenOrigin.COOKIE,
|
|
134
140
|
request_cookie_names: context.requestData.requestCookieNames,
|
|
135
141
|
request_id: context.requestId,
|
|
136
142
|
},
|
|
137
143
|
};
|
|
138
144
|
this.addOptionalRiskFields(riskActivity, context);
|
|
145
|
+
return this.finalizeRiskActivity(riskActivity);
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Protected function in case expansions or alterations to the risk activity are needed for certain platforms.
|
|
149
|
+
* @param riskActivity
|
|
150
|
+
* @returns RiskActivity
|
|
151
|
+
* @protected
|
|
152
|
+
*/
|
|
153
|
+
PostRiskApiClient.prototype.finalizeRiskActivity = function (riskActivity) {
|
|
139
154
|
return riskActivity;
|
|
140
155
|
};
|
|
141
156
|
PostRiskApiClient.prototype.addOptionalRiskFields = function (riskActivity, context) {
|
|
@@ -154,6 +169,7 @@ var PostRiskApiClient = /** @class */ (function () {
|
|
|
154
169
|
PostRiskApiClient.prototype.addOptionalRiskFieldsToAdditional = function (riskActivity, context) {
|
|
155
170
|
(0, utils_1.transferExistingProperties)(context, riskActivity.additional, {
|
|
156
171
|
vidSource: 'enforcer_vid_source',
|
|
172
|
+
graphqlData: 'graphql_operations',
|
|
157
173
|
});
|
|
158
174
|
(0, utils_1.transferExistingProperties)(context.serverData, riskActivity.additional, {
|
|
159
175
|
region: 'server_info_region',
|
|
@@ -182,11 +198,13 @@ var PostRiskApiClient = /** @class */ (function () {
|
|
|
182
198
|
PostRiskApiClient.prototype.addCookieRiskFieldsToAdditional = function (riskActivity, _a) {
|
|
183
199
|
var riskToken = _a.riskToken;
|
|
184
200
|
if (riskToken) {
|
|
185
|
-
riskActivity.additional.px_orig_cookie = riskToken.getCookieString();
|
|
186
201
|
if (riskToken.isValid()) {
|
|
187
202
|
riskActivity.additional.px_cookie = riskToken.getPayloadString();
|
|
188
203
|
riskActivity.additional.px_cookie_hmac = riskToken.hmac;
|
|
189
204
|
}
|
|
205
|
+
else {
|
|
206
|
+
riskActivity.additional.px_orig_cookie = riskToken.getCookieString();
|
|
207
|
+
}
|
|
190
208
|
}
|
|
191
209
|
};
|
|
192
210
|
PostRiskApiClient.prototype.formatRiskHeadersField = function (headers) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ModuleMode, VidSource } from '../../utils';
|
|
2
2
|
import { TokenOrigin } from '../../risk_token';
|
|
3
3
|
import { CustomParameters } from '../../custom_parameters';
|
|
4
|
+
import { GraphQLData } from '../../graphql/';
|
|
4
5
|
import { S2SCallReason } from '../S2SCallReason';
|
|
5
6
|
export declare type HeaderEntry = {
|
|
6
7
|
name: string;
|
|
@@ -40,6 +41,7 @@ export declare type RiskAdditionalData = {
|
|
|
40
41
|
cross_tab_session?: string;
|
|
41
42
|
app_user_id?: string;
|
|
42
43
|
jwt_additional_fields?: string[];
|
|
44
|
+
graphql_operations?: GraphQLData[];
|
|
43
45
|
} & CustomParameters;
|
|
44
46
|
export declare type RiskActivity = {
|
|
45
47
|
vid?: string;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { RiskStatus } from './RiskStatus';
|
|
2
2
|
import { PXDE } from '../../pxde';
|
|
3
|
+
import { BlockAction } from '../../block_handler';
|
|
3
4
|
export declare type RiskResponseV2 = {
|
|
4
5
|
status: RiskStatus;
|
|
5
6
|
cookie_cfg_block_result?: '0' | '1';
|
|
7
|
+
action?: BlockAction;
|
|
6
8
|
uuid?: string;
|
|
7
9
|
pxhd?: string;
|
|
8
10
|
message?: string;
|
|
@@ -35,6 +35,7 @@ var RiskResponseV2Handler = /** @class */ (function (_super) {
|
|
|
35
35
|
(0, utils_1.transferExistingProperties)(riskResponse, context, {
|
|
36
36
|
uuid: 'uuid',
|
|
37
37
|
pxhd: 'pxhd',
|
|
38
|
+
action: 'blockAction',
|
|
38
39
|
data_enrichment: 'pxde',
|
|
39
40
|
});
|
|
40
41
|
if (riskResponse.data_enrichment) {
|
|
@@ -97,7 +97,7 @@ var RiskTokenScoreRetriever = /** @class */ (function () {
|
|
|
97
97
|
case 0: return [4 /*yield*/, token.verify(context)];
|
|
98
98
|
case 1:
|
|
99
99
|
result = _a.sent();
|
|
100
|
-
if (result === TokenVerificationResult_1.TokenVerificationResult.DECRYPTION_FAILED) {
|
|
100
|
+
if (result === TokenVerificationResult_1.TokenVerificationResult.DECRYPTION_FAILED || result === TokenVerificationResult_1.TokenVerificationResult.CANNOT_VERIFY) {
|
|
101
101
|
return [2 /*return*/, this.handleFailure(context, risk_api_1.S2SCallReason.COOKIE_DECRYPTION_FAILED)];
|
|
102
102
|
}
|
|
103
103
|
if (result === TokenVerificationResult_1.TokenVerificationResult.VALIDATION_FAILED) {
|