@@ -210,10 +210,14 @@ class PxEnforcer {
210210 return callback ( ScoreEvaluateAction . S2S_PASS_TRAFFIC ) ;
211211 }
212212
213- this . logger . debug ( `Risk API response returned successfully, risk score: ${ ctx . score } , round_trip_time: ${ ctx . riskRtt } ms` ) ;
213+ this . logger . debug (
214+ `Risk API response returned successfully, risk score: ${ ctx . score } , round_trip_time: ${ ctx . riskRtt } ms` ,
215+ ) ;
214216
215217 if ( action === ScoreEvaluateAction . GOOD_SCORE ) {
216- this . logger . debug ( `Risk score is lower than blocking score. score: ${ ctx . score } blocking score: ${ this . _config . BLOCKING_SCORE } ` ) ;
218+ this . logger . debug (
219+ `Risk score is lower than blocking score. score: ${ ctx . score } blocking score: ${ this . _config . BLOCKING_SCORE } ` ,
220+ ) ;
217221 return callback ( ScoreEvaluateAction . S2S_PASS_TRAFFIC ) ;
218222 }
219223
@@ -248,13 +252,16 @@ class PxEnforcer {
248252
249253 handleVerification ( ctx , req , res , cb ) {
250254 const verified = ctx . score < this . _config . BLOCKING_SCORE ;
255+
251256 if ( res ) {
252257 const setCookie = res . getHeader ( 'Set-Cookie' ) ? res . getHeader ( 'Set-Cookie' ) : '' ;
253258 const secure = this . _config . PXHD_SECURE ? '; Secure' : '' ;
254259 const pxhdCookie = ctx . pxhdServer ? `_pxhd=${ ctx . pxhdServer } ${ secure } ` : '' ;
255260 const setCookieModified = [ setCookie , pxhdCookie ] . filter ( Boolean ) ;
256261 if ( setCookieModified . length > 0 ) {
257- const expires = `expires=${ new Date ( new Date ( ) . getTime ( ) + Constants . MILLISECONDS_IN_YEAR ) . toUTCString ( ) } ` ;
262+ const expires = `expires=${ new Date (
263+ new Date ( ) . getTime ( ) + Constants . MILLISECONDS_IN_YEAR ,
264+ ) . toUTCString ( ) } `;
258265 res . setHeader ( 'Set-Cookie' , `${ setCookieModified } ; ${ expires } ` ) ;
259266 }
260267 }
@@ -285,8 +292,7 @@ class PxEnforcer {
285292 }
286293
287294 // If verified, pass the request here
288- const shouldBypassMonitor = this . _config . BYPASS_MONITOR_HEADER && req . headers [ this . _config . BYPASS_MONITOR_HEADER ] === '1' ;
289- if ( verified || ctx . monitoredRoute || ( this . _config . MODULE_MODE === this . _config . MONITOR_MODE . MONITOR && ! shouldBypassMonitor ) ) {
295+ if ( verified || pxUtil . isReqInMonitorMode ( this . _config , ctx ) ) {
290296 return cb ( ) ;
291297 }
292298
@@ -299,7 +305,9 @@ class PxEnforcer {
299305 ctx . blockAction !== 'r' ;
300306
301307 this . logger . debug (
302- `Enforcing action: ${ pxUtil . parseAction ( ctx . blockAction ) } page is served ${ isJsonResponse ? 'using advanced protection mode' : '' } ` ,
308+ `Enforcing action: ${ pxUtil . parseAction ( ctx . blockAction ) } page is served ${
309+ isJsonResponse ? 'using advanced protection mode' : ''
310+ } `,
303311 ) ;
304312 const config = this . _config ;
305313 this . generateResponse ( ctx , isJsonResponse , function ( responseObject ) {
@@ -369,7 +377,9 @@ class PxEnforcer {
369377 }
370378
371379 if ( this . _config . EXTERNAL_ACTIVITIES && req ) {
372- req . headers [ 'x-px-pagerequested' ] = JSON . stringify ( this . pxClient . generateActivity ( 'page_requested' , details , ctx , this . _config ) ) ;
380+ req . headers [ 'x-px-pagerequested' ] = JSON . stringify (
381+ this . pxClient . generateActivity ( 'page_requested' , details , ctx , this . _config ) ,
382+ ) ;
373383 } else {
374384 this . logger . debug ( 'Sending page requested activity' ) ;
375385 this . pxClient . sendToPerimeterX ( 'page_requested' , details , ctx , this . _config ) ;
@@ -396,7 +406,7 @@ class PxEnforcer {
396406 block_module : 'px-node-express' ,
397407 block_score : ctx . score ,
398408 module_version : this . pxConfig . conf . MODULE_VERSION ,
399- simulated_block : this . _config . MODULE_MODE === this . _config . MONITOR_MODE . MONITOR || ctx . monitoredRoute ,
409+ simulated_block : pxUtil . isReqInMonitorMode ( this . _config , ctx ) ,
400410 ...ctx . additionalFields ,
401411 } ;
402412
@@ -431,17 +441,17 @@ class PxEnforcer {
431441
432442 getProps ( ctx ) {
433443 let jsClientSrc = `//${ this . _config . CLIENT_HOST } /${ this . _config . PX_APP_ID } /main.min.js` ;
434- let captchaSrc = `//${ this . _config . CAPTCHA_HOST } /${ this . _config . PX_APP_ID } /captcha.js?a=${ ctx . blockAction } &u=${ ctx . uuid } &v= ${
435- ctx . vid || ''
436- } &m=${ ctx . isMobile ( ) ? '1' : '0' } `;
444+ let captchaSrc = `//${ this . _config . CAPTCHA_HOST } /${ this . _config . PX_APP_ID } /captcha.js?a=${ ctx . blockAction } &u=${
445+ ctx . uuid
446+ } &v= ${ ctx . vid || '' } & m=${ ctx . isMobile ( ) ? '1' : '0' } `;
437447 let hostUrl = ctx . collectorUrl ;
438448
439449 if ( this . _config . FIRST_PARTY_ENABLED && ! ctx . isMobile ( ) ) {
440450 const prefix = this . _config . PX_APP_ID . substring ( 2 ) ;
441451 jsClientSrc = `/${ prefix } ${ this . _config . FIRST_PARTY_VENDOR_PATH } ` ;
442- captchaSrc = `/${ prefix } ${ this . _config . FIRST_PARTY_CAPTCHA_PATH } /captcha.js?a=${ ctx . blockAction } &u=${ ctx . uuid } &v= ${ ctx . vid || '' } &m= ${
443- ctx . isMobile ( ) ? '1' : '0'
444- } `;
452+ captchaSrc = `/${ prefix } ${ this . _config . FIRST_PARTY_CAPTCHA_PATH } /captcha.js?a=${ ctx . blockAction } &u=${
453+ ctx . uuid
454+ } &v= ${ ctx . vid || '' } &m= ${ ctx . isMobile ( ) ? '1' : '0' } `;
445455 hostUrl = `/${ prefix } ${ this . _config . FIRST_PARTY_XHR_PATH } ` ;
446456 }
447457
0 commit comments