perimeterx-js-core 0.7.0 → 0.7.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/lib/config/ConfigurationParams.d.ts +1 -0
- package/lib/config/DefaultConfigurations.js +1 -0
- package/lib/config/IConfiguration.d.ts +4 -0
- package/lib/config/StaticConfigurationBase.d.ts +1 -0
- package/lib/config/StaticConfigurationBase.js +3 -0
- package/lib/enforcer/EnforcerBase.d.ts +2 -1
- package/lib/enforcer/EnforcerBase.js +13 -3
- package/lib/enforcer/options/EnforcerBaseOptions.d.ts +2 -0
- package/lib/logger/HttpLogServiceClient.d.ts +17 -0
- package/lib/logger/HttpLogServiceClient.js +60 -0
- package/lib/logger/ILogServiceClient.d.ts +6 -0
- package/lib/logger/ILogServiceClient.js +1 -0
- package/lib/logger/ILogger.d.ts +6 -0
- package/lib/logger/LoggerBase.d.ts +6 -2
- package/lib/logger/LoggerBase.js +12 -1
- package/lib/logger/constants.d.ts +2 -0
- package/lib/logger/constants.js +2 -0
- package/lib/logger/index.d.ts +4 -0
- package/lib/logger/index.js +3 -0
- package/lib/logger/model/EnrichedLogRecord.d.ts +3 -0
- package/lib/logger/model/EnrichedLogRecord.js +1 -0
- package/lib/logger/model/LogMetadata.d.ts +9 -0
- package/lib/logger/model/LogMetadata.js +1 -0
- package/lib/logger/model/LogRecord.d.ts +6 -0
- package/lib/logger/model/LogRecord.js +1 -0
- package/lib/logger/model/index.d.ts +3 -0
- package/lib/logger/model/index.js +3 -0
- package/lib/phase/flow/EndEnforcerFlow.d.ts +6 -0
- package/lib/phase/flow/EndEnforcerFlow.js +10 -0
- package/lib/phase/flow/index.d.ts +1 -0
- package/lib/phase/flow/index.js +1 -0
- package/lib/phase/impl/SendLogsPhase.d.ts +11 -0
- package/lib/phase/impl/SendLogsPhase.js +26 -0
- package/lib/phase/impl/index.d.ts +1 -0
- package/lib/phase/impl/index.js +1 -0
- package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +5 -1
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/package.json +1 -1
|
@@ -73,6 +73,7 @@ export type ConfigurationParams<Req, Res> = {
|
|
|
73
73
|
px_sensitive_graphql_operation_types?: Array<'query' | 'mutation' | 'subscription' | GraphQLOperationType>;
|
|
74
74
|
px_cors_support_enabled?: boolean;
|
|
75
75
|
px_cors_preflight_request_filter_enabled?: boolean;
|
|
76
|
+
px_logger_auth_token?: string;
|
|
76
77
|
px_extract_ip?: () => {};
|
|
77
78
|
px_additional_activity_handler?: AdditionalActivityHandler;
|
|
78
79
|
px_enrich_custom_parameters?: CustomParametersFunction<Req, Res>;
|
|
@@ -301,6 +301,10 @@ export interface IConfiguration<Req, Res, ParamsType extends ConfigurationParams
|
|
|
301
301
|
* The default login successful custom callback to use if none is defined for an endpoint.
|
|
302
302
|
*/
|
|
303
303
|
readonly ciDefaultLoginSuccessfulCustomCallback: CustomLoginSuccessfulCallback<Res>;
|
|
304
|
+
/**
|
|
305
|
+
* The authentication token for the logging service.
|
|
306
|
+
*/
|
|
307
|
+
readonly loggerAuthToken: string;
|
|
304
308
|
/**
|
|
305
309
|
* Returns an object representation of the current configuration.
|
|
306
310
|
*/
|
|
@@ -76,6 +76,7 @@ export declare abstract class StaticConfigurationBase<Req, Res, ParamsType exten
|
|
|
76
76
|
get jwtHeaderName(): string;
|
|
77
77
|
get jwtHeaderUserIdFieldName(): string;
|
|
78
78
|
get ciEnabled(): boolean;
|
|
79
|
+
get loggerAuthToken(): string;
|
|
79
80
|
get ciEndpoints(): CredentialEndpointConfiguration<Req, Res>[];
|
|
80
81
|
get ciCompromisedCredentialsHeaderName(): string;
|
|
81
82
|
get ciSendRawUsernameOnAdditionalS2SActivity(): boolean;
|
|
@@ -236,6 +236,9 @@ export class StaticConfigurationBase {
|
|
|
236
236
|
get ciEnabled() {
|
|
237
237
|
return this.configParams.px_login_credentials_extraction_enabled;
|
|
238
238
|
}
|
|
239
|
+
get loggerAuthToken() {
|
|
240
|
+
return this.configParams.px_logger_auth_token;
|
|
241
|
+
}
|
|
239
242
|
get ciEndpoints() {
|
|
240
243
|
return this.configParams.px_login_credentials_extraction;
|
|
241
244
|
}
|
|
@@ -13,6 +13,7 @@ export declare abstract class EnforcerBase<TokenV extends TokenVersion, Req, Res
|
|
|
13
13
|
protected readonly filterFlow: IPhase<Req, Res>;
|
|
14
14
|
protected readonly enforceFlow: IPhase<Req, Res>;
|
|
15
15
|
protected readonly postEnforceFlow: IPhase<Req, Res>;
|
|
16
|
+
protected readonly endEnforcerFlow: IPhase<Req, Res>;
|
|
16
17
|
protected readonly activityClient: IActivityClient<Req, Res>;
|
|
17
18
|
/**
|
|
18
19
|
* Constructs the concrete request context given the provided EnforceArgs.
|
|
@@ -42,7 +43,7 @@ export declare abstract class EnforcerBase<TokenV extends TokenVersion, Req, Res
|
|
|
42
43
|
* @returns Promise<Res> - A Promise resolving to Res.
|
|
43
44
|
* @protected
|
|
44
45
|
*/
|
|
45
|
-
protected abstract convertToRes(response: IMinimalResponse): Promise<Res>;
|
|
46
|
+
protected abstract convertToRes(response: IMinimalResponse, ...args: EnforceArgs): Promise<Res>;
|
|
46
47
|
/**
|
|
47
48
|
* Converts the Res object into the IOutgoingResponse interface.
|
|
48
49
|
* @param args - PostEnforceArgs
|
|
@@ -12,10 +12,11 @@ import { DefaultTelemetry } from '../telemetry';
|
|
|
12
12
|
import { DefaultTokenV2Parser, DefaultTokenV3Parser, TokenVersion } from '../risk_token';
|
|
13
13
|
import { DefaultCors } from '../cors';
|
|
14
14
|
import { PostRiskApiClientV2, PostRiskApiClientV3 } from '../risk_api';
|
|
15
|
-
import { EnforceFlow, FilterFlow, PostEnforceFlow } from '../phase';
|
|
15
|
+
import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../phase';
|
|
16
16
|
import { AccountDefender, BotDefender, CredentialIntelligence, ProductName } from '../products';
|
|
17
17
|
import { HttpActivityClient, HttpBatchedActivityClient } from '../activities';
|
|
18
18
|
import { DefaultGraphQLParser } from '../graphql';
|
|
19
|
+
import { HttpLogServiceClient } from '../logger';
|
|
19
20
|
export class EnforcerBase {
|
|
20
21
|
/**
|
|
21
22
|
* The EnforcerBase constructor.
|
|
@@ -30,6 +31,7 @@ export class EnforcerBase {
|
|
|
30
31
|
this.filterFlow = new FilterFlow(config, initializationBlock);
|
|
31
32
|
this.enforceFlow = new EnforceFlow(config, initializationBlock);
|
|
32
33
|
this.postEnforceFlow = new PostEnforceFlow(config, initializationBlock);
|
|
34
|
+
this.endEnforcerFlow = new EndEnforcerFlow(config, initializationBlock);
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* The central function that triggers enforcement on the incoming request.
|
|
@@ -62,11 +64,16 @@ export class EnforcerBase {
|
|
|
62
64
|
const context = yield this.constructContext(...args);
|
|
63
65
|
let result = yield this.filterFlow.execute(context);
|
|
64
66
|
if (result.done) {
|
|
65
|
-
|
|
67
|
+
yield this.endEnforcerFlow.execute(context);
|
|
68
|
+
return result.response ? this.convertToRes(result.response, ...args) : null;
|
|
66
69
|
}
|
|
67
70
|
this.preserveContext(context, ...args);
|
|
68
71
|
result = yield this.enforceFlow.execute(context);
|
|
69
|
-
|
|
72
|
+
if (result.response) {
|
|
73
|
+
yield this.endEnforcerFlow.execute(context);
|
|
74
|
+
return this.convertToRes(result.response, ...args);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
70
77
|
});
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
@@ -83,6 +90,7 @@ export class EnforcerBase {
|
|
|
83
90
|
context.response = yield this.convertToOutgoingResponse(...args);
|
|
84
91
|
yield this.postEnforceFlow.execute(context);
|
|
85
92
|
}
|
|
93
|
+
yield this.endEnforcerFlow.execute(context);
|
|
86
94
|
}
|
|
87
95
|
catch (e) {
|
|
88
96
|
this.config.logger.error(`caught error in post enforce - ${e}`);
|
|
@@ -124,6 +132,7 @@ export class EnforcerBase {
|
|
|
124
132
|
(config.maxActivityBatchSize > 1
|
|
125
133
|
? new HttpBatchedActivityClient(config, httpClient)
|
|
126
134
|
: new HttpActivityClient(config, httpClient));
|
|
135
|
+
const logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new HttpLogServiceClient(config, httpClient) : null);
|
|
127
136
|
const allOptions = {
|
|
128
137
|
httpClient,
|
|
129
138
|
base64Utils,
|
|
@@ -137,6 +146,7 @@ export class EnforcerBase {
|
|
|
137
146
|
tokenParser,
|
|
138
147
|
riskApiClient,
|
|
139
148
|
activityClient,
|
|
149
|
+
logServiceClient,
|
|
140
150
|
};
|
|
141
151
|
const products = this.initializeProducts(config, options.products, base64Utils, hashUtils, ipRangeChecker);
|
|
142
152
|
return Object.assign({ products }, allOptions);
|
|
@@ -8,6 +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
|
+
import { ILogServiceClient } from '../../logger';
|
|
11
12
|
export type EnforcerBaseOptions<Req, Res> = {
|
|
12
13
|
httpClient: IHttpClient;
|
|
13
14
|
base64Utils: IBase64Utils;
|
|
@@ -22,4 +23,5 @@ export type EnforcerBaseOptions<Req, Res> = {
|
|
|
22
23
|
telemetry?: ITelemetry<Req, Res>;
|
|
23
24
|
riskApiClient?: IRiskApiClient<Req, Res>;
|
|
24
25
|
activityClient?: IActivityClient<Req, Res>;
|
|
26
|
+
logServiceClient?: ILogServiceClient<Req, Res>;
|
|
25
27
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EnrichedLogRecord, LogRecord } from './model';
|
|
2
|
+
import { ReadonlyContext } from '../context';
|
|
3
|
+
import { IConfiguration } from '../config';
|
|
4
|
+
import { IHttpClient } from '../http';
|
|
5
|
+
import { ILogger } from '../logger';
|
|
6
|
+
import { ILogServiceClient } from './ILogServiceClient';
|
|
7
|
+
export declare class HttpLogServiceClient<Req, Res> implements ILogServiceClient<Req, Res> {
|
|
8
|
+
protected readonly appId: string;
|
|
9
|
+
protected readonly backendUrl: string;
|
|
10
|
+
protected readonly loggerAuthToken: string;
|
|
11
|
+
protected readonly logger: ILogger;
|
|
12
|
+
protected readonly httpClient: IHttpClient;
|
|
13
|
+
constructor(config: IConfiguration<Req, Res>, httpClient: IHttpClient);
|
|
14
|
+
sendLogs(context: ReadonlyContext<Req, Res>, logs: LogRecord[]): Promise<void>;
|
|
15
|
+
protected enrichLogRecord(context: ReadonlyContext<Req, Res>, log: LogRecord): EnrichedLogRecord;
|
|
16
|
+
protected postLogs(logRecords: EnrichedLogRecord[]): Promise<boolean>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { EXTERNAL_LOGGER_SERVICE_PATH } from './constants';
|
|
11
|
+
import { AUTHORIZATION_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, ContentType, HttpMethod, OutgoingRequestImpl, } from '../http';
|
|
12
|
+
import { getAuthorizationHeader } from '../utils';
|
|
13
|
+
export class HttpLogServiceClient {
|
|
14
|
+
constructor(config, httpClient) {
|
|
15
|
+
this.appId = config.appId;
|
|
16
|
+
this.backendUrl = config.backendScoreApiUrl;
|
|
17
|
+
this.loggerAuthToken = config.loggerAuthToken;
|
|
18
|
+
this.logger = config.logger;
|
|
19
|
+
this.httpClient = httpClient;
|
|
20
|
+
}
|
|
21
|
+
sendLogs(context, logs) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
try {
|
|
24
|
+
const enrichedLogs = logs.map((log) => this.enrichLogRecord(context, log));
|
|
25
|
+
yield this.postLogs(enrichedLogs);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
this.logger.error(`unable to send logs: ${e}`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
enrichLogRecord(context, log) {
|
|
33
|
+
const requestData = context.requestData;
|
|
34
|
+
const url = new URL(requestData.rawUrl);
|
|
35
|
+
const logMeta = {
|
|
36
|
+
container: 'enforcer',
|
|
37
|
+
appID: this.appId,
|
|
38
|
+
method: requestData.method,
|
|
39
|
+
host: url.host,
|
|
40
|
+
url: requestData.rawUrl,
|
|
41
|
+
path: url.pathname + requestData.url.search,
|
|
42
|
+
requestId: context.requestId,
|
|
43
|
+
};
|
|
44
|
+
return Object.assign(Object.assign({}, logMeta), log);
|
|
45
|
+
}
|
|
46
|
+
postLogs(logRecords) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const url = `${this.backendUrl}${EXTERNAL_LOGGER_SERVICE_PATH}`;
|
|
49
|
+
const method = HttpMethod.POST;
|
|
50
|
+
const headers = {
|
|
51
|
+
[CONTENT_TYPE_HEADER_NAME]: [ContentType.APPLICATION_JSON],
|
|
52
|
+
[AUTHORIZATION_HEADER_NAME]: [getAuthorizationHeader(this.loggerAuthToken)],
|
|
53
|
+
};
|
|
54
|
+
const body = JSON.stringify(logRecords);
|
|
55
|
+
const req = new OutgoingRequestImpl({ url, method, headers, body });
|
|
56
|
+
const res = yield this.httpClient.send(req);
|
|
57
|
+
return (res === null || res === void 0 ? void 0 : res.status) === 200;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReadonlyContext } from '../context';
|
|
2
|
+
import { LogRecord } from './model';
|
|
3
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
4
|
+
export interface ILogServiceClient<Req, Res> {
|
|
5
|
+
sendLogs(context: ReadonlyContext<Req, Res>, logs: LogRecord[]): AsyncOrSync<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/logger/ILogger.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LoggerSeverity } from './LoggerSeverity';
|
|
2
|
+
import { LogRecord } from './model';
|
|
2
3
|
export interface ILogger {
|
|
3
4
|
/**
|
|
4
5
|
* @returns LoggerSeverity - The current logger severity.
|
|
@@ -21,4 +22,9 @@ export interface ILogger {
|
|
|
21
22
|
* @returns void
|
|
22
23
|
*/
|
|
23
24
|
error(message: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get all the saved logs for that request
|
|
27
|
+
* @returns LogRecord[]
|
|
28
|
+
*/
|
|
29
|
+
getLogs(): LogRecord[];
|
|
24
30
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ILogger } from './ILogger';
|
|
2
2
|
import { LoggerSeverity } from './LoggerSeverity';
|
|
3
|
+
import { LogRecord } from './model';
|
|
3
4
|
export declare abstract class LoggerBase implements ILogger {
|
|
4
|
-
|
|
5
|
-
protected
|
|
5
|
+
protected loggerSeverity: LoggerSeverity;
|
|
6
|
+
protected logs: LogRecord[];
|
|
7
|
+
protected constructor(loggerSeverity?: LoggerSeverity, logs?: LogRecord[]);
|
|
6
8
|
protected abstract log(message: string): void;
|
|
7
9
|
debug(message: string): void;
|
|
8
10
|
error(message: string): void;
|
|
@@ -10,4 +12,6 @@ export declare abstract class LoggerBase implements ILogger {
|
|
|
10
12
|
setLoggerSeverity(loggerSeverity: LoggerSeverity): void;
|
|
11
13
|
protected logError(message: string): void;
|
|
12
14
|
protected logDebug(message: string): void;
|
|
15
|
+
getLogs(): LogRecord[];
|
|
16
|
+
protected recordLog(message: string, loggerSeverity: LoggerSeverity): void;
|
|
13
17
|
}
|
package/lib/logger/LoggerBase.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { LoggerSeverity } from './LoggerSeverity';
|
|
2
2
|
export class LoggerBase {
|
|
3
|
-
constructor(loggerSeverity = LoggerSeverity.ERROR) {
|
|
3
|
+
constructor(loggerSeverity = LoggerSeverity.ERROR, logs = []) {
|
|
4
4
|
this.loggerSeverity = loggerSeverity;
|
|
5
|
+
this.logs = logs;
|
|
5
6
|
}
|
|
6
7
|
debug(message) {
|
|
8
|
+
this.recordLog(message, LoggerSeverity.DEBUG);
|
|
7
9
|
if (this.loggerSeverity == LoggerSeverity.DEBUG) {
|
|
8
10
|
this.logDebug(message);
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
error(message) {
|
|
14
|
+
this.recordLog(message, LoggerSeverity.ERROR);
|
|
12
15
|
if (this.loggerSeverity != LoggerSeverity.NONE) {
|
|
13
16
|
this.logError(message);
|
|
14
17
|
}
|
|
@@ -27,4 +30,12 @@ export class LoggerBase {
|
|
|
27
30
|
logDebug(message) {
|
|
28
31
|
this.log(message);
|
|
29
32
|
}
|
|
33
|
+
// default implementation, can be overridden
|
|
34
|
+
getLogs() {
|
|
35
|
+
return this.logs;
|
|
36
|
+
}
|
|
37
|
+
recordLog(message, loggerSeverity) {
|
|
38
|
+
const logRecord = { message: message, severity: loggerSeverity, messageTimestamp: Date.now() };
|
|
39
|
+
this.logs.push(logRecord);
|
|
40
|
+
}
|
|
30
41
|
}
|
package/lib/logger/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export { ILogger } from './ILogger';
|
|
2
|
+
export { ILogServiceClient } from './ILogServiceClient';
|
|
2
3
|
export { LoggerBase } from './LoggerBase';
|
|
4
|
+
export { HttpLogServiceClient } from './HttpLogServiceClient';
|
|
3
5
|
export { DefaultLogger } from './DefaultLogger';
|
|
4
6
|
export { LoggerSeverity } from './LoggerSeverity';
|
|
7
|
+
export * from './constants';
|
|
8
|
+
export * from './model';
|
package/lib/logger/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IConfiguration } from '../../config';
|
|
2
|
+
import { CompositePhase } from '../impl';
|
|
3
|
+
import { EnforcerBaseOptions } from '../../enforcer';
|
|
4
|
+
export declare class EndEnforcerFlow<Req, Res> extends CompositePhase<Req, Res> {
|
|
5
|
+
constructor(config: IConfiguration<Req, Res>, { logServiceClient }: Required<EnforcerBaseOptions<Req, Res>>);
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CompositePhase, SendLogsPhase } from '../impl';
|
|
2
|
+
export class EndEnforcerFlow extends CompositePhase {
|
|
3
|
+
constructor(config, { logServiceClient }) {
|
|
4
|
+
const phasesArray = [];
|
|
5
|
+
if (logServiceClient) {
|
|
6
|
+
phasesArray.push(new SendLogsPhase(config, logServiceClient));
|
|
7
|
+
}
|
|
8
|
+
super(phasesArray);
|
|
9
|
+
}
|
|
10
|
+
}
|
package/lib/phase/flow/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IContext } from '../../context';
|
|
2
|
+
import { IPhase } from '../IPhase';
|
|
3
|
+
import { PhaseResult } from '../PhaseResult';
|
|
4
|
+
import { IConfiguration } from '../../config';
|
|
5
|
+
import { ILogServiceClient } from '../../logger';
|
|
6
|
+
export declare class SendLogsPhase<Req, Res> implements IPhase<Req, Res> {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly logServiceClient;
|
|
9
|
+
constructor(config: IConfiguration<Req, Res>, logServiceClient: ILogServiceClient<Req, Res>);
|
|
10
|
+
execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { X_PX_ENFORCER_LOG_HEADER } from '../../logger';
|
|
11
|
+
export class SendLogsPhase {
|
|
12
|
+
constructor(config, logServiceClient) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.logServiceClient = logServiceClient;
|
|
15
|
+
}
|
|
16
|
+
execute(context) {
|
|
17
|
+
var _a;
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const headerValue = (_a = context.requestData.headers[X_PX_ENFORCER_LOG_HEADER]) === null || _a === void 0 ? void 0 : _a[0];
|
|
20
|
+
if (headerValue == this.config.loggerAuthToken) {
|
|
21
|
+
yield this.logServiceClient.sendLogs(context, this.config.logger.getLogs());
|
|
22
|
+
}
|
|
23
|
+
return { done: false };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
package/lib/phase/impl/index.js
CHANGED
|
@@ -9,7 +9,11 @@ export class DefaultBotDefenderFilter {
|
|
|
9
9
|
shouldFilter(context) {
|
|
10
10
|
const { requestData } = context;
|
|
11
11
|
const filterReason = this.getFilterReason(requestData);
|
|
12
|
-
|
|
12
|
+
if (filterReason !== FilterReason.NONE) {
|
|
13
|
+
this.config.logger.debug(`filter request due to ${filterReason}`);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
13
17
|
}
|
|
14
18
|
getFilterReason(request) {
|
|
15
19
|
if (this.shouldFilterByExtension(request)) {
|
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.7.
|
|
11
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.7.1";
|
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.7.
|
|
11
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.7.1';
|