perimeterx-js-core 0.4.2 → 0.4.4
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 +3 -1
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +1 -1
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +1 -2
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +1 -1
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +1 -2
- package/lib/context/ContextBase.d.ts +1 -2
- package/lib/context/ContextBase.js +2 -2
- package/lib/context/DefaultTokenV2Context.d.ts +1 -1
- package/lib/context/DefaultTokenV3Context.d.ts +1 -1
- package/lib/context/index.d.ts +4 -4
- package/lib/context/index.js +18 -7
- package/lib/enforcer/EnforcerBase.d.ts +4 -6
- package/lib/enforcer/EnforcerBase.js +3 -3
- package/lib/first_party/DefaultFirstParty.d.ts +1 -2
- package/lib/first_party/DefaultFirstParty.js +11 -9
- package/lib/first_party/utils.d.ts +1 -0
- package/lib/first_party/utils.js +7 -5
- package/lib/http/impl/index.d.ts +1 -0
- package/lib/http/impl/index.js +1 -0
- package/lib/http/impl/phin/PhinHttpClient.d.ts +6 -0
- package/lib/http/impl/phin/PhinHttpClient.js +81 -0
- package/lib/http/impl/phin/PhinIncomingResponse.d.ts +14 -0
- package/lib/http/impl/phin/PhinIncomingResponse.js +86 -0
- package/lib/http/impl/phin/index.d.ts +2 -0
- package/lib/http/impl/phin/index.js +18 -0
- package/lib/pxhd/PXHDUtils.d.ts +1 -2
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -93,7 +93,8 @@ When developing your JavaScript/TypeScript enforcer with this library, you will
|
|
|
93
93
|
objects such that they conform to these interfaces. Of course, you are free to extend these interfaces as needed.
|
|
94
94
|
|
|
95
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
|
|
96
|
-
or use an external library
|
|
96
|
+
or use an external library if needed. This library includes implementations using `phin` (`PhinHttpClient` and `PhinIncomingResponse`)
|
|
97
|
+
for Node.js-based enforcers.
|
|
97
98
|
|
|
98
99
|
### Crypto
|
|
99
100
|
|
|
@@ -128,6 +129,7 @@ can be swapped with other implementations. These classes are:
|
|
|
128
129
|
| `cookie` | `DefaultCookieParser` | `ContextBase` |
|
|
129
130
|
| `uuid` | `DefaultUuidGenerator` | `ContextBase` |
|
|
130
131
|
| `ip-range-check` | `DefaultIpRangeChecker` | `DefaultFilter` |
|
|
132
|
+
| `phin` | `PhinHttpClient`, `PhinIncomingResponse` | First party, Risk API, Activities |
|
|
131
133
|
|
|
132
134
|
## For Contributors
|
|
133
135
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
4
3
|
import { IMinimalResponse } from '../../http';
|
|
4
|
+
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
5
5
|
export declare class HtmlCaptchaResponseGenerator implements IBlockResponseGenerator {
|
|
6
6
|
private readonly config;
|
|
7
7
|
constructor(config: IConfiguration);
|
|
@@ -4,7 +4,6 @@ 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");
|
|
8
7
|
var HtmlCaptchaResponseGenerator = /** @class */ (function () {
|
|
9
8
|
function HtmlCaptchaResponseGenerator(config) {
|
|
10
9
|
this.config = config;
|
|
@@ -19,7 +18,7 @@ var HtmlCaptchaResponseGenerator = /** @class */ (function () {
|
|
|
19
18
|
_a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
|
|
20
19
|
_a);
|
|
21
20
|
var body = (0, utils_1.renderHtml)(captcha_template_1.CAPTCHA_TEMPLATE, (0, utils_1.createBlockData)(this.config, context));
|
|
22
|
-
return new
|
|
21
|
+
return new http_1.MinimalResponseImpl({
|
|
23
22
|
body: body,
|
|
24
23
|
status: status,
|
|
25
24
|
headers: headers,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
4
3
|
import { IMinimalResponse } from '../../http';
|
|
4
|
+
import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
|
|
5
5
|
export declare class JsonCaptchaResponseGenerator implements IBlockResponseGenerator {
|
|
6
6
|
private readonly config;
|
|
7
7
|
constructor(config: IConfiguration);
|
|
@@ -4,7 +4,6 @@ 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");
|
|
8
7
|
var JsonCaptchaResponseGenerator = /** @class */ (function () {
|
|
9
8
|
function JsonCaptchaResponseGenerator(config) {
|
|
10
9
|
this.config = config;
|
|
@@ -37,7 +36,7 @@ var JsonCaptchaResponseGenerator = /** @class */ (function () {
|
|
|
37
36
|
blockScript: blockData.blockScript,
|
|
38
37
|
altBlockScript: blockData.altBlockScript,
|
|
39
38
|
};
|
|
40
|
-
return new
|
|
39
|
+
return new http_1.MinimalResponseImpl({
|
|
41
40
|
body: JSON.stringify(jsonBlockPayload),
|
|
42
41
|
status: status,
|
|
43
42
|
headers: headers,
|
|
@@ -5,10 +5,9 @@ import { FilterReason } from '../filter';
|
|
|
5
5
|
import { PXDE } from '../pxde';
|
|
6
6
|
import { GraphQLData } from '../graphql';
|
|
7
7
|
import { IBotDefenderToken, TokenOrigin } from '../risk_token';
|
|
8
|
+
import { ReadOnlyHeaders, IIncomingRequest } from '../http';
|
|
8
9
|
import { VidSource, PassReason, ICookieParser, IUuidGenerator } from '../utils';
|
|
9
10
|
import { IContext, MobileData, RequestData, ResponseData, RiskApiData, ServerData, TlsData } from './IContext';
|
|
10
|
-
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
11
|
-
import { ReadOnlyHeaders } from '../http';
|
|
12
11
|
export declare type ContextBaseOptions = {
|
|
13
12
|
cookieParser?: ICookieParser;
|
|
14
13
|
uuidGenerator?: IUuidGenerator;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextBase = void 0;
|
|
4
4
|
var block_handler_1 = require("../block_handler");
|
|
5
|
-
var http_1 = require("../http");
|
|
6
5
|
var risk_token_1 = require("../risk_token");
|
|
6
|
+
var http_1 = require("../http");
|
|
7
7
|
var utils_1 = require("../utils");
|
|
8
8
|
var ContextBase = /** @class */ (function () {
|
|
9
9
|
function ContextBase(config, request, options) {
|
|
@@ -34,7 +34,7 @@ var ContextBase = /** @class */ (function () {
|
|
|
34
34
|
var requestCookieNames = Object.keys(cookies);
|
|
35
35
|
var readOnlyHeaders = (0, http_1.toReadOnlyHeaders)(headers);
|
|
36
36
|
var userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
|
|
37
|
-
var ip = this.extractIpFromHeader(config, readOnlyHeaders);
|
|
37
|
+
var ip = this.extractIpFromHeader(config, readOnlyHeaders) || request.clientIP;
|
|
38
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) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
3
3
|
import { IBase64Utils, IHashUtils } from '../utils';
|
|
4
|
+
import { IIncomingRequest } from '../http';
|
|
4
5
|
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;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
3
3
|
import { IHashUtils, ICipherUtils } from '../utils';
|
|
4
|
+
import { IIncomingRequest } from '../http';
|
|
4
5
|
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;
|
package/lib/context/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from './IContext';
|
|
2
|
+
export * from './ContextBase';
|
|
3
|
+
export * from './DefaultTokenV2Context';
|
|
4
|
+
export * from './DefaultTokenV3Context';
|
package/lib/context/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "DefaultTokenV2Context", { enumerable: true, get: function () { return DefaultTokenV2Context_1.DefaultTokenV2Context; } });
|
|
8
|
-
var DefaultTokenV3Context_1 = require("./DefaultTokenV3Context");
|
|
9
|
-
Object.defineProperty(exports, "DefaultTokenV3Context", { enumerable: true, get: function () { return DefaultTokenV3Context_1.DefaultTokenV3Context; } });
|
|
17
|
+
__exportStar(require("./IContext"), exports);
|
|
18
|
+
__exportStar(require("./ContextBase"), exports);
|
|
19
|
+
__exportStar(require("./DefaultTokenV2Context"), exports);
|
|
20
|
+
__exportStar(require("./DefaultTokenV3Context"), exports);
|
|
@@ -10,9 +10,7 @@ import { IBlockResponseGenerator } from '../block_handler';
|
|
|
10
10
|
import { TokenVersion } from '../risk_token';
|
|
11
11
|
import { IActivityClient } from '../activities';
|
|
12
12
|
import { IGraphQLParser } from '../graphql';
|
|
13
|
-
import { IHttpClient } from '../http';
|
|
14
|
-
import { IOutgoingResponse } from '../http';
|
|
15
|
-
import { IMinimalResponse } from '../http';
|
|
13
|
+
import { IHttpClient, IOutgoingResponse, IMinimalResponse } from '../http';
|
|
16
14
|
export declare type EnforcerBaseOptions = {
|
|
17
15
|
tokenVersion?: TokenVersion;
|
|
18
16
|
dataEnrichment?: IDataEnrichment;
|
|
@@ -95,13 +93,13 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
95
93
|
/**
|
|
96
94
|
* The central function that triggers enforcement on the incoming request.
|
|
97
95
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
98
|
-
* @returns Promise<
|
|
96
|
+
* @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
|
|
99
97
|
*/
|
|
100
98
|
enforce(...args: EnforceArgs): Promise<Res | null>;
|
|
101
99
|
/**
|
|
102
100
|
* Performs all enforcer functionality on the incoming request context.
|
|
103
101
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
104
|
-
* @returns Promise<
|
|
102
|
+
* @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
|
|
105
103
|
* @protected
|
|
106
104
|
*/
|
|
107
105
|
protected doEnforce(...args: EnforceArgs): Promise<Res | null>;
|
|
@@ -123,7 +121,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
123
121
|
* @param req - The Req sent to the origin.
|
|
124
122
|
* @param res - The Res received from the origin.
|
|
125
123
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
126
|
-
* @returns Promise<
|
|
124
|
+
* @returns Promise<void> - The response parameter will be modified as needed
|
|
127
125
|
* @protected
|
|
128
126
|
*/
|
|
129
127
|
postEnforce(req: Req, res: Res, ...args: EnforceArgs): Promise<void>;
|
|
@@ -94,7 +94,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
94
94
|
/**
|
|
95
95
|
* The central function that triggers enforcement on the incoming request.
|
|
96
96
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
97
|
-
* @returns Promise<
|
|
97
|
+
* @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
|
|
98
98
|
*/
|
|
99
99
|
EnforcerBase.prototype.enforce = function () {
|
|
100
100
|
var args = [];
|
|
@@ -126,7 +126,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
126
126
|
/**
|
|
127
127
|
* Performs all enforcer functionality on the incoming request context.
|
|
128
128
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
129
|
-
* @returns Promise<
|
|
129
|
+
* @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
|
|
130
130
|
* @protected
|
|
131
131
|
*/
|
|
132
132
|
EnforcerBase.prototype.doEnforce = function () {
|
|
@@ -353,7 +353,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
353
353
|
* @param req - The Req sent to the origin.
|
|
354
354
|
* @param res - The Res received from the origin.
|
|
355
355
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
356
|
-
* @returns Promise<
|
|
356
|
+
* @returns Promise<void> - The response parameter will be modified as needed
|
|
357
357
|
* @protected
|
|
358
358
|
*/
|
|
359
359
|
EnforcerBase.prototype.postEnforce = function (req, res) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
2
|
import { IContext } from '../context/IContext';
|
|
3
|
+
import { IHttpClient, IMinimalResponse } from '../http';
|
|
3
4
|
import { IFirstParty } from './IFirstParty';
|
|
4
|
-
import { IHttpClient } from '../http';
|
|
5
|
-
import { IMinimalResponse } from '../http';
|
|
6
5
|
export declare class DefaultFirstParty implements IFirstParty {
|
|
7
6
|
private readonly config;
|
|
8
7
|
private readonly httpClient;
|
|
@@ -52,8 +52,6 @@ var utils_1 = require("../utils");
|
|
|
52
52
|
var http_1 = require("../http");
|
|
53
53
|
var utils_2 = require("./utils");
|
|
54
54
|
var constants_1 = require("./constants");
|
|
55
|
-
var http_2 = require("../http");
|
|
56
|
-
var http_3 = require("../http");
|
|
57
55
|
var minimalResponseUtils = require("../http/utils/MinimalResponseUtils");
|
|
58
56
|
var DefaultFirstParty = /** @class */ (function () {
|
|
59
57
|
function DefaultFirstParty(config, httpClient) {
|
|
@@ -94,13 +92,13 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
94
92
|
switch (_a.label) {
|
|
95
93
|
case 0:
|
|
96
94
|
if (!this.config.firstPartyEnabled) {
|
|
97
|
-
return [2 /*return*/, new
|
|
95
|
+
return [2 /*return*/, new http_1.MinimalResponseImpl(constants_1.DEFAULT_CLIENT_RESPONSE_OPTIONS)];
|
|
98
96
|
}
|
|
99
97
|
url = this.getThirdPartySensorScriptUrl();
|
|
100
98
|
return [4 /*yield*/, this.forwardRequest(url, context)];
|
|
101
99
|
case 1:
|
|
102
100
|
response = _a.sent();
|
|
103
|
-
return [2 /*return*/, response ? response : new
|
|
101
|
+
return [2 /*return*/, response ? response : new http_1.MinimalResponseImpl(constants_1.DEFAULT_CLIENT_RESPONSE_OPTIONS)];
|
|
104
102
|
}
|
|
105
103
|
});
|
|
106
104
|
});
|
|
@@ -127,7 +125,7 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
127
125
|
};
|
|
128
126
|
DefaultFirstParty.getDefaultXhrResponse = function (path) {
|
|
129
127
|
var _a = path.endsWith('.gif') ? constants_1.DEFAULT_GIF_RESPONSE : constants_1.DEFAULT_XHR_RESPONSE, content = _a.content, options = _a.options;
|
|
130
|
-
return new
|
|
128
|
+
return new http_1.MinimalResponseImpl({
|
|
131
129
|
body: content,
|
|
132
130
|
status: options.status,
|
|
133
131
|
headers: options.headers,
|
|
@@ -140,13 +138,13 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
140
138
|
switch (_a.label) {
|
|
141
139
|
case 0:
|
|
142
140
|
if (!this.config.firstPartyEnabled) {
|
|
143
|
-
return [2 /*return*/, new
|
|
141
|
+
return [2 /*return*/, new http_1.MinimalResponseImpl(constants_1.DEFAULT_CLIENT_RESPONSE_OPTIONS)];
|
|
144
142
|
}
|
|
145
143
|
url = this.getThirdPartyCaptchaScriptUrl(context, prefix);
|
|
146
144
|
return [4 /*yield*/, this.forwardRequest(url, context)];
|
|
147
145
|
case 1:
|
|
148
146
|
response = _a.sent();
|
|
149
|
-
return [2 /*return*/, response ? response : new
|
|
147
|
+
return [2 /*return*/, response ? response : new http_1.MinimalResponseImpl(constants_1.DEFAULT_CLIENT_RESPONSE_OPTIONS)];
|
|
150
148
|
}
|
|
151
149
|
});
|
|
152
150
|
});
|
|
@@ -159,7 +157,7 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
159
157
|
switch (_d.label) {
|
|
160
158
|
case 0:
|
|
161
159
|
_d.trys.push([0, 2, , 3]);
|
|
162
|
-
request = new
|
|
160
|
+
request = new http_1.OutgoingRequestImpl({
|
|
163
161
|
url: url,
|
|
164
162
|
method: requestData.request.method,
|
|
165
163
|
headers: this.prepareFirstPartyHeaders(url, requestData, vid),
|
|
@@ -179,6 +177,7 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
179
177
|
});
|
|
180
178
|
};
|
|
181
179
|
DefaultFirstParty.prototype.prepareFirstPartyHeaders = function (url, requestData, vid) {
|
|
180
|
+
var _a;
|
|
182
181
|
var headers = __assign({}, requestData.headers);
|
|
183
182
|
try {
|
|
184
183
|
headers = (0, utils_1.removeSensitiveHeaders)(headers, this.config.sensitiveHeaders);
|
|
@@ -186,7 +185,10 @@ var DefaultFirstParty = /** @class */ (function () {
|
|
|
186
185
|
this.setXffHeader(headers, requestData.ip);
|
|
187
186
|
this.addFirstPartyHeaders(headers, requestData.ip);
|
|
188
187
|
if (vid) {
|
|
189
|
-
|
|
188
|
+
var vidCookieString = "pxvid=".concat(vid);
|
|
189
|
+
var existingCookies = (_a = headers[http_1.COOKIE_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a.join('; ');
|
|
190
|
+
var newCookies = existingCookies ? "".concat(existingCookies, "; ").concat(vidCookieString) : vidCookieString;
|
|
191
|
+
headers[http_1.COOKIE_HEADER_NAME] = [newCookies];
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
catch (e) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
2
|
export declare const getDefaultFirstPartyPrefix: (appId: string) => string;
|
|
3
|
+
export declare const getFirstPartyPaths: (config: IConfiguration, callback?: (prefix: string) => string) => string[];
|
|
3
4
|
export declare const getFirstPartySensorScriptPaths: (config: IConfiguration) => string[];
|
|
4
5
|
export declare const getFirstPartyCaptchaScriptPathPrefixes: (config: IConfiguration) => string[];
|
|
5
6
|
export declare const getFirstPartyXhrPathPrefixes: (config: IConfiguration) => string[];
|
package/lib/first_party/utils.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFirstPartyXhrPathPrefix = exports.getFirstPartyCaptchaScriptPathPrefix = exports.getFirstPartySensorScriptPath = exports.getFirstPartyXhrPathPrefixes = exports.getFirstPartyCaptchaScriptPathPrefixes = exports.getFirstPartySensorScriptPaths = exports.getDefaultFirstPartyPrefix = void 0;
|
|
3
|
+
exports.getFirstPartyXhrPathPrefix = exports.getFirstPartyCaptchaScriptPathPrefix = exports.getFirstPartySensorScriptPath = exports.getFirstPartyXhrPathPrefixes = exports.getFirstPartyCaptchaScriptPathPrefixes = exports.getFirstPartySensorScriptPaths = exports.getFirstPartyPaths = exports.getDefaultFirstPartyPrefix = void 0;
|
|
4
4
|
var getDefaultFirstPartyPrefix = function (appId) { return appId.substring(2); };
|
|
5
5
|
exports.getDefaultFirstPartyPrefix = getDefaultFirstPartyPrefix;
|
|
6
6
|
var getFirstPartyPaths = function (config, callback) {
|
|
7
7
|
var allPrefixes = [config.firstPartyPrefix, (0, exports.getDefaultFirstPartyPrefix)(config.appId)];
|
|
8
|
-
|
|
8
|
+
var prefixes = Array.from(new Set(allPrefixes));
|
|
9
|
+
return callback ? prefixes.map(callback) : prefixes;
|
|
9
10
|
};
|
|
11
|
+
exports.getFirstPartyPaths = getFirstPartyPaths;
|
|
10
12
|
var getFirstPartySensorScriptPaths = function (config) {
|
|
11
|
-
return getFirstPartyPaths(config, exports.getFirstPartySensorScriptPath);
|
|
13
|
+
return (0, exports.getFirstPartyPaths)(config, exports.getFirstPartySensorScriptPath);
|
|
12
14
|
};
|
|
13
15
|
exports.getFirstPartySensorScriptPaths = getFirstPartySensorScriptPaths;
|
|
14
16
|
var getFirstPartyCaptchaScriptPathPrefixes = function (config) {
|
|
15
|
-
return getFirstPartyPaths(config, exports.getFirstPartyCaptchaScriptPathPrefix);
|
|
17
|
+
return (0, exports.getFirstPartyPaths)(config, exports.getFirstPartyCaptchaScriptPathPrefix);
|
|
16
18
|
};
|
|
17
19
|
exports.getFirstPartyCaptchaScriptPathPrefixes = getFirstPartyCaptchaScriptPathPrefixes;
|
|
18
20
|
var getFirstPartyXhrPathPrefixes = function (config) {
|
|
19
|
-
return getFirstPartyPaths(config, exports.getFirstPartyXhrPathPrefix);
|
|
21
|
+
return (0, exports.getFirstPartyPaths)(config, exports.getFirstPartyXhrPathPrefix);
|
|
20
22
|
};
|
|
21
23
|
exports.getFirstPartyXhrPathPrefixes = getFirstPartyXhrPathPrefixes;
|
|
22
24
|
var getFirstPartySensorScriptPath = function (prefix) { return "/".concat(prefix, "/init.js"); };
|
package/lib/http/impl/index.d.ts
CHANGED
package/lib/http/impl/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./MinimalResponseImpl"), exports);
|
|
18
18
|
__exportStar(require("./OutgoingRequestImpl"), exports);
|
|
19
|
+
__exportStar(require("./phin"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HttpSendOptions, IHttpClient, IIncomingResponse, IOutgoingRequest } from '../../interfaces';
|
|
2
|
+
export declare class PhinHttpClient implements IHttpClient {
|
|
3
|
+
private readonly httpsKeepAliveAgent;
|
|
4
|
+
constructor();
|
|
5
|
+
send(request: IOutgoingRequest, options?: HttpSendOptions): Promise<IIncomingResponse>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.PhinHttpClient = void 0;
|
|
40
|
+
var http_1 = require("http");
|
|
41
|
+
var https_1 = require("https");
|
|
42
|
+
var p = require("phin");
|
|
43
|
+
var utils_1 = require("../../../utils");
|
|
44
|
+
var interfaces_1 = require("../../interfaces");
|
|
45
|
+
var PhinIncomingResponse_1 = require("./PhinIncomingResponse");
|
|
46
|
+
var PhinHttpClient = /** @class */ (function () {
|
|
47
|
+
function PhinHttpClient() {
|
|
48
|
+
this.httpsKeepAliveAgent = new https_1.Agent({ keepAlive: true });
|
|
49
|
+
}
|
|
50
|
+
PhinHttpClient.prototype.send = function (request, options) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var res, e_1, isTimeout;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
_a.trys.push([0, 2, , 3]);
|
|
57
|
+
return [4 /*yield*/, p({
|
|
58
|
+
url: request.url,
|
|
59
|
+
method: request.method,
|
|
60
|
+
headers: (0, interfaces_1.joinHeaderValues)(request.headers),
|
|
61
|
+
data: request.body,
|
|
62
|
+
timeout: (options === null || options === void 0 ? void 0 : options.timeoutMs) || null,
|
|
63
|
+
core: {
|
|
64
|
+
agent: request.url.startsWith('https://') ? this.httpsKeepAliveAgent : new http_1.Agent(),
|
|
65
|
+
},
|
|
66
|
+
})];
|
|
67
|
+
case 1:
|
|
68
|
+
res = _a.sent();
|
|
69
|
+
return [2 /*return*/, new PhinIncomingResponse_1.PhinIncomingResponse(res)];
|
|
70
|
+
case 2:
|
|
71
|
+
e_1 = _a.sent();
|
|
72
|
+
isTimeout = e_1.toString().toLowerCase().includes('timeout');
|
|
73
|
+
throw isTimeout ? new utils_1.EnforcerTimeoutError(options.timeoutMs) : e_1;
|
|
74
|
+
case 3: return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return PhinHttpClient;
|
|
80
|
+
}());
|
|
81
|
+
exports.PhinHttpClient = PhinHttpClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IResponse } from 'phin';
|
|
3
|
+
import { IIncomingResponse, ReadOnlyHeaders } from '../../interfaces';
|
|
4
|
+
export declare class PhinIncomingResponse implements IIncomingResponse {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly headers: ReadOnlyHeaders;
|
|
7
|
+
readonly body: Buffer;
|
|
8
|
+
constructor(response: IResponse);
|
|
9
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
10
|
+
blob(): Promise<Blob>;
|
|
11
|
+
formData(): Promise<FormData>;
|
|
12
|
+
json(): Promise<any>;
|
|
13
|
+
text(): Promise<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.PhinIncomingResponse = void 0;
|
|
40
|
+
var PhinIncomingResponse = /** @class */ (function () {
|
|
41
|
+
function PhinIncomingResponse(response) {
|
|
42
|
+
this.status = response.statusCode;
|
|
43
|
+
this.body = response.body;
|
|
44
|
+
this.headers = Object.fromEntries(Object.entries(response.headers).map(function (_a) {
|
|
45
|
+
var key = _a[0], val = _a[1];
|
|
46
|
+
return [key, typeof val === 'string' ? [val] : val];
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
PhinIncomingResponse.prototype.arrayBuffer = function () {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
return [2 /*return*/, this.body];
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
PhinIncomingResponse.prototype.blob = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
throw 'not implemented';
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
PhinIncomingResponse.prototype.formData = function () {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
throw 'not implemented';
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
PhinIncomingResponse.prototype.json = function () {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
return [2 /*return*/, JSON.parse(this.body.toString())];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
PhinIncomingResponse.prototype.text = function () {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
return [2 /*return*/, this.body.toString()];
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
return PhinIncomingResponse;
|
|
85
|
+
}());
|
|
86
|
+
exports.PhinIncomingResponse = PhinIncomingResponse;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PhinIncomingResponse"), exports);
|
|
18
|
+
__exportStar(require("./PhinHttpClient"), exports);
|
package/lib/pxhd/PXHDUtils.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IContext } from '../context';
|
|
2
|
-
import { IOutgoingResponse } from '../http';
|
|
3
|
-
import { IMinimalResponse } from '../http';
|
|
2
|
+
import { IOutgoingResponse, IMinimalResponse } from '../http';
|
|
4
3
|
export declare namespace PXHDUtils {
|
|
5
4
|
const PXHD_SAMESITE_VALUE = "Lax";
|
|
6
5
|
const PXHD_PATH_VALUE = "/";
|
package/lib/utils/constants.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare const BYPASS_MONITOR_HEADER_VALUE = "1";
|
|
|
7
7
|
export declare const X_PX_AUTHORIZATION_HEADER_NAME = "x-px-authorization";
|
|
8
8
|
export declare const X_PX_ORIGINAL_TOKEN_HEADER_NAME = "x-px-original-token";
|
|
9
9
|
export declare const X_PX_BYPASS_REASON_HEADER_NAME = "x-px-bypass-reason";
|
|
10
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.4.
|
|
10
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.4.4";
|
package/lib/utils/constants.js
CHANGED
|
@@ -10,4 +10,4 @@ exports.BYPASS_MONITOR_HEADER_VALUE = '1';
|
|
|
10
10
|
exports.X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
|
|
11
11
|
exports.X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
|
|
12
12
|
exports.X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
|
|
13
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.4.
|
|
13
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.4.4';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"crypto-js": "^4.1.1",
|
|
23
23
|
"ip-range-check": "^0.2.0",
|
|
24
24
|
"js-base64": "^3.7.2",
|
|
25
|
+
"phin": "^3.7.0",
|
|
25
26
|
"uuid": "^9.0.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|