diff --git a/lib/pxapi.js b/lib/pxapi.js index 5fcce1cf..b07a85e0 100644 --- a/lib/pxapi.js +++ b/lib/pxapi.js @@ -49,7 +49,7 @@ function callServer(ctx, config, callback) { data.additional.px_cookie = JSON.stringify(ctx.decodedCookie); } - pxUtil.prepareCustomParams(config, data.additional); + pxUtil.prepareCustomParams(config, data.additional, ctx.originalRequest); const reqHeaders = { Authorization: 'Bearer ' + config.AUTH_TOKEN, diff --git a/lib/pxclient.js b/lib/pxclient.js index ba2f885b..0c456026 100644 --- a/lib/pxclient.js +++ b/lib/pxclient.js @@ -42,7 +42,7 @@ class PxClient { } if (ctx.pxhdClient && (activityType === 'page_requested' || activityType === 'block')) { pxData.pxhd = ctx.pxhdClient; - pxUtil.prepareCustomParams(config, details); + pxUtil.prepareCustomParams(config, details, ctx.originalRequest); } pxData.details = details; diff --git a/lib/pxcontext.js b/lib/pxcontext.js index 90660113..5b417bc3 100644 --- a/lib/pxcontext.js +++ b/lib/pxcontext.js @@ -16,6 +16,7 @@ class PxContext { this.userAgent = userAgent; this.uri = req.originalUrl || '/'; this.fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl; + this.originalRequest = req.originalRequest; this.httpVersion = req.httpVersion || ''; this.httpMethod = req.method || ''; this.sensitiveRoute = this.isSpecialRoute(config.SENSITIVE_ROUTES, this.uri); diff --git a/lib/pxutil.js b/lib/pxutil.js index 87c0f3d3..8aecbc33 100644 --- a/lib/pxutil.js +++ b/lib/pxutil.js @@ -139,8 +139,9 @@ function filterConfig(config) { * it will populate to @dict with the proper custom params * @param {pxconfig} config - The config object of the application * @param {object} dict - the object that should be populated with the custom params + * @param {object} originalRequest - (optional) original request based on the calling framework * */ -function prepareCustomParams(config, dict) { +function prepareCustomParams(config, dict, originalRequest) { const customParams = { 'custom_param1': '', 'custom_param2': '', @@ -154,7 +155,7 @@ function prepareCustomParams(config, dict) { 'custom_param10': '' }; if (config.ENRICH_CUSTOM_PARAMETERS) { - const enrichedCustomParams = config.ENRICH_CUSTOM_PARAMETERS(customParams); + const enrichedCustomParams = config.ENRICH_CUSTOM_PARAMETERS(customParams, originalRequest); for (const param in enrichedCustomParams) { if (param.match(/^custom_param([1-9]|10)$/) && enrichedCustomParams[param] !== '') { dict[param] = enrichedCustomParams[param]; diff --git a/package-lock.json b/package-lock.json index e6435f11..12250279 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "perimeterx-node-core", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -89,6 +89,7 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, "requires": { "sprintf-js": "~1.0.2" } diff --git a/test/pxutils.test.js b/test/pxutils.test.js index 85b4d7b1..f76b7996 100644 --- a/test/pxutils.test.js +++ b/test/pxutils.test.js @@ -37,7 +37,7 @@ describe('PX Utils - pxutils.js', () => { it('should receive custom params function and custom params object and add only 2 of them', (done) => { const dict = {}; - pxutil.prepareCustomParams(pxConfig.conf, dict); + pxutil.prepareCustomParams(pxConfig.conf, dict, {uri: '/index.html'}); dict['custom_param1'].should.be.exactly('1'); dict['custom_param2'].should.be.exactly('2'); dict['custom_param10'].should.be.exactly('10'); @@ -47,11 +47,14 @@ describe('PX Utils - pxutils.js', () => { }); -function enrichCustomParameters(params) { +function enrichCustomParameters(params, origReq) { params['custom_param1'] = '1'; params['custom_param2'] = '2'; params['custom_param10'] = '10'; params['custom_param11'] = '11'; params['custom'] = '6'; + if ('/index.html' === origReq.uri) { + params['custom_param5'] = 'index'; + } return params; -} \ No newline at end of file +}