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
|
@@ -2,11 +2,19 @@ import { IConfiguration } from '../config';
|
|
|
2
2
|
import { IContext } from '../context';
|
|
3
3
|
import { IHttpClient } from '../http';
|
|
4
4
|
import { IActivityClient } from './IActivityClient';
|
|
5
|
+
import { Activity } from './model/Activity';
|
|
5
6
|
export declare class HttpActivityClient implements IActivityClient {
|
|
6
7
|
private readonly config;
|
|
7
8
|
private readonly httpClient;
|
|
8
9
|
constructor(config: IConfiguration, httpClient: IHttpClient);
|
|
9
10
|
sendActivities(context: IContext): Promise<boolean>;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
protected createActivities(context: IContext): Activity[];
|
|
12
|
+
/**
|
|
13
|
+
* Allows for expansions or alterations to the async activity if needed.
|
|
14
|
+
* @param activity
|
|
15
|
+
* @returns Activity
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
protected finalizeActivity(activity: Activity): Activity;
|
|
19
|
+
protected postActivities(activities: Activity[]): Promise<boolean>;
|
|
12
20
|
}
|
|
@@ -74,7 +74,16 @@ var HttpActivityClient = /** @class */ (function () {
|
|
|
74
74
|
else if (context.passReason) {
|
|
75
75
|
activities.push((0, utils_2.createActivity)(ActivityType_1.ActivityType.PAGE_REQUESTED, this.config, context));
|
|
76
76
|
}
|
|
77
|
-
return activities;
|
|
77
|
+
return activities.map(this.finalizeActivity);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Allows for expansions or alterations to the async activity if needed.
|
|
81
|
+
* @param activity
|
|
82
|
+
* @returns Activity
|
|
83
|
+
* @protected
|
|
84
|
+
*/
|
|
85
|
+
HttpActivityClient.prototype.finalizeActivity = function (activity) {
|
|
86
|
+
return activity;
|
|
78
87
|
};
|
|
79
88
|
HttpActivityClient.prototype.postActivities = function (activities) {
|
|
80
89
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpActivityClient } from './HttpActivityClient';
|
|
2
|
+
import { IConfiguration } from '../config';
|
|
3
|
+
import { IHttpClient } from '../http';
|
|
4
|
+
import { Activity } from './model/Activity';
|
|
5
|
+
export declare class HttpBatchedActivityClient extends HttpActivityClient {
|
|
6
|
+
private readonly batchSize;
|
|
7
|
+
private readonly timeoutMs;
|
|
8
|
+
private readonly maxBufferSize;
|
|
9
|
+
private buffer;
|
|
10
|
+
private timeoutId;
|
|
11
|
+
constructor(config: IConfiguration, httpClient: IHttpClient);
|
|
12
|
+
stop(): void;
|
|
13
|
+
protected postActivities(activities: Activity[]): Promise<boolean>;
|
|
14
|
+
private addToBuffer;
|
|
15
|
+
private shouldFlush;
|
|
16
|
+
protected triggerFlush(): Promise<boolean>;
|
|
17
|
+
private flush;
|
|
18
|
+
protected clear(): void;
|
|
19
|
+
private startTimer;
|
|
20
|
+
private stopTimer;
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.HttpBatchedActivityClient = void 0;
|
|
55
|
+
var HttpActivityClient_1 = require("./HttpActivityClient");
|
|
56
|
+
var HttpBatchedActivityClient = /** @class */ (function (_super) {
|
|
57
|
+
__extends(HttpBatchedActivityClient, _super);
|
|
58
|
+
function HttpBatchedActivityClient(config, httpClient) {
|
|
59
|
+
var _this = _super.call(this, config, httpClient) || this;
|
|
60
|
+
_this.buffer = [];
|
|
61
|
+
_this.batchSize = config.maxActivityBatchSize;
|
|
62
|
+
_this.timeoutMs = config.activityBatchTimeoutMs;
|
|
63
|
+
_this.maxBufferSize = _this.batchSize * 2;
|
|
64
|
+
_this.startTimer();
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
HttpBatchedActivityClient.prototype.stop = function () {
|
|
68
|
+
this.stopTimer();
|
|
69
|
+
};
|
|
70
|
+
HttpBatchedActivityClient.prototype.postActivities = function (activities) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
this.addToBuffer(activities);
|
|
74
|
+
return [2 /*return*/, this.shouldFlush() ? this.triggerFlush() : true];
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
HttpBatchedActivityClient.prototype.addToBuffer = function (activities) {
|
|
79
|
+
this.buffer = activities.concat(this.buffer);
|
|
80
|
+
if (this.buffer.length > this.maxBufferSize) {
|
|
81
|
+
this.buffer = this.buffer.slice(0, this.maxBufferSize);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
HttpBatchedActivityClient.prototype.shouldFlush = function () {
|
|
85
|
+
return this.buffer.length >= this.batchSize;
|
|
86
|
+
};
|
|
87
|
+
HttpBatchedActivityClient.prototype.triggerFlush = function () {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var sentSuccessfully, _a;
|
|
90
|
+
return __generator(this, function (_b) {
|
|
91
|
+
switch (_b.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
this.stopTimer();
|
|
94
|
+
_a = this.buffer.length > 0;
|
|
95
|
+
if (!_a) return [3 /*break*/, 2];
|
|
96
|
+
return [4 /*yield*/, this.flush()];
|
|
97
|
+
case 1:
|
|
98
|
+
_a = (_b.sent());
|
|
99
|
+
_b.label = 2;
|
|
100
|
+
case 2:
|
|
101
|
+
sentSuccessfully = _a;
|
|
102
|
+
this.startTimer();
|
|
103
|
+
return [2 /*return*/, sentSuccessfully];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
HttpBatchedActivityClient.prototype.flush = function () {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var sentSuccessfully;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, _super.prototype.postActivities.call(this, this.buffer)];
|
|
114
|
+
case 1:
|
|
115
|
+
sentSuccessfully = _a.sent();
|
|
116
|
+
if (sentSuccessfully) {
|
|
117
|
+
this.clear();
|
|
118
|
+
}
|
|
119
|
+
return [2 /*return*/, sentSuccessfully];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
HttpBatchedActivityClient.prototype.clear = function () {
|
|
125
|
+
this.buffer = [];
|
|
126
|
+
};
|
|
127
|
+
HttpBatchedActivityClient.prototype.startTimer = function () {
|
|
128
|
+
var _this = this;
|
|
129
|
+
this.timeoutId = setTimeout(function () { return _this.triggerFlush(); }, this.timeoutMs);
|
|
130
|
+
};
|
|
131
|
+
HttpBatchedActivityClient.prototype.stopTimer = function () {
|
|
132
|
+
clearTimeout(this.timeoutId);
|
|
133
|
+
this.timeoutId = null;
|
|
134
|
+
};
|
|
135
|
+
return HttpBatchedActivityClient;
|
|
136
|
+
}(HttpActivityClient_1.HttpActivityClient));
|
|
137
|
+
exports.HttpBatchedActivityClient = HttpBatchedActivityClient;
|
|
@@ -3,3 +3,4 @@ export { Activity } from './model/Activity';
|
|
|
3
3
|
export { ActivityTypeDetails, ActivityDetails, BlockActivityDetails, PageRequestedActivityDetails, } from './model/ActivityDetails';
|
|
4
4
|
export { ActivityType } from './ActivityType';
|
|
5
5
|
export { HttpActivityClient } from './HttpActivityClient';
|
|
6
|
+
export { HttpBatchedActivityClient } from './HttpBatchedActivityClient';
|
package/lib/activities/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpActivityClient = exports.ActivityType = void 0;
|
|
3
|
+
exports.HttpBatchedActivityClient = exports.HttpActivityClient = exports.ActivityType = void 0;
|
|
4
4
|
var ActivityType_1 = require("./ActivityType");
|
|
5
5
|
Object.defineProperty(exports, "ActivityType", { enumerable: true, get: function () { return ActivityType_1.ActivityType; } });
|
|
6
6
|
var HttpActivityClient_1 = require("./HttpActivityClient");
|
|
7
7
|
Object.defineProperty(exports, "HttpActivityClient", { enumerable: true, get: function () { return HttpActivityClient_1.HttpActivityClient; } });
|
|
8
|
+
var HttpBatchedActivityClient_1 = require("./HttpBatchedActivityClient");
|
|
9
|
+
Object.defineProperty(exports, "HttpBatchedActivityClient", { enumerable: true, get: function () { return HttpBatchedActivityClient_1.HttpBatchedActivityClient; } });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PassReason } from '../../utils
|
|
2
|
-
import { BlockReason } from '../../block_handler
|
|
1
|
+
import { PassReason } from '../../utils';
|
|
2
|
+
import { BlockReason } from '../../block_handler';
|
|
3
|
+
import { GraphQLData } from '../../graphql';
|
|
3
4
|
export declare type ActivityTypeDetails = PageRequestedActivityDetails | BlockActivityDetails | AdditionalS2SActivityDetails;
|
|
4
5
|
export declare type ActivityDetails = ActivityTypeDetails & {
|
|
5
6
|
client_uuid: string;
|
|
@@ -17,6 +18,7 @@ export declare type ActivityDetails = ActivityTypeDetails & {
|
|
|
17
18
|
tls_preferred_ciphers?: string;
|
|
18
19
|
tls_ciphers_sha?: string;
|
|
19
20
|
tls_ja3_fingerprint?: string;
|
|
21
|
+
graphql_operations?: GraphQLData[];
|
|
20
22
|
credentials_compromised?: boolean;
|
|
21
23
|
ci_version?: string;
|
|
22
24
|
sso_step?: string;
|
package/lib/activities/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ var createActivity = function (activityType, config, context) {
|
|
|
8
8
|
type: activityType,
|
|
9
9
|
px_app_id: config.appId,
|
|
10
10
|
url: context.requestData.url.href,
|
|
11
|
-
headers: (0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders).toObject(),
|
|
11
|
+
headers: (0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders).toObject(','),
|
|
12
12
|
pxhd: context.pxhd,
|
|
13
13
|
socket_ip: context.requestData.ip,
|
|
14
14
|
timestamp: Date.now(),
|
|
@@ -44,6 +44,7 @@ var createGenericActivityDetails = function (config, context) {
|
|
|
44
44
|
requestId: 'request_id',
|
|
45
45
|
uuid: 'client_uuid',
|
|
46
46
|
tokenOrigin: 'cookie_origin',
|
|
47
|
+
graphqlData: 'graphql_operations',
|
|
47
48
|
});
|
|
48
49
|
(0, utils_1.transferExistingProperties)(context.requestData, genericActivityDetails, {
|
|
49
50
|
httpVersion: 'http_version',
|
|
@@ -58,6 +58,10 @@ export declare type ConfigurationParams = {
|
|
|
58
58
|
px_jwt_header_name?: string;
|
|
59
59
|
px_jwt_header_user_id_field_name?: string;
|
|
60
60
|
px_jwt_header_additional_field_names?: string[];
|
|
61
|
+
px_graphql_enabled?: boolean;
|
|
62
|
+
px_graphql_routes?: string[];
|
|
63
|
+
px_sensitive_graphql_operation_names?: string[];
|
|
64
|
+
px_sensitive_graphql_operation_types?: Array<'query' | 'mutation' | 'subscription'>;
|
|
61
65
|
px_extract_ip?: () => {};
|
|
62
66
|
px_additional_activity_handler?: AdditionalActivityHandler;
|
|
63
67
|
px_enrich_custom_parameters?: CustomParametersFunction;
|
|
@@ -20,7 +20,7 @@ exports.DEFAULT_CONFIGURATIONS = {
|
|
|
20
20
|
px_module_mode: ModuleMode_1.ModuleMode.MONITOR,
|
|
21
21
|
px_additional_activity_handler: null,
|
|
22
22
|
px_advanced_blocking_response_enabled: true,
|
|
23
|
-
px_max_activity_batch_size:
|
|
23
|
+
px_max_activity_batch_size: 0,
|
|
24
24
|
px_batch_activities_timeout_ms: 1000,
|
|
25
25
|
px_bypass_monitor_header: '',
|
|
26
26
|
px_csp_enabled: false,
|
|
@@ -94,8 +94,12 @@ exports.DEFAULT_CONFIGURATIONS = {
|
|
|
94
94
|
px_filter_by_user_agent: [],
|
|
95
95
|
px_css_ref: '',
|
|
96
96
|
px_js_ref: '',
|
|
97
|
-
px_custom_cookie_header: '',
|
|
97
|
+
px_custom_cookie_header: 'x-px-cookies',
|
|
98
98
|
px_custom_logo: '',
|
|
99
|
+
px_graphql_enabled: true,
|
|
100
|
+
px_graphql_routes: ['/graphql'],
|
|
101
|
+
px_sensitive_graphql_operation_names: [],
|
|
102
|
+
px_sensitive_graphql_operation_types: [],
|
|
99
103
|
px_enrich_custom_parameters: null,
|
|
100
104
|
px_proxy_url: '',
|
|
101
105
|
px_jwt_cookie_name: '',
|
|
@@ -157,6 +157,32 @@ export interface IConfiguration<ParamsType extends ConfigurationParams = Configu
|
|
|
157
157
|
* The maximum expected length of the user-agent beyond which it will be truncated.
|
|
158
158
|
*/
|
|
159
159
|
readonly userAgentMaxLength: number;
|
|
160
|
+
/**
|
|
161
|
+
* The batch size at which asynchronous activities are sent to the collector.
|
|
162
|
+
*/
|
|
163
|
+
readonly maxActivityBatchSize: number;
|
|
164
|
+
/**
|
|
165
|
+
* The maximum amount of time to wait before sending asynchronous activities to the collector.
|
|
166
|
+
*/
|
|
167
|
+
readonly activityBatchTimeoutMs: number;
|
|
168
|
+
/**
|
|
169
|
+
* Whether parsing of GraphQL request bodies should be enabled.
|
|
170
|
+
*/
|
|
171
|
+
readonly graphqlEnabled: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Routes that should trigger GraphQL parsing by the enforcer.
|
|
174
|
+
*/
|
|
175
|
+
readonly graphqlRoutes: string[];
|
|
176
|
+
/**
|
|
177
|
+
* An array of GraphQL operation names that should trigger a risk API call
|
|
178
|
+
* even if a valid, unexpired, low-score risk cookie is present.
|
|
179
|
+
*/
|
|
180
|
+
readonly sensitiveGraphqlOperationNames: string[];
|
|
181
|
+
/**
|
|
182
|
+
* An array of GraphQL operation types (e.g., mutation) that should trigger a risk API call
|
|
183
|
+
* even if a valid, unexpired, low-score risk cookie is present.
|
|
184
|
+
*/
|
|
185
|
+
readonly sensitiveGraphqlOperationTypes: string[];
|
|
160
186
|
/**
|
|
161
187
|
* A function returning CustomParameters that will be added to the enforcer activities.
|
|
162
188
|
*/
|
|
@@ -51,6 +51,12 @@ export declare abstract class StaticConfigurationBase<ParamsType extends Configu
|
|
|
51
51
|
get riskCookieMinIterations(): number;
|
|
52
52
|
get riskCookieMaxLength(): number;
|
|
53
53
|
get userAgentMaxLength(): number;
|
|
54
|
+
get maxActivityBatchSize(): number;
|
|
55
|
+
get activityBatchTimeoutMs(): number;
|
|
56
|
+
get graphqlEnabled(): boolean;
|
|
57
|
+
get graphqlRoutes(): string[];
|
|
58
|
+
get sensitiveGraphqlOperationNames(): string[];
|
|
59
|
+
get sensitiveGraphqlOperationTypes(): string[];
|
|
54
60
|
get enrichCustomParameters(): CustomParametersFunction;
|
|
55
61
|
get additionalActivityHandler(): AdditionalActivityHandler;
|
|
56
62
|
get altBackendCaptchaUrl(): string;
|
|
@@ -329,6 +329,48 @@ var StaticConfigurationBase = /** @class */ (function () {
|
|
|
329
329
|
enumerable: false,
|
|
330
330
|
configurable: true
|
|
331
331
|
});
|
|
332
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "maxActivityBatchSize", {
|
|
333
|
+
get: function () {
|
|
334
|
+
return this.configParams.px_max_activity_batch_size;
|
|
335
|
+
},
|
|
336
|
+
enumerable: false,
|
|
337
|
+
configurable: true
|
|
338
|
+
});
|
|
339
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "activityBatchTimeoutMs", {
|
|
340
|
+
get: function () {
|
|
341
|
+
return this.configParams.px_batch_activities_timeout_ms;
|
|
342
|
+
},
|
|
343
|
+
enumerable: false,
|
|
344
|
+
configurable: true
|
|
345
|
+
});
|
|
346
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "graphqlEnabled", {
|
|
347
|
+
get: function () {
|
|
348
|
+
return this.configParams.px_graphql_enabled;
|
|
349
|
+
},
|
|
350
|
+
enumerable: false,
|
|
351
|
+
configurable: true
|
|
352
|
+
});
|
|
353
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "graphqlRoutes", {
|
|
354
|
+
get: function () {
|
|
355
|
+
return this.configParams.px_graphql_routes;
|
|
356
|
+
},
|
|
357
|
+
enumerable: false,
|
|
358
|
+
configurable: true
|
|
359
|
+
});
|
|
360
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "sensitiveGraphqlOperationNames", {
|
|
361
|
+
get: function () {
|
|
362
|
+
return this.configParams.px_sensitive_graphql_operation_names;
|
|
363
|
+
},
|
|
364
|
+
enumerable: false,
|
|
365
|
+
configurable: true
|
|
366
|
+
});
|
|
367
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "sensitiveGraphqlOperationTypes", {
|
|
368
|
+
get: function () {
|
|
369
|
+
return this.configParams.px_sensitive_graphql_operation_types;
|
|
370
|
+
},
|
|
371
|
+
enumerable: false,
|
|
372
|
+
configurable: true
|
|
373
|
+
});
|
|
332
374
|
Object.defineProperty(StaticConfigurationBase.prototype, "enrichCustomParameters", {
|
|
333
375
|
get: function () {
|
|
334
376
|
return this.configParams.px_enrich_custom_parameters || null;
|
|
@@ -4,6 +4,7 @@ import { CustomParameters } from '../custom_parameters';
|
|
|
4
4
|
import { FilterReason } from '../filter';
|
|
5
5
|
import { IHttpRequest, HttpHeaders } from '../http';
|
|
6
6
|
import { PXDE } from '../pxde';
|
|
7
|
+
import { GraphQLData } from '../graphql';
|
|
7
8
|
import { IBotDefenderToken, TokenOrigin } from '../risk_token';
|
|
8
9
|
import { VidSource, PassReason, ICookieParser, IUuidGenerator } from '../utils';
|
|
9
10
|
import { IContext, MobileData, RequestData, ResponseData, RiskApiData, ServerData, TlsData } from './IContext';
|
|
@@ -35,21 +36,21 @@ export declare abstract class ContextBase<OptionsType extends ContextBaseOptions
|
|
|
35
36
|
pxde?: PXDE;
|
|
36
37
|
pxdeVerified?: boolean;
|
|
37
38
|
customParameters?: CustomParameters;
|
|
39
|
+
graphqlData?: GraphQLData[];
|
|
38
40
|
protected readonly config: IConfiguration;
|
|
39
41
|
protected constructor(config: IConfiguration, request: IHttpRequest, options?: OptionsType);
|
|
40
42
|
protected abstract createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: OptionsType): IBotDefenderToken;
|
|
41
43
|
protected createRequestData(config: IConfiguration, request: IHttpRequest, cookieParser?: ICookieParser): RequestData;
|
|
44
|
+
protected getCookies(cookieParser: ICookieParser, ...cookieHeaderValues: string[]): Record<string, string>;
|
|
42
45
|
protected extractUserAgentFromHeader(config: IConfiguration, headers: HttpHeaders): string;
|
|
43
46
|
protected extractIpFromHeader(config: IConfiguration, headers: HttpHeaders): string;
|
|
44
47
|
protected isMonitored(config: IConfiguration, requestData: RequestData): boolean;
|
|
45
48
|
protected isSensitive(config: IConfiguration, { url }: RequestData): boolean;
|
|
46
49
|
protected isAllowedToBypassMonitor(config: IConfiguration, requestData: RequestData): boolean;
|
|
47
|
-
completeInitialization(): Promise<void>;
|
|
48
50
|
protected setRiskTokenOnContext(config: IConfiguration, options: OptionsType): void;
|
|
49
51
|
protected setMobileTokenOnContext(config: IConfiguration, mobileToken: string, options: OptionsType): void;
|
|
50
52
|
protected setWebTokenOnContext(config: IConfiguration, options: OptionsType): void;
|
|
51
53
|
protected setCookiesOnContext(): void;
|
|
52
54
|
protected getMobileToken(config: IConfiguration, mobileToken: string, options: OptionsType): IBotDefenderToken;
|
|
53
|
-
protected handleCustomParameters(config: IConfiguration, request: IHttpRequest): Promise<void>;
|
|
54
55
|
get isMobile(): boolean;
|
|
55
56
|
}
|
|
@@ -1,44 +1,7 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.ContextBase = void 0;
|
|
40
4
|
var block_handler_1 = require("../block_handler");
|
|
41
|
-
var custom_parameters_1 = require("../custom_parameters");
|
|
42
5
|
var http_1 = require("../http");
|
|
43
6
|
var risk_token_1 = require("../risk_token");
|
|
44
7
|
var utils_1 = require("../utils");
|
|
@@ -63,18 +26,28 @@ var ContextBase = /** @class */ (function () {
|
|
|
63
26
|
}
|
|
64
27
|
}
|
|
65
28
|
ContextBase.prototype.createRequestData = function (config, request, cookieParser) {
|
|
66
|
-
var _a;
|
|
29
|
+
var _a, _b;
|
|
67
30
|
if (cookieParser === void 0) { cookieParser = new utils_1.DefaultCookieParser(); }
|
|
68
31
|
var url = (0, utils_1.getDecodedUrl)(request.url);
|
|
69
32
|
var method = request.method;
|
|
70
33
|
var headers = request.headers;
|
|
71
|
-
var
|
|
72
|
-
var cookies = cookieHeaderValue ? cookieParser.parseCookies(cookieHeaderValue) : {};
|
|
34
|
+
var cookies = this.getCookies(cookieParser, (_a = request.headers.get(http_1.COOKIE_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0], (_b = request.headers.get(config.customCookieHeader)) === null || _b === void 0 ? void 0 : _b[0]);
|
|
73
35
|
var requestCookieNames = Object.keys(cookies);
|
|
74
36
|
var userAgent = this.extractUserAgentFromHeader(config, headers);
|
|
75
37
|
var ip = this.extractIpFromHeader(config, headers);
|
|
76
38
|
return { url: url, method: method, headers: headers, cookies: cookies, ip: ip, userAgent: userAgent, requestCookieNames: requestCookieNames, request: request };
|
|
77
39
|
};
|
|
40
|
+
ContextBase.prototype.getCookies = function (cookieParser) {
|
|
41
|
+
var cookieHeaderValues = [];
|
|
42
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
43
|
+
cookieHeaderValues[_i - 1] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
var cookies = {};
|
|
46
|
+
cookieHeaderValues.forEach(function (value) {
|
|
47
|
+
Object.assign(cookies, value ? cookieParser.parseCookies(value) : null);
|
|
48
|
+
});
|
|
49
|
+
return cookies;
|
|
50
|
+
};
|
|
78
51
|
ContextBase.prototype.extractUserAgentFromHeader = function (config, headers) {
|
|
79
52
|
var _a;
|
|
80
53
|
var userAgent = ((_a = headers === null || headers === void 0 ? void 0 : headers.get(http_1.USER_AGENT_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
@@ -111,18 +84,6 @@ var ContextBase = /** @class */ (function () {
|
|
|
111
84
|
return (config.bypassMonitorHeader &&
|
|
112
85
|
((_a = requestData.headers.get(config.bypassMonitorHeader)) === null || _a === void 0 ? void 0 : _a[0]) === utils_1.BYPASS_MONITOR_HEADER_VALUE);
|
|
113
86
|
};
|
|
114
|
-
ContextBase.prototype.completeInitialization = function () {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
-
return __generator(this, function (_a) {
|
|
117
|
-
switch (_a.label) {
|
|
118
|
-
case 0: return [4 /*yield*/, this.handleCustomParameters(this.config, this.requestData.request)];
|
|
119
|
-
case 1:
|
|
120
|
-
_a.sent();
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
87
|
ContextBase.prototype.setRiskTokenOnContext = function (config, options) {
|
|
127
88
|
var _a;
|
|
128
89
|
var mobileToken = (_a = this.requestData.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -169,31 +130,6 @@ var ContextBase = /** @class */ (function () {
|
|
|
169
130
|
return null;
|
|
170
131
|
}
|
|
171
132
|
};
|
|
172
|
-
ContextBase.prototype.handleCustomParameters = function (config, request) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
-
var _a, _b, _c, e_1;
|
|
175
|
-
return __generator(this, function (_d) {
|
|
176
|
-
switch (_d.label) {
|
|
177
|
-
case 0:
|
|
178
|
-
if (!(config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function')) return [3 /*break*/, 4];
|
|
179
|
-
_d.label = 1;
|
|
180
|
-
case 1:
|
|
181
|
-
_d.trys.push([1, 3, , 4]);
|
|
182
|
-
_a = this;
|
|
183
|
-
_c = (_b = custom_parameters_1.CustomParametersUtils).normalizeCustomParams;
|
|
184
|
-
return [4 /*yield*/, config.enrichCustomParameters(config.toParams(), request)];
|
|
185
|
-
case 2:
|
|
186
|
-
_a.customParameters = _c.apply(_b, [_d.sent()]);
|
|
187
|
-
return [3 /*break*/, 4];
|
|
188
|
-
case 3:
|
|
189
|
-
e_1 = _d.sent();
|
|
190
|
-
config.logger.error("unable to enrich custom params: ".concat(e_1));
|
|
191
|
-
return [3 /*break*/, 4];
|
|
192
|
-
case 4: return [2 /*return*/];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
133
|
Object.defineProperty(ContextBase.prototype, "isMobile", {
|
|
198
134
|
get: function () {
|
|
199
135
|
return this.tokenOrigin === risk_token_1.TokenOrigin.HEADER;
|
|
@@ -6,6 +6,7 @@ import { BlockAction, BlockReason } from '../block_handler';
|
|
|
6
6
|
import { HttpHeaders, HttpMethod, IHttpRequest } from '../http';
|
|
7
7
|
import { CustomParameters } from '../custom_parameters';
|
|
8
8
|
import { PXDE } from '../pxde';
|
|
9
|
+
import { GraphQLData } from '../graphql/model/GraphQLData';
|
|
9
10
|
export declare type RequestData = {
|
|
10
11
|
/**
|
|
11
12
|
* The request URL.
|
|
@@ -253,8 +254,8 @@ export interface IContext {
|
|
|
253
254
|
*/
|
|
254
255
|
customParameters?: CustomParameters;
|
|
255
256
|
/**
|
|
256
|
-
*
|
|
257
|
-
* the request
|
|
257
|
+
* An array of objects with information about the different GraphQL operations
|
|
258
|
+
* parsed from the request.
|
|
258
259
|
*/
|
|
259
|
-
|
|
260
|
+
graphqlData?: GraphQLData[];
|
|
260
261
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { IConfiguration } from '../config';
|
|
2
|
+
import { IContext } from '../context';
|
|
1
3
|
import { CustomParameters } from './CustomParameters';
|
|
2
4
|
export declare namespace CustomParametersUtils {
|
|
5
|
+
const handleCustomParameters: (config: IConfiguration, context: IContext) => Promise<void>;
|
|
3
6
|
const normalizeCustomParams: (customParameters: Record<string, any>) => CustomParameters;
|
|
4
7
|
}
|
|
@@ -1,8 +1,67 @@
|
|
|
1
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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.CustomParametersUtils = void 0;
|
|
4
40
|
var CustomParametersUtils;
|
|
5
41
|
(function (CustomParametersUtils) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
CustomParametersUtils.handleCustomParameters = function (config, context) { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
+
var parameters, e_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
if (!(config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function')) return [3 /*break*/, 4];
|
|
49
|
+
_a.label = 1;
|
|
50
|
+
case 1:
|
|
51
|
+
_a.trys.push([1, 3, , 4]);
|
|
52
|
+
return [4 /*yield*/, config.enrichCustomParameters(config.toParams(), context.requestData.request)];
|
|
53
|
+
case 2:
|
|
54
|
+
parameters = _a.sent();
|
|
55
|
+
context.customParameters = CustomParametersUtils.normalizeCustomParams(parameters);
|
|
56
|
+
return [3 /*break*/, 4];
|
|
57
|
+
case 3:
|
|
58
|
+
e_1 = _a.sent();
|
|
59
|
+
config.logger.error("unable to enrich custom params: ".concat(e_1));
|
|
60
|
+
return [3 /*break*/, 4];
|
|
61
|
+
case 4: return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); };
|
|
6
65
|
CustomParametersUtils.normalizeCustomParams = function (customParameters) {
|
|
7
66
|
var normalizedParams = {};
|
|
8
67
|
if (customParameters && typeof customParameters === 'object') {
|