perimeterx-js-core 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/action/ActionData.d.ts +1 -1
- package/lib/action/Decision.d.ts +1 -1
- package/lib/action/ProductAction.d.ts +1 -1
- package/lib/activities/model/Activity.d.ts +1 -1
- package/lib/activities/model/ActivityDetails.d.ts +5 -5
- package/lib/activities/utils.js +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/config/ConfigurationParams.d.ts +1 -1
- package/lib/context/DefaultContext.d.ts +4 -1
- package/lib/context/DefaultContext.js +6 -3
- package/lib/context/interfaces/MobileData.d.ts +1 -1
- package/lib/context/interfaces/ReadonlyContext.d.ts +1 -1
- package/lib/context/interfaces/RequestData.d.ts +6 -1
- package/lib/context/interfaces/RiskApiData.d.ts +1 -1
- package/lib/context/interfaces/ServerData.d.ts +1 -1
- package/lib/context/interfaces/TlsData.d.ts +1 -1
- package/lib/context/interfaces/TokenData.d.ts +1 -1
- package/lib/cors/CustomBlockResponseHeadersHandler.d.ts +1 -1
- package/lib/cors/CustomPreflightHandler.d.ts +1 -1
- package/lib/custom_parameters/CustomParameters.d.ts +1 -1
- package/lib/custom_parameters/CustomParametersFunction.d.ts +1 -1
- package/lib/enforcer/options/EnforcerBaseOptions.d.ts +1 -1
- package/lib/enforcer/options/EnforcerOptionsType.d.ts +1 -1
- package/lib/enforcer/options/EnforcerV2Options.d.ts +1 -1
- package/lib/enforcer/options/EnforcerV3Options.d.ts +1 -1
- package/lib/first_party/FirstPartyData.d.ts +1 -1
- package/lib/graphql/model/GraphQLData.d.ts +1 -1
- package/lib/graphql/model/GraphQLOperation.d.ts +1 -1
- package/lib/http/impl/FormDataImpl.js +2 -2
- package/lib/http/impl/MinimalResponseImpl.d.ts +1 -1
- package/lib/http/impl/OutgoingRequestImpl.d.ts +1 -1
- package/lib/http/interfaces/IHttpClient.d.ts +1 -1
- package/lib/http/interfaces/ReadonlyHeaders.d.ts +1 -1
- package/lib/phase/PhaseResult.d.ts +1 -1
- package/lib/products/account_defender/AccountDefender.d.ts +1 -1
- package/lib/products/account_defender/AccountDefenderData.d.ts +1 -1
- package/lib/products/account_defender/JwtData.d.ts +1 -1
- package/lib/products/bot_defender/BotDefender.d.ts +1 -1
- package/lib/products/bot_defender/BotDefenderData.d.ts +1 -1
- package/lib/products/bot_defender/block/model/BlockData.d.ts +1 -1
- package/lib/products/bot_defender/block/model/JsonBlockPayload.d.ts +1 -1
- package/lib/products/bot_defender/block/model/MobileBlockPayload.d.ts +1 -1
- package/lib/products/bot_defender/block/utils.js +5 -4
- package/lib/products/bot_defender/reasons/BotDefenderReasonType.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulCallback.d.ts +1 -1
- package/lib/products/credential_intelligence/model/CredentialData.d.ts +1 -1
- package/lib/products/credential_intelligence/model/CredentialIntelligenceData.d.ts +1 -1
- package/lib/products/credential_intelligence/model/Credentials.d.ts +1 -1
- package/lib/products/credential_intelligence/model/CustomExtractionCallback.d.ts +1 -1
- package/lib/products/interfaces/ProductData.d.ts +1 -1
- package/lib/products/interfaces/ProductDataType.d.ts +1 -1
- package/lib/products/interfaces/ProductType.d.ts +1 -1
- package/lib/products/interfaces/Products.d.ts +1 -1
- package/lib/pxde/model/PXDE.d.ts +1 -1
- package/lib/pxde/model/PxdeData.d.ts +1 -1
- package/lib/pxhd/model/PXHD.d.ts +1 -1
- package/lib/risk_api/client/PostRiskApiClientBase.js +1 -1
- package/lib/risk_api/model/RiskActivity.d.ts +4 -4
- package/lib/risk_api/risk_response/RiskResponsePayloadType.d.ts +1 -1
- package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -1
- package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -1
- package/lib/risk_token/parser/DefaultTokenV2Parser.d.ts +1 -1
- package/lib/risk_token/parser/DefaultTokenV3Parser.d.ts +1 -1
- package/lib/risk_token/parser/TokenParserOptions.d.ts +1 -1
- package/lib/risk_token/token/TokenPayloadType.d.ts +1 -1
- package/lib/risk_token/token/v2/TokenV2Payload.d.ts +1 -1
- package/lib/risk_token/token/v3/TokenV3Payload.d.ts +1 -1
- package/lib/telemetry/model/TelemetryActivity.d.ts +2 -2
- package/lib/utils/cipher/ICipherUtils.d.ts +1 -1
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/url_parser/DefaultUrlParser.d.ts +13 -0
- package/lib/utils/url_parser/DefaultUrlParser.js +21 -0
- package/lib/utils/url_parser/IURLParser.d.ts +4 -0
- package/lib/utils/url_parser/IURLParser.js +1 -0
- package/lib/utils/url_parser/index.d.ts +2 -0
- package/lib/utils/url_parser/index.js +2 -0
- package/lib/utils/utils.d.ts +5 -0
- package/lib/utils/utils.js +5 -1
- package/package.json +4 -4
package/lib/action/Decision.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLData } from '../../graphql';
|
|
2
2
|
import { BlockAction } from '../../blocker';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type ActivityTypeDetails = PageRequestedActivityDetails | BlockActivityDetails | AdditionalS2SActivityDetails;
|
|
4
|
+
export type ActivityDetails = ActivityTypeDetails & {
|
|
5
5
|
client_uuid: string;
|
|
6
6
|
request_id: string;
|
|
7
7
|
module_version: string;
|
|
@@ -26,20 +26,20 @@ export declare type ActivityDetails = ActivityTypeDetails & {
|
|
|
26
26
|
app_user_id?: string;
|
|
27
27
|
jwt_additional_fields?: Record<string, any>;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
29
|
+
export type PageRequestedActivityDetails = {
|
|
30
30
|
pass_reason: string;
|
|
31
31
|
px_cookie?: string;
|
|
32
32
|
error_message?: string;
|
|
33
33
|
s2s_error_reason?: string;
|
|
34
34
|
s2s_error_http_status?: number;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type BlockActivityDetails = {
|
|
37
37
|
block_reason: string;
|
|
38
38
|
block_action: BlockAction;
|
|
39
39
|
block_score: number;
|
|
40
40
|
simulated_block: boolean;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type AdditionalS2SActivityDetails = {
|
|
43
43
|
http_status_code: number;
|
|
44
44
|
login_successful: boolean;
|
|
45
45
|
raw_username?: string;
|
package/lib/activities/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ export const createActivity = (activityType, config, context) => {
|
|
|
8
8
|
return {
|
|
9
9
|
type: activityType,
|
|
10
10
|
px_app_id: config.appId,
|
|
11
|
-
url: context.requestData.
|
|
11
|
+
url: context.requestData.rawUrl,
|
|
12
12
|
headers: activityType !== ActivityType.ADDITIONAL_S2S
|
|
13
13
|
? joinHeaderValues(removeSensitiveHeaders(context.requestData.headers, config.sensitiveHeaders))
|
|
14
14
|
: undefined,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ConfigurationParams } from '../config';
|
|
2
2
|
import { ReadonlyContext } from '../context';
|
|
3
|
-
export
|
|
3
|
+
export type AdditionalActivityHandler = <Req, Res>(config: ConfigurationParams<Req, Res>, context: ReadonlyContext<Req, Res>, request: Req) => void | Promise<void>;
|
|
@@ -5,7 +5,7 @@ import { CredentialEndpointConfiguration, CredentialIntelligenceVersion, CustomL
|
|
|
5
5
|
import { LoggerSeverity } from '../logger';
|
|
6
6
|
import { ModuleMode } from '../utils';
|
|
7
7
|
import { GraphQLOperationType } from '../graphql';
|
|
8
|
-
export
|
|
8
|
+
export type ConfigurationParams<Req, Res> = {
|
|
9
9
|
px_app_id: string;
|
|
10
10
|
px_auth_token: string;
|
|
11
11
|
px_cookie_secret: string;
|
|
@@ -9,9 +9,11 @@ import { ICookieParser, IRequestIdGenerator, VidSource } from '../utils';
|
|
|
9
9
|
import { IContext, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
|
|
10
10
|
import { ProductData, ProductName } from '../products';
|
|
11
11
|
import { Action } from '../action';
|
|
12
|
-
|
|
12
|
+
import { IURLParser } from '../utils/url_parser';
|
|
13
|
+
export type DefaultContextOptions = {
|
|
13
14
|
cookieParser?: ICookieParser;
|
|
14
15
|
requestIdGenerator: IRequestIdGenerator;
|
|
16
|
+
urlParser?: IURLParser;
|
|
15
17
|
};
|
|
16
18
|
export declare class DefaultContext<Req, Res> implements IContext<Req, Res> {
|
|
17
19
|
readonly requestId: string;
|
|
@@ -35,6 +37,7 @@ export declare class DefaultContext<Req, Res> implements IContext<Req, Res> {
|
|
|
35
37
|
customParameters?: CustomParameters;
|
|
36
38
|
response?: IOutgoingResponse<Res>;
|
|
37
39
|
protected readonly config: IConfiguration<Req, Res>;
|
|
40
|
+
protected readonly urlParser: IURLParser;
|
|
38
41
|
constructor(config: IConfiguration<Req, Res>, request: IIncomingRequest<Req>, options: DefaultContextOptions);
|
|
39
42
|
get isMobile(): boolean;
|
|
40
43
|
protected createRequestData(config: IConfiguration<Req, Res>, request: IIncomingRequest<Req>, cookieParser?: ICookieParser): RequestData<Req>;
|
|
@@ -3,10 +3,12 @@ import { PXHDSource } from '../pxhd';
|
|
|
3
3
|
import { TokenOrigin, TokenParseResult } from '../risk_token';
|
|
4
4
|
import { RiskApiCallResult } from '../risk_api';
|
|
5
5
|
import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '../http';
|
|
6
|
-
import { StringSplitCookieParser,
|
|
6
|
+
import { StringSplitCookieParser, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils';
|
|
7
|
+
import { DefaultUrlParser } from '../utils/url_parser';
|
|
7
8
|
export class DefaultContext {
|
|
8
9
|
constructor(config, request, options) {
|
|
9
10
|
this.config = config;
|
|
11
|
+
this.urlParser = options.urlParser || new DefaultUrlParser();
|
|
10
12
|
this.tokenData = {
|
|
11
13
|
tokenParseResult: TokenParseResult.NONE,
|
|
12
14
|
};
|
|
@@ -29,7 +31,8 @@ export class DefaultContext {
|
|
|
29
31
|
return this.tokenOrigin === TokenOrigin.HEADER;
|
|
30
32
|
}
|
|
31
33
|
createRequestData(config, request, cookieParser = new StringSplitCookieParser()) {
|
|
32
|
-
const
|
|
34
|
+
const rawUrl = request.url;
|
|
35
|
+
const url = this.urlParser.parse(rawUrl);
|
|
33
36
|
const method = request.method;
|
|
34
37
|
const headers = request.headers;
|
|
35
38
|
const cookies = DefaultContext.getCookies(cookieParser, request.headers.get(COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
|
|
@@ -37,7 +40,7 @@ export class DefaultContext {
|
|
|
37
40
|
const readOnlyHeaders = toReadonlyHeaders(headers);
|
|
38
41
|
const userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
|
|
39
42
|
const ip = this.extractIpFromHeader(config, readOnlyHeaders) || request.clientIP;
|
|
40
|
-
return { url, method, headers: readOnlyHeaders, cookies, ip, userAgent, requestCookieNames, request };
|
|
43
|
+
return { url, rawUrl, method, headers: readOnlyHeaders, cookies, ip, userAgent, requestCookieNames, request };
|
|
41
44
|
}
|
|
42
45
|
static getCookies(cookieParser, ...cookieHeaderValues) {
|
|
43
46
|
const cookies = {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { HttpMethod, IIncomingRequest, IURL, ReadonlyHeaders } from '../../http';
|
|
2
|
-
export
|
|
2
|
+
export type RequestData<Req> = {
|
|
3
3
|
/**
|
|
4
4
|
* The request URL.
|
|
5
5
|
*/
|
|
6
6
|
url: IURL;
|
|
7
|
+
/**
|
|
8
|
+
* The native url fetched from the environment.
|
|
9
|
+
* It should contain "..", duplicate slashes and un-decoded ascii characters (%XX) if possible.
|
|
10
|
+
*/
|
|
11
|
+
rawUrl: string;
|
|
7
12
|
/**
|
|
8
13
|
* The request method, capitalized.
|
|
9
14
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ReadonlyHeaders } from '../http';
|
|
2
|
-
export
|
|
2
|
+
export type CustomBlockResponseHeadersHandler<Req> = (request: Req) => ReadonlyHeaders | Promise<ReadonlyHeaders>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IMinimalResponse } from '../http';
|
|
2
|
-
export
|
|
2
|
+
export type CustomPreflightHandler<Req> = (request: Req) => IMinimalResponse | Promise<IMinimalResponse>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ConfigurationParams } from '../config';
|
|
2
2
|
import { CustomParameters } from './CustomParameters';
|
|
3
|
-
export
|
|
3
|
+
export type CustomParametersFunction<Req, Res> = (config: ConfigurationParams<Req, Res>, request: Req) => CustomParameters | Promise<CustomParameters>;
|
|
@@ -8,7 +8,7 @@ import { IRiskApiClient } from '../../risk_api';
|
|
|
8
8
|
import { IActivityClient } from '../../activities';
|
|
9
9
|
import { Products } from '../../products';
|
|
10
10
|
import { IGraphQLParser } from '../../graphql';
|
|
11
|
-
export
|
|
11
|
+
export type EnforcerBaseOptions<Req, Res> = {
|
|
12
12
|
httpClient: IHttpClient;
|
|
13
13
|
base64Utils: IBase64Utils;
|
|
14
14
|
hmacUtils: IHmacUtils;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { EnforcerV2Options } from './EnforcerV2Options';
|
|
3
3
|
import { EnforcerV3Options } from './EnforcerV3Options';
|
|
4
|
-
export
|
|
4
|
+
export type EnforcerOptionsType<TokenV extends TokenVersion, Req, Res> = TokenV extends TokenVersion.V2 ? EnforcerV2Options<Req, Res> : TokenV extends TokenVersion.V3 ? EnforcerV3Options<Req, Res> : never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { EnforcerBaseOptions } from './EnforcerBaseOptions';
|
|
3
|
-
export
|
|
3
|
+
export type EnforcerV2Options<Req, Res> = {
|
|
4
4
|
tokenVersion: TokenVersion.V2;
|
|
5
5
|
} & EnforcerBaseOptions<Req, Res>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { ICipherUtils } from '../../utils';
|
|
3
3
|
import { EnforcerBaseOptions } from './EnforcerBaseOptions';
|
|
4
|
-
export
|
|
4
|
+
export type EnforcerV3Options<Req, Res> = {
|
|
5
5
|
tokenVersion: TokenVersion.V3;
|
|
6
6
|
cipherUtils: ICipherUtils;
|
|
7
7
|
} & EnforcerBaseOptions<Req, Res>;
|
|
@@ -29,8 +29,8 @@ export class FormDataImpl {
|
|
|
29
29
|
if (typeof value === 'string') {
|
|
30
30
|
this.data[name] = [value];
|
|
31
31
|
}
|
|
32
|
-
else {
|
|
33
|
-
this.data[name] = [
|
|
32
|
+
else if (File) {
|
|
33
|
+
this.data[name] = [new File([value], filename)];
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncOrSync } from 'ts-essentials';
|
|
2
2
|
import { IOutgoingRequest } from './IOutgoingRequest';
|
|
3
3
|
import { IIncomingResponse } from './IIncomingResponse';
|
|
4
|
-
export
|
|
4
|
+
export type HttpSendOptions = {
|
|
5
5
|
timeoutMs?: number;
|
|
6
6
|
};
|
|
7
7
|
export interface IHttpClient {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepReadonly } from 'ts-essentials';
|
|
2
2
|
import { IHeaders } from './IHeaders';
|
|
3
|
-
export
|
|
3
|
+
export type ReadonlyHeaders = DeepReadonly<Record<string, string[]>>;
|
|
4
4
|
export declare const toReadonlyHeaders: (headers: IHeaders) => ReadonlyHeaders;
|
|
5
5
|
export declare const toMutableHeaders: (headers: ReadonlyHeaders) => Record<string, string[]>;
|
|
6
6
|
export declare const joinHeaderValues: (headers: ReadonlyHeaders) => Record<string, string>;
|
|
@@ -5,7 +5,7 @@ import { IBase64Utils } from '../../utils';
|
|
|
5
5
|
import { IAccountDefender } from './IAccountDefender';
|
|
6
6
|
import { AccountDefenderData } from './AccountDefenderData';
|
|
7
7
|
import { JwtData } from './JwtData';
|
|
8
|
-
export
|
|
8
|
+
export type AccountDefenderOptions = {
|
|
9
9
|
base64Utils: IBase64Utils;
|
|
10
10
|
};
|
|
11
11
|
export declare class AccountDefender<Req, Res> implements IAccountDefender<Req, Res> {
|
|
@@ -11,7 +11,7 @@ import { IBase64Utils, IIpRangeChecker } from '../../utils';
|
|
|
11
11
|
import { IBotDefender } from '../';
|
|
12
12
|
import { BotDefenderData } from './BotDefenderData';
|
|
13
13
|
import { BotDefenderS2SCallReason } from './reasons';
|
|
14
|
-
export
|
|
14
|
+
export type BotDefenderOptions<Req, Res> = {
|
|
15
15
|
base64Utils: IBase64Utils;
|
|
16
16
|
firstParty?: IFirstParty<Req, Res>;
|
|
17
17
|
blocker?: IConditionalBlocker<Req, Res>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ActionData } from '../../action';
|
|
2
|
-
export
|
|
2
|
+
export type BotDefenderData = ActionData & {
|
|
3
3
|
/**
|
|
4
4
|
* Whether the request should go through the enforcement flow in monitor mode.
|
|
5
5
|
* This depends on various configurations including the module mode, monitored routes, enforced
|
|
@@ -13,18 +13,19 @@ export const renderHtml = (htmlTemplate, blockData) => {
|
|
|
13
13
|
};
|
|
14
14
|
export const createBlockData = (config, context) => {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
const
|
|
16
|
+
const captchaScriptSuffix = '/captcha.js';
|
|
17
|
+
const captchaParams = `?a=${context.blockAction}&u=${context.uuid}&v=${context.vid || ''}&m=${context.isMobile ? '1' : '0'}`;
|
|
17
18
|
let jsClientSrc = `${config.backendClientUrl}/${config.appId}/main.min.js`;
|
|
18
|
-
let blockScript = `${config.backendCaptchaUrl}/${config.appId}${captchaParams}`;
|
|
19
|
+
let blockScript = `${config.backendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
|
|
19
20
|
let hostUrl = config.backendCollectorUrl;
|
|
20
21
|
if (config.firstPartyEnabled && !context.isMobile) {
|
|
21
22
|
jsClientSrc = getMostCustomizedFirstPartyPath(config, FirstPartySuffix.SENSOR);
|
|
22
|
-
blockScript = `${getMostCustomizedFirstPartyPath(config, FirstPartySuffix.CAPTCHA)}${captchaParams}`;
|
|
23
|
+
blockScript = `${getMostCustomizedFirstPartyPath(config, FirstPartySuffix.CAPTCHA)}${config.customFirstPartyCaptchaEndpoint ? captchaParams : `${captchaScriptSuffix}${captchaParams}`}`;
|
|
23
24
|
hostUrl = getMostCustomizedFirstPartyPath(config, FirstPartySuffix.XHR);
|
|
24
25
|
}
|
|
25
26
|
const cssRef = config.cssRef ? `<link rel="stylesheet" type="text/css" href="${config.cssRef}" />` : '';
|
|
26
27
|
const jsRef = config.jsRef ? `<script src="${config.jsRef}"></script>` : '';
|
|
27
|
-
const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaParams}`;
|
|
28
|
+
const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
|
|
28
29
|
return {
|
|
29
30
|
appId: config.appId,
|
|
30
31
|
vid: context.vid || ((_b = (_a = context.requestData) === null || _a === void 0 ? void 0 : _a.cookies) === null || _b === void 0 ? void 0 : _b[PXVID_COOKIE_NAME]) || '',
|
|
@@ -2,4 +2,4 @@ import { Action } from '../../../action';
|
|
|
2
2
|
import { BotDefenderBlockReason } from './BotDefenderBlockReason';
|
|
3
3
|
import { BotDefenderPassReason } from './BotDefenderPassReason';
|
|
4
4
|
import { BotDefenderS2SCallReason } from './BotDefenderS2SCallReason';
|
|
5
|
-
export
|
|
5
|
+
export type BotDefenderReasonType<A extends Action> = A extends Action.BLOCK ? BotDefenderBlockReason : A extends Action.SIMULATED_BLOCK ? BotDefenderBlockReason : A extends Action.PASS_REQUEST ? BotDefenderPassReason : A extends Action.TRIGGER_RISK_API ? BotDefenderS2SCallReason : never;
|
|
@@ -2,7 +2,7 @@ import { HttpMethod } from '../../../http';
|
|
|
2
2
|
import { CustomExtractionCallback } from '../model';
|
|
3
3
|
import { PathType, SentThrough, CredentialIntelligenceVersion } from './index';
|
|
4
4
|
import { CustomLoginSuccessfulCallback, LoginSuccessfulReportingMethod } from './login_successful';
|
|
5
|
-
export
|
|
5
|
+
export type CredentialEndpointConfiguration<Req, Res> = {
|
|
6
6
|
/**
|
|
7
7
|
* The URI of the request that contains the credentials.
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type CustomLoginSuccessfulCallback<Res> = (response: Res) => boolean | Promise<boolean>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionData } from '../../../action';
|
|
2
2
|
import { CredentialData } from './CredentialData';
|
|
3
|
-
export
|
|
3
|
+
export type CredentialIntelligenceData = ActionData & CredentialData & {
|
|
4
4
|
endpointIndex?: number;
|
|
5
5
|
isLoginSuccessful?: boolean;
|
|
6
6
|
isCompromised?: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Credentials } from './Credentials';
|
|
2
|
-
export
|
|
2
|
+
export type CustomExtractionCallback<Req> = (request: Req) => Credentials | Promise<Credentials>;
|
|
@@ -2,4 +2,4 @@ import { ProductName } from '../utils';
|
|
|
2
2
|
import { BotDefenderData } from '../bot_defender';
|
|
3
3
|
import { CredentialIntelligenceData } from '../credential_intelligence';
|
|
4
4
|
import { AccountDefenderData } from '../account_defender';
|
|
5
|
-
export
|
|
5
|
+
export type ProductDataType<Name extends ProductName> = Name extends ProductName.BOT_DEFENDER ? BotDefenderData : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? CredentialIntelligenceData : Name extends ProductName.CODE_DEFENDER ? never : Name extends ProductName.ACCOUNT_DEFENDER ? AccountDefenderData : Name extends ProductName.HYPE_SALE_CHALLENGE ? never : never;
|
|
@@ -2,4 +2,4 @@ import { ProductName } from '../utils';
|
|
|
2
2
|
import { IBotDefender } from '../bot_defender';
|
|
3
3
|
import { ICredentialIntelligence } from '../credential_intelligence';
|
|
4
4
|
import { IAccountDefender } from '../account_defender';
|
|
5
|
-
export
|
|
5
|
+
export type ProductType<Name extends ProductName, Req, Res> = Name extends ProductName.BOT_DEFENDER ? IBotDefender<Req, Res> : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? ICredentialIntelligence<Req, Res> : Name extends ProductName.ACCOUNT_DEFENDER ? IAccountDefender<Req, Res> : never;
|
package/lib/pxde/model/PXDE.d.ts
CHANGED
package/lib/pxhd/model/PXHD.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export class PostRiskApiClientBase {
|
|
|
62
62
|
request: {
|
|
63
63
|
ip: context.requestData.ip,
|
|
64
64
|
headers: this.formatRiskHeadersField(context.requestData.headers),
|
|
65
|
-
url: context.requestData.
|
|
65
|
+
url: context.requestData.rawUrl,
|
|
66
66
|
},
|
|
67
67
|
additional: {
|
|
68
68
|
s2s_call_reason: ((_a = context.reasons) === null || _a === void 0 ? void 0 : _a[ProductName.BOT_DEFENDER]) ||
|
|
@@ -3,16 +3,16 @@ import { TokenOrigin } from '../../risk_token';
|
|
|
3
3
|
import { CustomParameters } from '../../custom_parameters';
|
|
4
4
|
import { GraphQLData } from '../../graphql/';
|
|
5
5
|
import { CredentialIntelligenceVersion, SsoStep } from '../../products';
|
|
6
|
-
export
|
|
6
|
+
export type HeaderEntry = {
|
|
7
7
|
name: string;
|
|
8
8
|
value: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type RiskRequestData = {
|
|
11
11
|
ip: string;
|
|
12
12
|
url: string;
|
|
13
13
|
headers: HeaderEntry[];
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type RiskAdditionalData = {
|
|
16
16
|
request_id: string;
|
|
17
17
|
module_version: string;
|
|
18
18
|
s2s_call_reason: string;
|
|
@@ -47,7 +47,7 @@ export declare type RiskAdditionalData = {
|
|
|
47
47
|
ci_version?: CredentialIntelligenceVersion;
|
|
48
48
|
sso_step?: SsoStep;
|
|
49
49
|
} & CustomParameters;
|
|
50
|
-
export
|
|
50
|
+
export type RiskActivity = {
|
|
51
51
|
vid?: string;
|
|
52
52
|
uuid?: string;
|
|
53
53
|
pxhd?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { RiskResponseV3Payload } from './v3';
|
|
3
3
|
import { RiskResponseV2Payload } from './v2';
|
|
4
|
-
export
|
|
4
|
+
export type RiskResponsePayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? RiskResponseV3Payload : TokenV extends TokenVersion.V2 ? RiskResponseV2Payload : never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PXDE } from '../../../pxde';
|
|
2
2
|
import { BlockAction } from '../../../blocker';
|
|
3
3
|
import { RiskStatus } from '../../model';
|
|
4
|
-
export
|
|
4
|
+
export type RiskResponseV2Payload = {
|
|
5
5
|
status: RiskStatus;
|
|
6
6
|
cookie_cfg_block_result?: '0' | '1';
|
|
7
7
|
action?: BlockAction;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockAction } from '../../../blocker';
|
|
2
2
|
import { PXDE } from '../../../pxde';
|
|
3
3
|
import { RiskStatus } from '../../model';
|
|
4
|
-
export
|
|
4
|
+
export type RiskResponseV3Payload = {
|
|
5
5
|
status: RiskStatus;
|
|
6
6
|
score?: number;
|
|
7
7
|
action?: BlockAction;
|
|
@@ -3,7 +3,7 @@ import { TokenParserBase } from './TokenParserBase';
|
|
|
3
3
|
import { TokenVersion } from '../TokenVersion';
|
|
4
4
|
import { IConfiguration } from '../../config';
|
|
5
5
|
import { IToken } from '../token';
|
|
6
|
-
export
|
|
6
|
+
export type DefaultTokenV2ParserOptions = {
|
|
7
7
|
base64Utils: IBase64Utils;
|
|
8
8
|
hmacUtils: IHmacUtils;
|
|
9
9
|
};
|
|
@@ -3,7 +3,7 @@ import { ICipherUtils, IHmacUtils } from '../../utils';
|
|
|
3
3
|
import { TokenVersion } from '../TokenVersion';
|
|
4
4
|
import { IToken } from '../token';
|
|
5
5
|
import { TokenParserBase } from './TokenParserBase';
|
|
6
|
-
export
|
|
6
|
+
export type DefaultTokenV3ParserOptions = {
|
|
7
7
|
cipherUtils: ICipherUtils;
|
|
8
8
|
hmacUtils: IHmacUtils;
|
|
9
9
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenVersion } from '../TokenVersion';
|
|
2
2
|
import { DefaultTokenV3ParserOptions } from './DefaultTokenV3Parser';
|
|
3
3
|
import { DefaultTokenV2ParserOptions } from './DefaultTokenV2Parser';
|
|
4
|
-
export
|
|
4
|
+
export type TokenOptionsType<TokenV> = TokenV extends TokenVersion.V2 ? DefaultTokenV2ParserOptions : DefaultTokenV3ParserOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenVersion } from '../TokenVersion';
|
|
2
2
|
import { TokenV3Payload } from './v3/TokenV3Payload';
|
|
3
3
|
import { TokenV2Payload } from './v2/TokenV2Payload';
|
|
4
|
-
export
|
|
4
|
+
export type TokenPayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? TokenV3Payload : TokenV extends TokenVersion.V2 ? TokenV2Payload : never;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ActivityType } from '../../activities';
|
|
2
2
|
import { ConfigurationParams } from '../../config';
|
|
3
|
-
export
|
|
3
|
+
export type TelemetryActivityDetails = {
|
|
4
4
|
enforcer_configs: ConfigurationParams<unknown, unknown>;
|
|
5
5
|
module_version: string;
|
|
6
6
|
update_reason: 'command';
|
|
7
7
|
node_name?: string;
|
|
8
8
|
os_name?: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type TelemetryActivity = {
|
|
11
11
|
type: ActivityType.ENFORCER_TELEMETRY;
|
|
12
12
|
timestamp: number;
|
|
13
13
|
px_app_id: string;
|
package/lib/utils/constants.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ 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
10
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
11
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.
|
|
11
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.7.0";
|
package/lib/utils/constants.js
CHANGED
|
@@ -8,4 +8,4 @@ export const X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
|
|
|
8
8
|
export const X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
|
|
9
9
|
export const X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
|
|
10
10
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
11
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.
|
|
11
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.7.0';
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IURLParser } from './IURLParser';
|
|
2
|
+
import { IURL } from '../../http';
|
|
3
|
+
export type UrlParserOptions = {
|
|
4
|
+
normalize?: boolean;
|
|
5
|
+
reverseCharactersEncoding?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class DefaultUrlParser implements IURLParser {
|
|
8
|
+
private options;
|
|
9
|
+
constructor(options?: UrlParserOptions);
|
|
10
|
+
parse(rawUrl: string): IURL;
|
|
11
|
+
private reverseCharactersEncoding;
|
|
12
|
+
private normalize;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class DefaultUrlParser {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.options = Object.assign({ normalize: true, reverseCharactersEncoding: false }, options);
|
|
4
|
+
}
|
|
5
|
+
parse(rawUrl) {
|
|
6
|
+
const url = new URL(rawUrl);
|
|
7
|
+
if (this.options.reverseCharactersEncoding) {
|
|
8
|
+
url.pathname = this.reverseCharactersEncoding(url.pathname);
|
|
9
|
+
}
|
|
10
|
+
if (this.options.normalize) {
|
|
11
|
+
url.pathname = this.normalize(url.pathname);
|
|
12
|
+
}
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
reverseCharactersEncoding(path) {
|
|
16
|
+
return decodeURI(path);
|
|
17
|
+
}
|
|
18
|
+
normalize(path) {
|
|
19
|
+
return path.replace(/\/+$/, '').replace(/\/+/g, '/');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export declare const getScoreApiDomain: (appId: string) => string;
|
|
|
6
6
|
export declare const getCollectorDomain: (appId: string) => string;
|
|
7
7
|
export declare const getAuthorizationHeader: (authToken: string) => string;
|
|
8
8
|
export declare const getExtension: (route: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param rawUrl
|
|
12
|
+
* @deprecated use {@link IURLParser} instead.
|
|
13
|
+
*/
|
|
9
14
|
export declare const getDecodedUrl: (rawUrl: string) => IURL;
|
|
10
15
|
export declare const removeSensitiveFields: <T extends Record<string, any>>(object: T, sensitiveFields: (keyof T)[]) => T;
|
|
11
16
|
export declare const removeSensitiveHeaders: (headers: ReadonlyHeaders, sensitiveHeaderNames: string[]) => Record<string, string[]>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -39,8 +39,12 @@ export const getExtension = (route) => {
|
|
|
39
39
|
}
|
|
40
40
|
return endOfPath.substring(extensionIndex);
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param rawUrl
|
|
45
|
+
* @deprecated use {@link IURLParser} instead.
|
|
46
|
+
*/
|
|
42
47
|
export const getDecodedUrl = (rawUrl) => {
|
|
43
|
-
rawUrl = rawUrl.replace(/%/g, '%25');
|
|
44
48
|
try {
|
|
45
49
|
return new URL(decodeURIComponent(rawUrl));
|
|
46
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/crypto-js": "^4.1.1",
|
|
36
36
|
"@types/mocha": "^10.0.0",
|
|
37
37
|
"@types/sinon": "^10.0.13",
|
|
38
|
-
"@types/uuid": "^
|
|
38
|
+
"@types/uuid": "^9.0.2",
|
|
39
39
|
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
40
40
|
"@typescript-eslint/parser": "^5.40.0",
|
|
41
41
|
"chai": "^4.3.6",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"mocha": "^10.0.0",
|
|
50
50
|
"nyc": "^15.1.0",
|
|
51
51
|
"prettier": "^2.7.1",
|
|
52
|
-
"sinon": "^
|
|
52
|
+
"sinon": "^15.2.0",
|
|
53
53
|
"ts-loader": "^9.4.1",
|
|
54
54
|
"ts-node": "^10.9.1",
|
|
55
|
-
"typescript": "^
|
|
55
|
+
"typescript": "^5.1.6"
|
|
56
56
|
},
|
|
57
57
|
"lint-staged": {
|
|
58
58
|
"*.ts": "npm run lint:fix"
|