Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit 599abb0

Browse files
authored
Merge pull request #176 from PerimeterX/dev
Dev
2 parents 27e5af2 + ba6975f commit 599abb0

24 files changed

+327
-251
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [3.0.0] - 2021-09-26
9+
10+
### Changed
11+
12+
- Configuration changes to match [Enforcer Spec v1.0.0](https://github.com/PerimeterX/px-enforcer-spec)
13+
814
## [2.13.1] - 2021-07-04
915

1016
### Added

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 PerimeterX
3+
Copyright (c) 2021 PerimeterX
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[PerimeterX](http://www.perimeterx.com) Shared base for NodeJS enforcers
77
=============================================================
88

9-
> Latest stable version: [v2.13.1](https://www.npmjs.com/package/perimeterx-node-core)
9+
> Latest stable version: [v3.0.0](https://www.npmjs.com/package/perimeterx-node-core)
1010
1111
This is a shared base implementation for PerimeterX Express enforcer and future NodeJS enforcers. For a fully functioning implementation example, see the [Node-Express enforcer](https://github.com/PerimeterX/perimeterx-node-express/) implementation.
1212

@@ -30,7 +30,7 @@ Table of Contents
3030
To integrate this module into an enforcer, users should initialize the enforcer.
3131
```javascript
3232
function initPXModule(params, client) {
33-
params.moduleVersion = '<your module version>';
33+
params.px_module_version = '<your module version>';
3434
enforcer = new PxEnforcer(params, client);
3535
//if dynamic configurations is configured
3636
if (enforcer.config.conf.DYNAMIC_CONFIGURATIONS) {
@@ -63,21 +63,23 @@ function pxMiddleware(req, res, next) {
6363

6464
Extend the `PxClient` class to send activities to PerimeterX.
6565
```javascript
66-
const PxClient = require('perimeterx-node-core').PxClient;
66+
const { PxClient } = require('perimeterx-node-core');
67+
6768
class MyClient extends PxClient {
6869
init(config) {
6970
setInterval(() => {
7071
this.submitActivities(config);
7172
}, 1000);
7273
}
7374
}
74-
module.exports = PxExpressClient;
75+
76+
module.exports = { MyClient };
7577
```
7678

7779
Make sure to pass the client instance when initializing the enforcer.
7880
```javascript
7981
function initPXModule(params) {
80-
params.moduleVersion = '<your module version>';
82+
params.px_module_version = '<your module version>';
8183
const pxClient = new MyClient();
8284
enforcer = new PxEnforcer(params, pxClient);
8385
//if dynamic configurations is configured

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Copyright © 2017 PerimeterX, Inc.
1+
/** Copyright © 2021 PerimeterX, Inc.
22
33
** Permission is hereby granted, free of charge, to any
44
** person obtaining a copy of this software and associated

lib/configloader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const request = require('./request');
2+
const { ModuleMode } = require('./enums/ModuleMode');
3+
const { LoggerSeverity } = require('./enums/LoggerSeverity');
24

35
class ConfigLoader {
46

@@ -37,13 +39,13 @@ class ConfigLoader {
3739
this.config.COOKIE_SECRET_KEY = body.cookieKey;
3840
this.config.PX_APP_ID = body.appId;
3941
this.config.BLOCKING_SCORE = body.blockingScore;
40-
this.config.DEBUG_MODE = body.debugMode;
42+
this.config.LOGGER_SEVERITY = body.debugMode ? LoggerSeverity.DEBUG : LoggerSeverity.ERROR;
4143
this.config.ENABLE_MODULE = body.moduleEnabled;
4244
this.config.SENSITIVE_HEADERS = body.sensitiveHeaders;
4345
this.config.IP_HEADERS = body.ipHeaders;
4446
this.config.ACTIVITIES_TIMEOUT = body.connectTimeout;
4547
this.config.API_TIMEOUT_MS = body.riskTimeout;
46-
this.config.MODULE_MODE = body.moduleMode === 'blocking' ? this.config.MONITOR_MODE.BLOCK : this.config.MONITOR_MODE.MONITOR;
48+
this.config.MODULE_MODE = body.moduleMode === 'blocking' ? ModuleMode.ACTIVE_BLOCKING : ModuleMode.MONITOR;
4749
this.config.FIRST_PARTY_ENABLED = body.firstPartyEnabled;
4850
this.config.FIRST_PARTY_XHR_ENABLED = body.firstPartyXhrEnabled;
4951
this.pxClient.sendEnforcerTelemetry('remote_config', this.config);

lib/enums/CookieOrigin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const CookieOrigin = {
2+
NONE: undefined,
3+
COOKIE: 'cookie',
4+
HEADER: 'header'
5+
};
6+
7+
module.exports = {
8+
CookieOrigin
9+
};

lib/enums/LoggerSeverity.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const LoggerSeverity = {
2+
NONE: 'none',
3+
ERROR: 'error',
4+
DEBUG: 'debug',
5+
};
6+
7+
module.exports = {
8+
LoggerSeverity
9+
};

lib/enums/ModuleMode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const ModuleMode = {
2+
ACTIVE_BLOCKING: 'active_blocking',
3+
MONITOR: 'monitor',
4+
};
5+
6+
module.exports = {
7+
ModuleMode
8+
};

lib/pxapi.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const pxUtil = require('./pxutil');
33
const pxHttpc = require('./pxhttpc');
44

55
const S2SErrorInfo = require('./models/S2SErrorInfo');
6-
6+
const { ModuleMode } = require('./enums/ModuleMode');
77
const PassReason = require('./enums/PassReason');
88
const ScoreEvaluateAction = require('./enums/ScoreEvaluateAction');
99
const S2SErrorReason = require('./enums/S2SErrorReason');
@@ -38,7 +38,7 @@ function buildRequestData(ctx, config) {
3838
const headers = pxUtil.formatHeaders(ctx.headers, config.SENSITIVE_HEADERS);
3939
const httpVersion = ctx.httpVersion;
4040
const riskMode =
41-
(config.MODULE_MODE === config.MONITOR_MODE.MONITOR && !ctx.shouldBypassMonitor) || ctx.monitoredRoute
41+
(config.MODULE_MODE === ModuleMode.MONITOR && !ctx.shouldBypassMonitor) || ctx.monitoredRoute
4242
? 'monitor'
4343
: 'active_blocking';
4444

@@ -130,6 +130,9 @@ function evalByServerCall(ctx, config, callback) {
130130
);
131131
ctx.passReason = PassReason.S2S_ERROR;
132132
ctx.s2sErrorInfo = err;
133+
if (res && res.uuid) {
134+
ctx.uuid = res.uuid;
135+
}
133136
return callback(ScoreEvaluateAction.UNEXPECTED_RESULT);
134137
}
135138
ctx.pxhdServer = res.pxhd;

0 commit comments

Comments
 (0)