perimeterx-js-core 0.2.0 → 0.4.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 +16 -9
- package/lib/activities/HttpActivityClient.d.ts +1 -1
- package/lib/activities/HttpActivityClient.js +7 -4
- package/lib/activities/HttpBatchedActivityClient.d.ts +1 -1
- package/lib/activities/model/ActivityDetails.d.ts +4 -2
- package/lib/activities/utils.js +2 -1
- package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/DefaultBlockResponseGenerator.js +7 -2
- package/lib/block_handler/IBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +6 -1
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +8 -4
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.js +6 -1
- package/lib/config/ConfigurationParams.d.ts +4 -0
- package/lib/config/DefaultConfigurations.js +9 -5
- package/lib/config/IConfiguration.d.ts +18 -0
- package/lib/config/StaticConfigurationBase.d.ts +4 -0
- package/lib/config/StaticConfigurationBase.js +28 -0
- package/lib/context/ContextBase.d.ts +9 -7
- package/lib/context/ContextBase.js +22 -89
- package/lib/context/DefaultTokenV2Context.d.ts +2 -2
- package/lib/context/DefaultTokenV2Context.js +1 -1
- package/lib/context/DefaultTokenV3Context.d.ts +2 -2
- package/lib/context/DefaultTokenV3Context.js +1 -1
- package/lib/context/IContext.d.ts +9 -6
- package/lib/custom_parameters/CustomParametersFunction.d.ts +2 -2
- package/lib/custom_parameters/CustomParametersUtils.d.ts +3 -0
- package/lib/custom_parameters/CustomParametersUtils.js +59 -0
- package/lib/enforcer/EnforcerBase.d.ts +20 -27
- package/lib/enforcer/EnforcerBase.js +54 -19
- package/lib/filter/DefaultFilter.js +1 -1
- package/lib/first_party/DefaultFirstParty.d.ts +3 -2
- package/lib/first_party/DefaultFirstParty.js +45 -35
- package/lib/first_party/IFirstParty.d.ts +2 -2
- package/lib/first_party/constants.d.ts +2 -9
- package/lib/first_party/constants.js +7 -9
- package/lib/graphql/DefaultGraphQLParser.d.ts +19 -0
- package/lib/graphql/DefaultGraphQLParser.js +179 -0
- package/lib/graphql/IGraphQLParser.d.ts +5 -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/GraphQLOperation.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperationType.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperationType.js +9 -0
- package/lib/http/impl/MinimalResponseImpl.d.ts +13 -0
- package/lib/http/impl/MinimalResponseImpl.js +12 -0
- package/lib/http/impl/OutgoingRequestImpl.d.ts +14 -0
- package/lib/http/impl/OutgoingRequestImpl.js +14 -0
- package/lib/http/impl/index.d.ts +2 -0
- package/lib/http/impl/index.js +18 -0
- package/lib/http/index.d.ts +2 -9
- package/lib/http/index.js +2 -11
- package/lib/http/interfaces/IBody.d.ts +26 -0
- package/lib/http/interfaces/IHttpClient.d.ts +8 -0
- package/lib/http/interfaces/IIncomingRequest.d.ts +23 -0
- package/lib/http/interfaces/IIncomingRequest.js +2 -0
- package/lib/http/interfaces/IIncomingResponse.d.ts +9 -0
- package/lib/http/interfaces/IIncomingResponse.js +2 -0
- package/lib/http/interfaces/IMinimalResponse.d.ts +6 -0
- package/lib/http/interfaces/IMinimalResponse.js +2 -0
- package/lib/http/interfaces/IOutgoingRequest.d.ts +11 -0
- package/lib/http/interfaces/IOutgoingRequest.js +2 -0
- package/lib/http/interfaces/IOutgoingResponse.d.ts +17 -0
- package/lib/http/interfaces/IOutgoingResponse.js +2 -0
- package/lib/http/interfaces/ReadOnlyHeaders.d.ts +3 -0
- package/lib/http/interfaces/ReadOnlyHeaders.js +25 -0
- package/lib/http/interfaces/index.d.ts +7 -0
- package/lib/http/interfaces/index.js +23 -0
- package/lib/http/utils/MinimalResponseUtils.d.ts +4 -0
- package/lib/http/utils/MinimalResponseUtils.js +39 -0
- package/lib/http/utils/index.d.ts +1 -3
- package/lib/http/utils/index.js +2 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pxde/IDataEnrichment.d.ts +1 -1
- package/lib/pxhd/PXHDUtils.d.ts +5 -2
- package/lib/pxhd/PXHDUtils.js +17 -2
- package/lib/risk_api/PostRiskApiClient.d.ts +3 -2
- package/lib/risk_api/PostRiskApiClient.js +20 -14
- package/lib/risk_api/S2SErrorHandler.d.ts +2 -2
- package/lib/risk_api/S2SErrorHandler.js +1 -1
- 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/IRiskResponseHandler.d.ts +2 -2
- package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.d.ts +2 -2
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +1 -0
- package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.js +12 -4
- package/lib/telemetry/DefaultTelemetry.d.ts +2 -1
- package/lib/telemetry/DefaultTelemetry.js +16 -7
- package/lib/utils/IScoreRetriever.d.ts +1 -1
- package/lib/utils/base64/{DefaultBase64Utils.d.ts → AtobBase64Utils.d.ts} +2 -2
- package/lib/utils/base64/AtobBase64Utils.js +15 -0
- package/lib/utils/base64/BufferBase64Utils.d.ts +6 -0
- package/lib/utils/base64/BufferBase64Utils.js +18 -0
- package/lib/utils/base64/JSBase64Base64Utils.d.ts +5 -0
- package/lib/utils/base64/JSBase64Base64Utils.js +16 -0
- package/lib/utils/base64/index.d.ts +4 -2
- package/lib/utils/base64/index.js +18 -3
- package/lib/utils/cipher/CryptoCipherUtils.d.ts +12 -0
- package/lib/{http/body_reader/StringBodyReader.js → utils/cipher/CryptoCipherUtils.js} +20 -25
- package/lib/utils/cipher/SubtleCryptoCipherUtils.d.ts +9 -0
- package/lib/utils/cipher/SubtleCryptoCipherUtils.js +94 -0
- package/lib/utils/cipher/index.d.ts +2 -0
- package/lib/utils/cipher/index.js +16 -0
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/hash/CryptoHmacUtils.d.ts +11 -0
- package/lib/utils/hash/CryptoHmacUtils.js +25 -0
- package/lib/utils/hash/{DefaultHashUtils.d.ts → CryptoJSHmacUtils.d.ts} +1 -1
- package/lib/utils/hash/CryptoJSHmacUtils.js +19 -0
- package/lib/utils/hash/index.d.ts +3 -2
- package/lib/utils/hash/index.js +17 -3
- package/lib/utils/utils.d.ts +1 -2
- package/lib/utils/utils.js +15 -4
- package/package.json +1 -2
- package/lib/http/IHttpClient.d.ts +0 -14
- package/lib/http/body_reader/IBodyReader.d.ts +0 -5
- package/lib/http/body_reader/StringBodyReader.d.ts +0 -8
- package/lib/http/request/DefaultHttpRequest.d.ts +0 -5
- package/lib/http/request/DefaultHttpRequest.js +0 -42
- package/lib/http/request/HttpRequestBase.d.ts +0 -24
- package/lib/http/request/HttpRequestBase.js +0 -77
- package/lib/http/request/IHttpRequest.d.ts +0 -31
- package/lib/http/response/DefaultHttpResponse.d.ts +0 -5
- package/lib/http/response/DefaultHttpResponse.js +0 -32
- package/lib/http/response/HttpResponseBase.d.ts +0 -17
- package/lib/http/response/HttpResponseBase.js +0 -75
- package/lib/http/response/IHttpResponse.d.ts +0 -26
- package/lib/http/utils/HttpBody.d.ts +0 -4
- package/lib/http/utils/HttpHeaders.d.ts +0 -51
- package/lib/http/utils/HttpHeaders.js +0 -106
- package/lib/utils/base64/DefaultBase64Utils.js +0 -16
- package/lib/utils/hash/DefaultHashUtils.js +0 -19
- /package/lib/{http/IHttpClient.js → graphql/IGraphQLParser.js} +0 -0
- /package/lib/{http/body_reader/IBodyReader.js → graphql/model/GraphQLData.js} +0 -0
- /package/lib/{http/request/IHttpRequest.js → graphql/model/GraphQLOperation.js} +0 -0
- /package/lib/http/{response/IHttpResponse.js → interfaces/IBody.js} +0 -0
- /package/lib/http/{utils/HttpBody.js → interfaces/IHttpClient.js} +0 -0
package/README.md
CHANGED
|
@@ -100,17 +100,24 @@ or use an external library (e.g., `phin`, `axios`) if needed.
|
|
|
100
100
|
|
|
101
101
|
### Crypto
|
|
102
102
|
|
|
103
|
-
Since cryptographic functionality varies from platform to platform, this library's crypto utils takes the form of
|
|
103
|
+
Since cryptographic functionality varies from platform to platform, this library's crypto utils takes the form of interfaces
|
|
104
104
|
as well.
|
|
105
105
|
|
|
106
|
-
`IBase64Utils` - Represents a Base64 encoding and decoding utility that other components may require.
|
|
107
|
-
|
|
106
|
+
`IBase64Utils` - Represents a Base64 encoding and decoding utility that other components may require. The following implementations
|
|
107
|
+
are provided:
|
|
108
|
+
* `AtobBase64Utils`, which relies on native `atob` and `btoa` functions.
|
|
109
|
+
* `BufferBase64Utils`, which relies on the native NodeJS `Buffer.from()` function.
|
|
110
|
+
* `JSBase64Base64Utils`, which uses the `js-base64` dependency.
|
|
108
111
|
|
|
109
|
-
`IHashUtils` - Represents an HMAC-generating utility that other components may require.
|
|
110
|
-
|
|
112
|
+
`IHashUtils` - Represents an HMAC-generating utility that other components may require. The following implementations are
|
|
113
|
+
provided:
|
|
114
|
+
* `CryptoHmacUtils`, which relies on the native NodeJS `crypto` package.
|
|
115
|
+
* `CryptoJSHmacUtils`, which uses the `crypto-js` dependency.
|
|
111
116
|
|
|
112
|
-
`ICipherUtils` - Represents an encryption and decryption utility that is required for RiskTokenV3.
|
|
113
|
-
|
|
117
|
+
`ICipherUtils` - Represents an encryption and decryption utility that is required for RiskTokenV3. The following implementations
|
|
118
|
+
are provided:
|
|
119
|
+
* `CryptoCipherUtils`, which relies on the native NodeJS `crypto` package.
|
|
120
|
+
* `SubtleCryptoCipherUtils`, which relies on an object implementing the `SubtleCrypto` interface. By default, it is assumed that the global `crypto.subtle` implements this interface.
|
|
114
121
|
|
|
115
122
|
### Other Dependencies
|
|
116
123
|
|
|
@@ -119,8 +126,8 @@ can be swapped with other implementations. These classes are:
|
|
|
119
126
|
|
|
120
127
|
| **Library** | **Implementation** | **Used For** |
|
|
121
128
|
| :--- | :--- | :--- |
|
|
122
|
-
| `crypto-js` | `
|
|
123
|
-
| `js-base64` | `
|
|
129
|
+
| `crypto-js` | `CryptoJSHmacUtils` | PXDE, telemetry, risk token V2/V3, etc. |
|
|
130
|
+
| `js-base64` | `JSBase64Base64Utils` | PXDE, telemetry, risk token V2, etc. |
|
|
124
131
|
| `cookie` | `DefaultCookieParser` | `ContextBase` |
|
|
125
132
|
| `uuid` | `DefaultUuidGenerator` | `ContextBase` |
|
|
126
133
|
| `ip-range-check` | `DefaultIpRangeChecker` | `DefaultFilter` |
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
2
|
import { IContext } from '../context';
|
|
3
|
-
import { IHttpClient } from '../http';
|
|
4
3
|
import { IActivityClient } from './IActivityClient';
|
|
5
4
|
import { Activity } from './model/Activity';
|
|
5
|
+
import { IHttpClient } from '../http';
|
|
6
6
|
export declare class HttpActivityClient implements IActivityClient {
|
|
7
7
|
private readonly config;
|
|
8
8
|
private readonly httpClient;
|
|
@@ -42,6 +42,8 @@ var utils_1 = require("../utils");
|
|
|
42
42
|
var ActivityType_1 = require("./ActivityType");
|
|
43
43
|
var utils_2 = require("./utils");
|
|
44
44
|
var constants_1 = require("./constants");
|
|
45
|
+
var http_2 = require("../http");
|
|
46
|
+
var http_3 = require("../http");
|
|
45
47
|
var HttpActivityClient = /** @class */ (function () {
|
|
46
48
|
function HttpActivityClient(config, httpClient) {
|
|
47
49
|
this.config = config;
|
|
@@ -87,13 +89,13 @@ var HttpActivityClient = /** @class */ (function () {
|
|
|
87
89
|
};
|
|
88
90
|
HttpActivityClient.prototype.postActivities = function (activities) {
|
|
89
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var url, method, headers, body, status;
|
|
92
|
+
var url, method, headers, body, req, status;
|
|
91
93
|
var _a;
|
|
92
94
|
return __generator(this, function (_b) {
|
|
93
95
|
switch (_b.label) {
|
|
94
96
|
case 0:
|
|
95
97
|
url = "".concat(this.config.backendCollectorUrl).concat(constants_1.ACTIVITIES_ENDPOINT);
|
|
96
|
-
method =
|
|
98
|
+
method = http_2.HttpMethod.POST;
|
|
97
99
|
headers = (_a = {},
|
|
98
100
|
_a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.APPLICATION_JSON],
|
|
99
101
|
_a[http_1.AUTHORIZATION_HEADER_NAME] = [(0, utils_1.getAuthorizationHeader)(this.config.authToken)],
|
|
@@ -103,9 +105,10 @@ var HttpActivityClient = /** @class */ (function () {
|
|
|
103
105
|
var type = _a.type;
|
|
104
106
|
return "".concat(type, " activity");
|
|
105
107
|
}).join(', '), " to ").concat(url));
|
|
106
|
-
|
|
108
|
+
req = new http_3.OutgoingRequestImpl({ url: url, method: method, headers: headers, body: body });
|
|
109
|
+
return [4 /*yield*/, this.httpClient.send(req).then(function (resp) { return resp.status; })];
|
|
107
110
|
case 1:
|
|
108
|
-
status =
|
|
111
|
+
status = _b.sent();
|
|
109
112
|
return [2 /*return*/, status === 200];
|
|
110
113
|
}
|
|
111
114
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpActivityClient } from './HttpActivityClient';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
|
-
import { IHttpClient } from '../http';
|
|
4
3
|
import { Activity } from './model/Activity';
|
|
4
|
+
import { IHttpClient } from '../http';
|
|
5
5
|
export declare class HttpBatchedActivityClient extends HttpActivityClient {
|
|
6
6
|
private readonly batchSize;
|
|
7
7
|
private readonly timeoutMs;
|
|
@@ -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)
|
|
11
|
+
headers: (0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders),
|
|
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',
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IContext } from '../context';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
|
-
import { IHttpResponse } from '../http';
|
|
4
3
|
import { IBase64Utils } from '../utils';
|
|
5
4
|
import { IBlockResponseGenerator } from './IBlockResponseGenerator';
|
|
5
|
+
import { IMinimalResponse } from '../http';
|
|
6
6
|
export declare class DefaultBlockResponseGenerator implements IBlockResponseGenerator {
|
|
7
7
|
private readonly config;
|
|
8
8
|
private readonly captchaResponseGenerator;
|
|
9
9
|
constructor(config: IConfiguration, base64Utils: IBase64Utils);
|
|
10
10
|
shouldGenerate(context: IContext): boolean;
|
|
11
|
-
generateBlockResponse(context: IContext):
|
|
11
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
12
12
|
private generateRateLimitResponse;
|
|
13
13
|
private generateCaptchaResponse;
|
|
14
14
|
}
|
|
@@ -6,6 +6,7 @@ var http_1 = require("../http");
|
|
|
6
6
|
var BlockAction_1 = require("./BlockAction");
|
|
7
7
|
var CaptchaBlockResponseGenerator_1 = require("./captcha/CaptchaBlockResponseGenerator");
|
|
8
8
|
var rate_limit_template_1 = require("./templates/rate_limit_template");
|
|
9
|
+
var http_2 = require("../http");
|
|
9
10
|
var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
10
11
|
function DefaultBlockResponseGenerator(config, base64Utils) {
|
|
11
12
|
this.config = config;
|
|
@@ -26,7 +27,7 @@ var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
|
26
27
|
res = this.generateCaptchaResponse(context);
|
|
27
28
|
break;
|
|
28
29
|
}
|
|
29
|
-
return pxhd_1.PXHDUtils.
|
|
30
|
+
return pxhd_1.PXHDUtils.addPxhdToMinimalResponse(context, res);
|
|
30
31
|
};
|
|
31
32
|
DefaultBlockResponseGenerator.prototype.generateRateLimitResponse = function () {
|
|
32
33
|
var _a;
|
|
@@ -34,7 +35,11 @@ var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
|
34
35
|
var headers = (_a = {},
|
|
35
36
|
_a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
|
|
36
37
|
_a);
|
|
37
|
-
return new
|
|
38
|
+
return new http_2.MinimalResponseImpl({
|
|
39
|
+
body: rate_limit_template_1.RATE_LIMIT_TEMPLATE,
|
|
40
|
+
status: status,
|
|
41
|
+
headers: headers,
|
|
42
|
+
});
|
|
38
43
|
};
|
|
39
44
|
DefaultBlockResponseGenerator.prototype.generateCaptchaResponse = function (context) {
|
|
40
45
|
return this.captchaResponseGenerator.generateBlockResponse(context);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IContext } from '../context';
|
|
2
|
-
import {
|
|
2
|
+
import { IMinimalResponse } from '../http';
|
|
3
3
|
export interface IBlockResponseGenerator {
|
|
4
4
|
/**
|
|
5
5
|
* @param context - The request context.
|
|
@@ -10,5 +10,5 @@ export interface IBlockResponseGenerator {
|
|
|
10
10
|
* @param context - The request context.
|
|
11
11
|
* @returns IHttpResponse - The block response that should be returned to the end-user.
|
|
12
12
|
*/
|
|
13
|
-
generateBlockResponse(context: IContext):
|
|
13
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
14
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IHttpResponse } from '../../http';
|
|
4
3
|
import { IBase64Utils } from '../../utils';
|
|
5
4
|
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
5
|
+
import { IMinimalResponse } from '../../http';
|
|
6
6
|
export declare class CaptchaBlockResponseGenerator implements IBlockResponseGenerator {
|
|
7
7
|
private readonly config;
|
|
8
8
|
private readonly jsonCaptchaGenerator;
|
|
@@ -10,5 +10,5 @@ export declare class CaptchaBlockResponseGenerator implements IBlockResponseGene
|
|
|
10
10
|
private readonly htmlCaptchaGenerator;
|
|
11
11
|
constructor(config: IConfiguration, base64Utils: IBase64Utils);
|
|
12
12
|
shouldGenerate({ blockAction }: IContext): boolean;
|
|
13
|
-
generateBlockResponse(context: IContext):
|
|
13
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
14
14
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IHttpResponse } from '../../http';
|
|
4
3
|
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
4
|
+
import { IMinimalResponse } from '../../http';
|
|
5
5
|
export declare class HtmlCaptchaResponseGenerator implements IBlockResponseGenerator {
|
|
6
6
|
private readonly config;
|
|
7
7
|
constructor(config: IConfiguration);
|
|
8
8
|
shouldGenerate(context: IContext): boolean;
|
|
9
|
-
generateBlockResponse(context: IContext):
|
|
9
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
10
10
|
}
|
|
@@ -4,6 +4,7 @@ exports.HtmlCaptchaResponseGenerator = void 0;
|
|
|
4
4
|
var http_1 = require("../../http");
|
|
5
5
|
var utils_1 = require("../utils");
|
|
6
6
|
var captcha_template_1 = require("../templates/captcha_template");
|
|
7
|
+
var http_2 = require("../../http");
|
|
7
8
|
var HtmlCaptchaResponseGenerator = /** @class */ (function () {
|
|
8
9
|
function HtmlCaptchaResponseGenerator(config) {
|
|
9
10
|
this.config = config;
|
|
@@ -18,7 +19,11 @@ var HtmlCaptchaResponseGenerator = /** @class */ (function () {
|
|
|
18
19
|
_a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
|
|
19
20
|
_a);
|
|
20
21
|
var body = (0, utils_1.renderHtml)(captcha_template_1.CAPTCHA_TEMPLATE, (0, utils_1.createBlockData)(this.config, context));
|
|
21
|
-
return new
|
|
22
|
+
return new http_2.MinimalResponseImpl({
|
|
23
|
+
body: body,
|
|
24
|
+
status: status,
|
|
25
|
+
headers: headers,
|
|
26
|
+
});
|
|
22
27
|
};
|
|
23
28
|
return HtmlCaptchaResponseGenerator;
|
|
24
29
|
}());
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IHttpResponse } from '../../http';
|
|
4
3
|
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
4
|
+
import { IMinimalResponse } from '../../http';
|
|
5
5
|
export declare class JsonCaptchaResponseGenerator implements IBlockResponseGenerator {
|
|
6
6
|
private readonly config;
|
|
7
7
|
constructor(config: IConfiguration);
|
|
8
8
|
shouldGenerate(context: IContext): boolean;
|
|
9
|
-
generateBlockResponse(context: IContext):
|
|
9
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
10
10
|
}
|
|
@@ -4,17 +4,17 @@ exports.JsonCaptchaResponseGenerator = void 0;
|
|
|
4
4
|
var BlockAction_1 = require("../BlockAction");
|
|
5
5
|
var http_1 = require("../../http");
|
|
6
6
|
var utils_1 = require("../utils");
|
|
7
|
+
var http_2 = require("../../http");
|
|
7
8
|
var JsonCaptchaResponseGenerator = /** @class */ (function () {
|
|
8
9
|
function JsonCaptchaResponseGenerator(config) {
|
|
9
10
|
this.config = config;
|
|
10
11
|
}
|
|
11
12
|
JsonCaptchaResponseGenerator.prototype.shouldGenerate = function (context) {
|
|
12
|
-
var _a, _b;
|
|
13
13
|
if (!this.config.advancedBlockingResponseEnabled) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
var acceptHeaderValue =
|
|
17
|
-
|
|
16
|
+
var acceptHeaderValue = context.requestData.request.headers.get(http_1.ACCEPT_HEADER_NAME) ||
|
|
17
|
+
context.requestData.request.headers.get(http_1.CONTENT_TYPE_HEADER_NAME) ||
|
|
18
18
|
'';
|
|
19
19
|
var acceptHeaderContainsJson = acceptHeaderValue === null || acceptHeaderValue === void 0 ? void 0 : acceptHeaderValue.split(',').some(function (value) { return value.toLowerCase() === http_1.ContentType.APPLICATION_JSON; });
|
|
20
20
|
return !context.isMobile && context.blockAction !== BlockAction_1.BlockAction.RATE_LIMIT && acceptHeaderContainsJson;
|
|
@@ -37,7 +37,11 @@ var JsonCaptchaResponseGenerator = /** @class */ (function () {
|
|
|
37
37
|
blockScript: blockData.blockScript,
|
|
38
38
|
altBlockScript: blockData.altBlockScript,
|
|
39
39
|
};
|
|
40
|
-
return new
|
|
40
|
+
return new http_2.MinimalResponseImpl({
|
|
41
|
+
body: JSON.stringify(jsonBlockPayload),
|
|
42
|
+
status: status,
|
|
43
|
+
headers: headers,
|
|
44
|
+
});
|
|
41
45
|
};
|
|
42
46
|
return JsonCaptchaResponseGenerator;
|
|
43
47
|
}());
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IHttpResponse } from '../../http';
|
|
4
3
|
import { IBase64Utils } from '../../utils';
|
|
5
4
|
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
5
|
+
import { IMinimalResponse } from '../../http';
|
|
6
6
|
export declare class MobileCaptchaResponseGenerator implements IBlockResponseGenerator {
|
|
7
7
|
private readonly config;
|
|
8
8
|
private readonly base64Utils;
|
|
9
9
|
constructor(config: IConfiguration, base64Utils: IBase64Utils);
|
|
10
10
|
shouldGenerate(context: IContext): boolean;
|
|
11
|
-
generateBlockResponse(context: IContext):
|
|
11
|
+
generateBlockResponse(context: IContext): IMinimalResponse;
|
|
12
12
|
}
|
|
@@ -5,6 +5,7 @@ var http_1 = require("../../http");
|
|
|
5
5
|
var BlockAction_1 = require("../BlockAction");
|
|
6
6
|
var utils_1 = require("../utils");
|
|
7
7
|
var captcha_template_1 = require("../templates/captcha_template");
|
|
8
|
+
var http_2 = require("../../http");
|
|
8
9
|
var MobileCaptchaResponseGenerator = /** @class */ (function () {
|
|
9
10
|
function MobileCaptchaResponseGenerator(config, base64Utils) {
|
|
10
11
|
this.config = config;
|
|
@@ -29,7 +30,11 @@ var MobileCaptchaResponseGenerator = /** @class */ (function () {
|
|
|
29
30
|
page: this.base64Utils.base64Encode(captchaPage),
|
|
30
31
|
collectorHost: this.config.backendCollectorUrl,
|
|
31
32
|
};
|
|
32
|
-
return new
|
|
33
|
+
return new http_2.MinimalResponseImpl({
|
|
34
|
+
body: JSON.stringify(mobileBlockPayload),
|
|
35
|
+
status: status,
|
|
36
|
+
headers: headers,
|
|
37
|
+
});
|
|
33
38
|
};
|
|
34
39
|
return MobileCaptchaResponseGenerator;
|
|
35
40
|
}());
|
|
@@ -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;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_CONFIGURATIONS = void 0;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var logger_1 = require("../logger");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
6
|
exports.DEFAULT_CONFIGURATIONS = {
|
|
7
7
|
px_app_id: '',
|
|
8
8
|
px_auth_token: '',
|
|
@@ -13,11 +13,11 @@ exports.DEFAULT_CONFIGURATIONS = {
|
|
|
13
13
|
px_risk_cookie_max_length: 2048,
|
|
14
14
|
px_risk_cookie_min_iterations: 500,
|
|
15
15
|
px_risk_cookie_max_iterations: 5000,
|
|
16
|
-
px_logger_severity:
|
|
16
|
+
px_logger_severity: logger_1.LoggerSeverity.ERROR,
|
|
17
17
|
px_ip_headers: [],
|
|
18
18
|
px_extract_ip: null,
|
|
19
19
|
px_module_enabled: true,
|
|
20
|
-
px_module_mode:
|
|
20
|
+
px_module_mode: utils_1.ModuleMode.MONITOR,
|
|
21
21
|
px_additional_activity_handler: null,
|
|
22
22
|
px_advanced_blocking_response_enabled: true,
|
|
23
23
|
px_max_activity_batch_size: 0,
|
|
@@ -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: '',
|
|
@@ -165,6 +165,24 @@ export interface IConfiguration<ParamsType extends ConfigurationParams = Configu
|
|
|
165
165
|
* The maximum amount of time to wait before sending asynchronous activities to the collector.
|
|
166
166
|
*/
|
|
167
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[];
|
|
168
186
|
/**
|
|
169
187
|
* A function returning CustomParameters that will be added to the enforcer activities.
|
|
170
188
|
*/
|
|
@@ -53,6 +53,10 @@ export declare abstract class StaticConfigurationBase<ParamsType extends Configu
|
|
|
53
53
|
get userAgentMaxLength(): number;
|
|
54
54
|
get maxActivityBatchSize(): number;
|
|
55
55
|
get activityBatchTimeoutMs(): number;
|
|
56
|
+
get graphqlEnabled(): boolean;
|
|
57
|
+
get graphqlRoutes(): string[];
|
|
58
|
+
get sensitiveGraphqlOperationNames(): string[];
|
|
59
|
+
get sensitiveGraphqlOperationTypes(): string[];
|
|
56
60
|
get enrichCustomParameters(): CustomParametersFunction;
|
|
57
61
|
get additionalActivityHandler(): AdditionalActivityHandler;
|
|
58
62
|
get altBackendCaptchaUrl(): string;
|
|
@@ -343,6 +343,34 @@ var StaticConfigurationBase = /** @class */ (function () {
|
|
|
343
343
|
enumerable: false,
|
|
344
344
|
configurable: true
|
|
345
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
|
+
});
|
|
346
374
|
Object.defineProperty(StaticConfigurationBase.prototype, "enrichCustomParameters", {
|
|
347
375
|
get: function () {
|
|
348
376
|
return this.configParams.px_enrich_custom_parameters || null;
|
|
@@ -2,11 +2,13 @@ import { IConfiguration } from '../config';
|
|
|
2
2
|
import { BlockReason, BlockAction } from '../block_handler';
|
|
3
3
|
import { CustomParameters } from '../custom_parameters';
|
|
4
4
|
import { FilterReason } from '../filter';
|
|
5
|
-
import { IHttpRequest, HttpHeaders } from '../http';
|
|
6
5
|
import { PXDE } from '../pxde';
|
|
6
|
+
import { GraphQLData } from '../graphql';
|
|
7
7
|
import { IBotDefenderToken, TokenOrigin } from '../risk_token';
|
|
8
8
|
import { VidSource, PassReason, ICookieParser, IUuidGenerator } from '../utils';
|
|
9
9
|
import { IContext, MobileData, RequestData, ResponseData, RiskApiData, ServerData, TlsData } from './IContext';
|
|
10
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
11
|
+
import { ReadOnlyHeaders } from '../http';
|
|
10
12
|
export declare type ContextBaseOptions = {
|
|
11
13
|
cookieParser?: ICookieParser;
|
|
12
14
|
uuidGenerator?: IUuidGenerator;
|
|
@@ -35,21 +37,21 @@ export declare abstract class ContextBase<OptionsType extends ContextBaseOptions
|
|
|
35
37
|
pxde?: PXDE;
|
|
36
38
|
pxdeVerified?: boolean;
|
|
37
39
|
customParameters?: CustomParameters;
|
|
40
|
+
graphqlData?: GraphQLData[];
|
|
38
41
|
protected readonly config: IConfiguration;
|
|
39
|
-
protected constructor(config: IConfiguration, request:
|
|
42
|
+
protected constructor(config: IConfiguration, request: IIncomingRequest, options?: OptionsType);
|
|
40
43
|
protected abstract createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: OptionsType): IBotDefenderToken;
|
|
41
|
-
protected createRequestData(config: IConfiguration, request:
|
|
42
|
-
protected
|
|
43
|
-
protected
|
|
44
|
+
protected createRequestData(config: IConfiguration, request: IIncomingRequest, cookieParser?: ICookieParser): RequestData;
|
|
45
|
+
protected getCookies(cookieParser: ICookieParser, ...cookieHeaderValues: string[]): Record<string, string>;
|
|
46
|
+
protected extractUserAgentFromHeader(config: IConfiguration, headers: ReadOnlyHeaders): string;
|
|
47
|
+
protected extractIpFromHeader(config: IConfiguration, headers: ReadOnlyHeaders): string;
|
|
44
48
|
protected isMonitored(config: IConfiguration, requestData: RequestData): boolean;
|
|
45
49
|
protected isSensitive(config: IConfiguration, { url }: RequestData): boolean;
|
|
46
50
|
protected isAllowedToBypassMonitor(config: IConfiguration, requestData: RequestData): boolean;
|
|
47
|
-
completeInitialization(): Promise<void>;
|
|
48
51
|
protected setRiskTokenOnContext(config: IConfiguration, options: OptionsType): void;
|
|
49
52
|
protected setMobileTokenOnContext(config: IConfiguration, mobileToken: string, options: OptionsType): void;
|
|
50
53
|
protected setWebTokenOnContext(config: IConfiguration, options: OptionsType): void;
|
|
51
54
|
protected setCookiesOnContext(): void;
|
|
52
55
|
protected getMobileToken(config: IConfiguration, mobileToken: string, options: OptionsType): IBotDefenderToken;
|
|
53
|
-
protected handleCustomParameters(config: IConfiguration, request: IHttpRequest): Promise<void>;
|
|
54
56
|
get isMobile(): boolean;
|
|
55
57
|
}
|