3131use Perimeterx \CredentialsIntelligence \Protocol \CredentialsIntelligenceProtocolFactory ;
3232use Perimeterx \CredentialsIntelligence \LoginSuccess \LoginSuccessfulReportingMethod ;
3333use Perimeterx \CredentialsIntelligence \LoginSuccess \LoginSuccessfulParserFactory ;
34+ use Perimeterx \Utils \GuzzleHttpClient ;
35+
3436final class Perimeterx
3537{
3638 /**
@@ -96,7 +98,7 @@ private function __construct(array $pxConfig = [])
9698 'max_buffer_len ' => 1 ,
9799 'send_page_activities ' => true ,
98100 'send_block_activities ' => true ,
99- 'sdk_name ' => 'PHP SDK v3.9.1 ' ,
101+ 'sdk_name ' => 'PHP SDK v3.10.0 ' ,
100102 'debug_mode ' => false ,
101103 'perimeterx_server_host ' => 'https://sapi- ' . strtolower ($ pxConfig ['app_id ' ]) . '.perimeterx.net ' ,
102104 'captcha_script_host ' => 'https://captcha.px-cdn.net ' ,
@@ -114,10 +116,12 @@ private function __construct(array $pxConfig = [])
114116 'defer_activities ' => true ,
115117 'enable_json_response ' => false ,
116118 'return_response ' => false ,
119+ 'px_first_party_enabled ' => true ,
120+ 'px_cd_first_party_enabled ' => false ,
117121 'px_login_credentials_extraction_enabled ' => false ,
118122 'px_login_credentials_extraction ' => [],
119123 'px_compromised_credentials_header ' => 'px-compromised-credentials ' ,
120- 'px_credentials_intelligence_version ' => CIVersion::V1 ,
124+ 'px_credentials_intelligence_version ' => CIVersion::V2 ,
121125 'px_additional_s2s_activity_header_enabled ' => false ,
122126 'px_automatic_additional_s2s_activity_enabled ' => true ,
123127 'px_send_raw_username_on_additional_s2s_activity ' => false ,
@@ -150,7 +154,11 @@ public function pxVerify()
150154 $ this ->pxConfig ['logger ' ]->debug ('Request will not be verified, module is disabled ' );
151155 return 1 ;
152156 }
153-
157+
158+ if ($ this ->pxConfig ['px_first_party_enabled ' ] || $ this ->pxConfig ['px_cd_first_party_enabled ' ]) {
159+ $ this ->handleFirstParty ();
160+ }
161+
154162 $ additionalFields = $ this ->createAdditionalFields ();
155163
156164 $ pxCtx = new PerimeterxContext ($ this ->pxConfig , $ additionalFields );
@@ -261,21 +269,30 @@ private function handleVerification($pxCtx)
261269 'loader ' => new \Mustache_Loader_FilesystemLoader (dirname (__FILE__ ) . '/templates ' ),
262270 ));
263271
264- $ collectorUrl = 'https://collector- ' . strtolower ($ this ->pxConfig ['app_id ' ]) . '.perimeterx.net ' ;
265272 $ appId = $ this ->pxConfig ['app_id ' ];
273+ $ collectorUrl = 'https://collector- ' . strtolower ($ appId ) . '.perimeterx.net ' ;
274+
275+ $ captchaScript = $ this ->getCaptchaScript ($ this ->pxConfig ['captcha_script_host ' ], $ appId , $ pxCtx );
276+ $ jsClientSrc = "//client.perimeterx.net/ $ appId/main.min.js " ;
277+ if ($ this ->pxConfig ['px_first_party_enabled ' ]) {
278+ $ appIdWithoutPx = substr ($ appId , 2 );
279+ $ captchaScript = $ this ->getCaptchaScript ("/ $ appIdWithoutPx/captcha " , $ appId , $ pxCtx );
280+ $ jsClientSrc = "/ $ appIdWithoutPx/init.js " ;
281+ $ collectorUrl = "/ $ appIdWithoutPx/xhr " ;
282+ }
266283
267284 $ templateInputs = array (
268- 'appId ' => $ this -> pxConfig [ ' app_id ' ] ,
285+ 'appId ' => $ appId ,
269286 'vid ' => $ pxCtx ->getVid (),
270287 'uuid ' => $ block_uuid ,
271288 'cssRef ' => $ this ->getCssRef (),
272289 'jsRef ' => $ this ->getJsRef (),
273290 'hostUrl ' => $ collectorUrl ,
274291 'customLogo ' => isset ($ this ->pxConfig ['custom_logo ' ]) ? $ this ->pxConfig ['custom_logo ' ] : '' ,
275- 'blockScript ' => $ this -> getCaptchaScript ( $ this -> pxConfig [ ' captcha_script_host ' ], $ appId , $ pxCtx ) ,
292+ 'blockScript ' => $ captchaScript ,
276293 'altBlockScript ' => $ this ->getCaptchaScript ($ this ->pxConfig ['alternate_captcha_script_host ' ], $ appId , $ pxCtx ),
277- 'firstPartyEnabled ' => ' false ' ,
278- 'jsClientSrc ' => " //client.perimeterx.net/ { $ this -> pxConfig [ ' app_id ' ]} /main.min.js "
294+ 'firstPartyEnabled ' => $ this -> pxConfig [ ' px_first_party_enabled ' ] ,
295+ 'jsClientSrc ' => $ jsClientSrc
279296 );
280297
281298 http_response_code (403 );
@@ -310,7 +327,7 @@ private function handleVerification($pxCtx)
310327 $ result = array (
311328 'appId ' => $ this ->pxConfig ['app_id ' ],
312329 'jsClientSrc ' => $ templateInputs ['jsClientSrc ' ],
313- 'firstPartyEnabled ' => false ,
330+ 'firstPartyEnabled ' => $ this -> pxConfig [ ' px_first_party_enabled ' ] ,
314331 'vid ' => $ templateInputs ['vid ' ],
315332 'uuid ' => $ templateInputs ['uuid ' ],
316333 'hostUrl ' => $ templateInputs ['hostUrl ' ],
@@ -348,6 +365,29 @@ private function handleVerification($pxCtx)
348365 die ();
349366 }
350367
368+ /**
369+ * Method for handling first party requests for both BD and CD
370+ */
371+ private function handleFirstParty () {
372+ $ pxFirstParty = new PerimeterxFirstPartyClient ($ this ->pxConfig , new GuzzleHttpClient ());
373+
374+ if ($ this ->pxConfig ['px_first_party_enabled ' ]) {
375+ $ response = $ pxFirstParty ->handleFirstParty ();
376+ if (isset ($ response )) {
377+ echo $ response ;
378+ die ();
379+ }
380+ }
381+
382+ if ($ this ->pxConfig ['px_cd_first_party_enabled ' ]) {
383+ $ response = $ pxFirstParty ->handleCodeDefenderFirstParty ();
384+ if (isset ($ response )) {
385+ echo $ response ;
386+ die ();
387+ }
388+ }
389+ }
390+
351391 /*
352392 * Method for assembling the Captcha script tag source
353393 */
0 commit comments