perimeterx-js-core 0.3.0 → 0.4.1
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 +24 -20
- 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/utils.js +1 -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/DefaultConfigurations.js +4 -4
- package/lib/context/ContextBase.d.ts +6 -5
- package/lib/context/ContextBase.js +11 -14
- 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 +6 -4
- package/lib/custom_parameters/CustomParametersFunction.d.ts +2 -2
- package/lib/enforcer/EnforcerBase.d.ts +14 -26
- package/lib/enforcer/EnforcerBase.js +13 -12
- package/lib/filter/DefaultFilter.js +1 -1
- package/lib/first_party/DefaultFirstParty.d.ts +3 -2
- package/lib/first_party/DefaultFirstParty.js +44 -34
- 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.js +7 -11
- 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/IIncomingResponse.d.ts +9 -0
- package/lib/http/interfaces/IMinimalResponse.d.ts +6 -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 +8 -0
- package/lib/http/interfaces/index.js +24 -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/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 +14 -11
- package/lib/risk_api/S2SErrorHandler.d.ts +2 -2
- package/lib/risk_api/S2SErrorHandler.js +1 -1
- 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_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 +14 -3
- package/package.json +1 -1
- 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 -53
- package/lib/http/utils/HttpHeaders.js +0 -123
- package/lib/utils/base64/DefaultBase64Utils.js +0 -16
- package/lib/utils/hash/DefaultHashUtils.js +0 -19
- /package/lib/http/{IHttpClient.js → interfaces/IBody.js} +0 -0
- /package/lib/http/{body_reader/IBodyReader.js → interfaces/IHttpClient.js} +0 -0
- /package/lib/http/{request/IHttpRequest.js → interfaces/IIncomingRequest.js} +0 -0
- /package/lib/http/{response/IHttpResponse.js → interfaces/IIncomingResponse.js} +0 -0
- /package/lib/http/{utils/HttpBody.js → interfaces/IMinimalResponse.js} +0 -0
package/README.md
CHANGED
|
@@ -77,40 +77,44 @@ While you will need to create a custom implementation for the request context, y
|
|
|
77
77
|
### HTTP
|
|
78
78
|
|
|
79
79
|
Every framework has a different API for creating and sending HTTP requests and responses. This library reduces this functionality
|
|
80
|
-
into
|
|
80
|
+
into several interfaces:
|
|
81
81
|
|
|
82
|
-
`
|
|
82
|
+
`IIncomingRequest` - Represents an HTTP request from the user.
|
|
83
83
|
|
|
84
|
-
`
|
|
84
|
+
`IOutgoingResponse` - Represents an HTTP response which is returned to the user.
|
|
85
85
|
|
|
86
|
-
`
|
|
86
|
+
`IOutgoingRequest` - Represents an HTTP request that can be executed (sent to other origin)
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
objects such that they conform to these interfaces. Of course, you are free to extend these interfaces as needed.
|
|
88
|
+
`IIncomingResponse` - Represents an HTTP response that received from sending `IOutgoingRequest`
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
encapsulating request and response body handling to a single `IBodyReader` interface.
|
|
90
|
+
`IHttpClient` - Represents a client that can send an `IIncomingRequest` and return an `IOutgoingResponse`.
|
|
93
91
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class to parse request and response bodies provided as strings.
|
|
92
|
+
When developing your JavaScript/TypeScript enforcer with this library, you will need to wrap the native HTTP request/response
|
|
93
|
+
objects such that they conform to these interfaces. Of course, you are free to extend these interfaces as needed.
|
|
97
94
|
|
|
98
95
|
You will also need to implement an HTTP client. You can do this however you see fit: use the platform's built-in API
|
|
99
96
|
or use an external library (e.g., `phin`, `axios`) if needed.
|
|
100
97
|
|
|
101
98
|
### Crypto
|
|
102
99
|
|
|
103
|
-
Since cryptographic functionality varies from platform to platform, this library's crypto utils takes the form of
|
|
100
|
+
Since cryptographic functionality varies from platform to platform, this library's crypto utils takes the form of interfaces
|
|
104
101
|
as well.
|
|
105
102
|
|
|
106
|
-
`IBase64Utils` - Represents a Base64 encoding and decoding utility that other components may require.
|
|
107
|
-
|
|
103
|
+
`IBase64Utils` - Represents a Base64 encoding and decoding utility that other components may require. The following implementations
|
|
104
|
+
are provided:
|
|
105
|
+
* `AtobBase64Utils`, which relies on native `atob` and `btoa` functions.
|
|
106
|
+
* `BufferBase64Utils`, which relies on the native NodeJS `Buffer.from()` function.
|
|
107
|
+
* `JSBase64Base64Utils`, which uses the `js-base64` dependency.
|
|
108
108
|
|
|
109
|
-
`IHashUtils` - Represents an HMAC-generating utility that other components may require.
|
|
110
|
-
|
|
109
|
+
`IHashUtils` - Represents an HMAC-generating utility that other components may require. The following implementations are
|
|
110
|
+
provided:
|
|
111
|
+
* `CryptoHmacUtils`, which relies on the native NodeJS `crypto` package.
|
|
112
|
+
* `CryptoJSHmacUtils`, which uses the `crypto-js` dependency.
|
|
111
113
|
|
|
112
|
-
`ICipherUtils` - Represents an encryption and decryption utility that is required for RiskTokenV3.
|
|
113
|
-
|
|
114
|
+
`ICipherUtils` - Represents an encryption and decryption utility that is required for RiskTokenV3. The following implementations
|
|
115
|
+
are provided:
|
|
116
|
+
* `CryptoCipherUtils`, which relies on the native NodeJS `crypto` package.
|
|
117
|
+
* `SubtleCryptoCipherUtils`, which relies on an object implementing the `SubtleCrypto` interface. By default, it is assumed that the global `crypto.subtle` implements this interface.
|
|
114
118
|
|
|
115
119
|
### Other Dependencies
|
|
116
120
|
|
|
@@ -119,8 +123,8 @@ can be swapped with other implementations. These classes are:
|
|
|
119
123
|
|
|
120
124
|
| **Library** | **Implementation** | **Used For** |
|
|
121
125
|
| :--- | :--- | :--- |
|
|
122
|
-
| `crypto-js` | `
|
|
123
|
-
| `js-base64` | `
|
|
126
|
+
| `crypto-js` | `CryptoJSHmacUtils` | PXDE, telemetry, risk token V2/V3, etc. |
|
|
127
|
+
| `js-base64` | `JSBase64Base64Utils` | PXDE, telemetry, risk token V2, etc. |
|
|
124
128
|
| `cookie` | `DefaultCookieParser` | `ContextBase` |
|
|
125
129
|
| `uuid` | `DefaultUuidGenerator` | `ContextBase` |
|
|
126
130
|
| `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;
|
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(),
|
|
@@ -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
|
}());
|
|
@@ -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,
|
|
@@ -2,12 +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';
|
|
7
6
|
import { GraphQLData } from '../graphql';
|
|
8
7
|
import { IBotDefenderToken, TokenOrigin } from '../risk_token';
|
|
9
8
|
import { VidSource, PassReason, ICookieParser, IUuidGenerator } from '../utils';
|
|
10
9
|
import { IContext, MobileData, RequestData, ResponseData, RiskApiData, ServerData, TlsData } from './IContext';
|
|
10
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
11
|
+
import { ReadOnlyHeaders } from '../http';
|
|
11
12
|
export declare type ContextBaseOptions = {
|
|
12
13
|
cookieParser?: ICookieParser;
|
|
13
14
|
uuidGenerator?: IUuidGenerator;
|
|
@@ -38,12 +39,12 @@ export declare abstract class ContextBase<OptionsType extends ContextBaseOptions
|
|
|
38
39
|
customParameters?: CustomParameters;
|
|
39
40
|
graphqlData?: GraphQLData[];
|
|
40
41
|
protected readonly config: IConfiguration;
|
|
41
|
-
protected constructor(config: IConfiguration, request:
|
|
42
|
+
protected constructor(config: IConfiguration, request: IIncomingRequest, options?: OptionsType);
|
|
42
43
|
protected abstract createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: OptionsType): IBotDefenderToken;
|
|
43
|
-
protected createRequestData(config: IConfiguration, request:
|
|
44
|
+
protected createRequestData(config: IConfiguration, request: IIncomingRequest, cookieParser?: ICookieParser): RequestData;
|
|
44
45
|
protected getCookies(cookieParser: ICookieParser, ...cookieHeaderValues: string[]): Record<string, string>;
|
|
45
|
-
protected extractUserAgentFromHeader(config: IConfiguration, headers:
|
|
46
|
-
protected extractIpFromHeader(config: IConfiguration, headers:
|
|
46
|
+
protected extractUserAgentFromHeader(config: IConfiguration, headers: ReadOnlyHeaders): string;
|
|
47
|
+
protected extractIpFromHeader(config: IConfiguration, headers: ReadOnlyHeaders): string;
|
|
47
48
|
protected isMonitored(config: IConfiguration, requestData: RequestData): boolean;
|
|
48
49
|
protected isSensitive(config: IConfiguration, { url }: RequestData): boolean;
|
|
49
50
|
protected isAllowedToBypassMonitor(config: IConfiguration, requestData: RequestData): boolean;
|
|
@@ -26,16 +26,16 @@ var ContextBase = /** @class */ (function () {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
ContextBase.prototype.createRequestData = function (config, request, cookieParser) {
|
|
29
|
-
var _a, _b;
|
|
30
29
|
if (cookieParser === void 0) { cookieParser = new utils_1.DefaultCookieParser(); }
|
|
31
30
|
var url = (0, utils_1.getDecodedUrl)(request.url);
|
|
32
31
|
var method = request.method;
|
|
33
32
|
var headers = request.headers;
|
|
34
|
-
var cookies = this.getCookies(cookieParser,
|
|
33
|
+
var cookies = this.getCookies(cookieParser, request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
|
|
35
34
|
var requestCookieNames = Object.keys(cookies);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
35
|
+
var readOnlyHeaders = (0, http_1.toReadOnlyHeaders)(headers);
|
|
36
|
+
var userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
|
|
37
|
+
var ip = this.extractIpFromHeader(config, readOnlyHeaders);
|
|
38
|
+
return { url: url, method: method, headers: readOnlyHeaders, cookies: cookies, ip: ip, userAgent: userAgent, requestCookieNames: requestCookieNames, request: request };
|
|
39
39
|
};
|
|
40
40
|
ContextBase.prototype.getCookies = function (cookieParser) {
|
|
41
41
|
var cookieHeaderValues = [];
|
|
@@ -50,7 +50,7 @@ var ContextBase = /** @class */ (function () {
|
|
|
50
50
|
};
|
|
51
51
|
ContextBase.prototype.extractUserAgentFromHeader = function (config, headers) {
|
|
52
52
|
var _a;
|
|
53
|
-
var userAgent = ((_a = headers
|
|
53
|
+
var userAgent = ((_a = headers[http_1.USER_AGENT_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
54
54
|
if (userAgent.length > config.userAgentMaxLength) {
|
|
55
55
|
userAgent = userAgent.substring(0, config.userAgentMaxLength);
|
|
56
56
|
}
|
|
@@ -60,7 +60,7 @@ var ContextBase = /** @class */ (function () {
|
|
|
60
60
|
var ip;
|
|
61
61
|
config.ipHeaders.some(function (ipHeader) {
|
|
62
62
|
var _a;
|
|
63
|
-
var headerValue = (_a = headers
|
|
63
|
+
var headerValue = (_a = headers[ipHeader]) === null || _a === void 0 ? void 0 : _a[0];
|
|
64
64
|
if (headerValue) {
|
|
65
65
|
ip = headerValue;
|
|
66
66
|
return true;
|
|
@@ -80,13 +80,11 @@ var ContextBase = /** @class */ (function () {
|
|
|
80
80
|
return (0, utils_1.isRouteInPatterns)(url.pathname, config.sensitiveRoutes);
|
|
81
81
|
};
|
|
82
82
|
ContextBase.prototype.isAllowedToBypassMonitor = function (config, requestData) {
|
|
83
|
-
var _a;
|
|
84
83
|
return (config.bypassMonitorHeader &&
|
|
85
|
-
|
|
84
|
+
requestData.request.headers.get(config.bypassMonitorHeader) === utils_1.BYPASS_MONITOR_HEADER_VALUE);
|
|
86
85
|
};
|
|
87
86
|
ContextBase.prototype.setRiskTokenOnContext = function (config, options) {
|
|
88
|
-
var
|
|
89
|
-
var mobileToken = (_a = this.requestData.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0];
|
|
87
|
+
var mobileToken = this.requestData.request.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME);
|
|
90
88
|
if (mobileToken) {
|
|
91
89
|
this.setMobileTokenOnContext(config, mobileToken, options);
|
|
92
90
|
}
|
|
@@ -95,11 +93,10 @@ var ContextBase = /** @class */ (function () {
|
|
|
95
93
|
}
|
|
96
94
|
};
|
|
97
95
|
ContextBase.prototype.setMobileTokenOnContext = function (config, mobileToken, options) {
|
|
98
|
-
var _a, _b;
|
|
99
96
|
this.tokenOrigin = risk_token_1.TokenOrigin.HEADER;
|
|
100
97
|
this.riskToken = this.getMobileToken(config, mobileToken, options);
|
|
101
|
-
this.mobileData.originalToken = this.getMobileToken(config,
|
|
102
|
-
this.mobileData.bypassReason =
|
|
98
|
+
this.mobileData.originalToken = this.getMobileToken(config, this.requestData.request.headers.get(utils_1.X_PX_ORIGINAL_TOKEN_HEADER_NAME), options);
|
|
99
|
+
this.mobileData.bypassReason = this.requestData.request.headers.get(utils_1.X_PX_BYPASS_REASON_HEADER_NAME) || '';
|
|
103
100
|
if (!this.riskToken && /^\d+$/.test(mobileToken)) {
|
|
104
101
|
this.mobileData.mobileError = mobileToken;
|
|
105
102
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
|
-
import { IHttpRequest } from '../http';
|
|
3
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
4
3
|
import { IBase64Utils, IHashUtils } from '../utils';
|
|
5
4
|
import { ContextBase, ContextBaseOptions } from './ContextBase';
|
|
5
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
6
6
|
export declare type DefaultTokenV2ContextOptions = {
|
|
7
7
|
base64Utils?: IBase64Utils;
|
|
8
8
|
hashUtils?: IHashUtils;
|
|
9
9
|
} & ContextBaseOptions;
|
|
10
10
|
export declare class DefaultTokenV2Context extends ContextBase<DefaultTokenV2ContextOptions> {
|
|
11
|
-
constructor(config: IConfiguration, httpRequest:
|
|
11
|
+
constructor(config: IConfiguration, httpRequest: IIncomingRequest, options?: DefaultTokenV2ContextOptions);
|
|
12
12
|
protected createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: DefaultTokenV2ContextOptions): IBotDefenderToken;
|
|
13
13
|
}
|
|
@@ -26,7 +26,7 @@ var DefaultTokenV2Context = /** @class */ (function (_super) {
|
|
|
26
26
|
}
|
|
27
27
|
DefaultTokenV2Context.prototype.createRiskToken = function (config, cookies, options) {
|
|
28
28
|
if (cookies[risk_token_1.COOKIE_V2_NAME]) {
|
|
29
|
-
return new risk_token_1.DefaultBotDefenderTokenV2(config, cookies[risk_token_1.COOKIE_V2_NAME], (options === null || options === void 0 ? void 0 : options.base64Utils) || new utils_1.
|
|
29
|
+
return new risk_token_1.DefaultBotDefenderTokenV2(config, cookies[risk_token_1.COOKIE_V2_NAME], (options === null || options === void 0 ? void 0 : options.base64Utils) || new utils_1.JSBase64Base64Utils(), (options === null || options === void 0 ? void 0 : options.hashUtils) || new utils_1.CryptoJSHmacUtils());
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
|
-
import { IHttpRequest } from '../http';
|
|
3
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
4
3
|
import { IHashUtils, ICipherUtils } from '../utils';
|
|
5
4
|
import { ContextBase, ContextBaseOptions } from './ContextBase';
|
|
5
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
6
6
|
export declare type DefaultTokenV3ContextOptions = {
|
|
7
7
|
cipherUtils: ICipherUtils;
|
|
8
8
|
hashUtils?: IHashUtils;
|
|
9
9
|
} & ContextBaseOptions;
|
|
10
10
|
export declare class DefaultTokenV3Context extends ContextBase<DefaultTokenV3ContextOptions> {
|
|
11
|
-
constructor(config: IConfiguration, httpRequest:
|
|
11
|
+
constructor(config: IConfiguration, httpRequest: IIncomingRequest, options: DefaultTokenV3ContextOptions);
|
|
12
12
|
protected createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: DefaultTokenV3ContextOptions): IBotDefenderToken;
|
|
13
13
|
}
|
|
@@ -26,7 +26,7 @@ var DefaultTokenV3Context = /** @class */ (function (_super) {
|
|
|
26
26
|
}
|
|
27
27
|
DefaultTokenV3Context.prototype.createRiskToken = function (config, cookies, options) {
|
|
28
28
|
if (cookies[risk_token_1.COOKIE_V3_NAME]) {
|
|
29
|
-
return new risk_token_1.DefaultBotDefenderTokenV3(config, cookies[risk_token_1.COOKIE_V3_NAME], options.cipherUtils, options.hashUtils || new utils_1.
|
|
29
|
+
return new risk_token_1.DefaultBotDefenderTokenV3(config, cookies[risk_token_1.COOKIE_V3_NAME], options.cipherUtils, options.hashUtils || new utils_1.CryptoJSHmacUtils());
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
@@ -3,10 +3,12 @@ import { FilterReason } from '../filter';
|
|
|
3
3
|
import { S2SCallReason, S2SErrorReason } from '../risk_api';
|
|
4
4
|
import { PassReason, VidSource } from '../utils';
|
|
5
5
|
import { BlockAction, BlockReason } from '../block_handler';
|
|
6
|
-
import { HttpHeaders, HttpMethod, IHttpRequest } from '../http';
|
|
7
6
|
import { CustomParameters } from '../custom_parameters';
|
|
8
7
|
import { PXDE } from '../pxde';
|
|
9
|
-
import { GraphQLData } from '../graphql
|
|
8
|
+
import { GraphQLData } from '../graphql';
|
|
9
|
+
import { HttpMethod } from '../http';
|
|
10
|
+
import { ReadOnlyHeaders } from '../http';
|
|
11
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
10
12
|
export declare type RequestData = {
|
|
11
13
|
/**
|
|
12
14
|
* The request URL.
|
|
@@ -20,7 +22,7 @@ export declare type RequestData = {
|
|
|
20
22
|
* An object representing the request headers. The keys are the header names (all lowercase) and the values
|
|
21
23
|
* are arrays of strings, with each string representing one value associated with the header name.
|
|
22
24
|
*/
|
|
23
|
-
headers:
|
|
25
|
+
headers: ReadOnlyHeaders;
|
|
24
26
|
/**
|
|
25
27
|
* An object representing the request cookies. The keys are the cookie
|
|
26
28
|
* names and the values are the cookie values.
|
|
@@ -41,7 +43,7 @@ export declare type RequestData = {
|
|
|
41
43
|
/**
|
|
42
44
|
* An interface representing the original HTTP request.
|
|
43
45
|
*/
|
|
44
|
-
request:
|
|
46
|
+
request: IIncomingRequest;
|
|
45
47
|
/**
|
|
46
48
|
* The HTTP version used for the request (e.g., 0.9, 1.0, 1.1, 2.0).
|
|
47
49
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHttpRequest } from '../http';
|
|
2
1
|
import { ConfigurationParams } from '../config';
|
|
3
2
|
import { CustomParameters } from './CustomParameters';
|
|
4
|
-
|
|
3
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
4
|
+
export declare type CustomParametersFunction = (config: ConfigurationParams, httpRequest: IIncomingRequest) => CustomParameters | Promise<CustomParameters>;
|