Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pxapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function callServer(pxCtx, callback) {
http_method: pxCtx.httpMethod,
risk_mode: riskMode,
module_version: config.MODULE_VERSION,
cookie_origin: pxCtx.cookieOrigin
cookie_origin: pxCtx.cookieOrigin,
request_cookie_names: pxCtx.requestCookieNames
}
};

Expand Down Expand Up @@ -186,3 +187,4 @@ function isBadRiskScore(res, pxCtx) {
return 1;
}
}

1 change: 1 addition & 0 deletions lib/pxcontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PxContext {
this.cookies = {};
this.score = 0;
this.ip = PxContext.extractIP(config, request);
this.requestCookieNames = pxUtil.extractCookieNames(request.headers['cookie']);
this.headers = pxUtil.filterSensitiveHeaders(request.headers);
this.hostname = request.hostname || request.get('host');
this.userAgent = userAgent;
Expand Down
16 changes: 15 additions & 1 deletion lib/pxutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,26 @@ function filterConfig(config) {
return jsonConfig;
}

/**
* extractCookieNames - Extract all the cookie names that were sent in the cookie http header.
* @param {Object} cookieHeader - The received http request cookie header.
*/
function extractCookieNames(cookieHeader) {
let result;
if(cookieHeader){
let cookies = cookieHeader.split(';');
result = cookies.map(cookie => cookie.split('=')[0].trim());
}
return result;
}

module.exports = {
formatHeaders,
filterSensitiveHeaders,
checkForStatic,
verifyDefined,
filterConfig,
parseAction,
generateProxyHeaders
generateProxyHeaders,
extractCookieNames
}
10 changes: 10 additions & 0 deletions test/pxutils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ describe('PX Utils - pxutils.js', () => {
formattedHeaders[0]['value'].should.be.exactly('v');
return done();
});

it('should extract cookie names from the cookie header', (done) => {
var cookieHeader = '_px3=px3Cookie;tempCookie=CookieTemp; _px7=NotARealCookie';
var formattedHeaders = pxutil.extractCookieNames(cookieHeader);
(Object.prototype.toString.call(formattedHeaders)).should.be.exactly('[object Array]');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not formattedHeaders.toString()? this will actually pretty print the array instead of the general [object Array]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to know the type, not the value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case

Suggested change
(Object.prototype.toString.call(formattedHeaders)).should.be.exactly('[object Array]');
Array.isArray(formattedHeaders).should.be.true()

formattedHeaders[0].should.be.exactly('_px3');
formattedHeaders[1].should.be.exactly('tempCookie');
formattedHeaders[2].should.be.exactly('_px7');
return done();
});
});