perimeterx / php-sdk
PerimeterX SDK for PHP
Requires
- php: >=5.5
- guzzlehttp/guzzle: ~6.0
- mustache/mustache: ^2.11.1
- psr/log: ^1.0.2
Requires (Dev)
- mockery/mockery: 0.9.*
- overtrue/phplint: ^1.1
- phpunit/phpunit: 5.6.*
- dev-master
- 3.10.2
- 3.10.1
- 3.10.0
- 3.9.1
- 3.9.0
- 3.8.0
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.5
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.3.15
- 1.3.14
- 1.3.13
- 1.3.12
- 1.3.11
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.2
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.0
- 1.1.0
- 1.0.0
- dev-dev
- dev-release/v3.10.2
- dev-fix/custom-params-on-async-activities
- dev-release/v3.10.1
- dev-release/v3.10.0
- dev-SDKNEW-1638/feature
- dev-hotfix/block-page-url-rendering
- dev-release/v3.9.0
- dev-feature/new-block-page
- dev-hotfix/add-creds-to-async-activities
- dev-revert-189-feature/new-block-page
- dev-release/v3.8.0
- dev-feature/new-ci-protocol
- dev-release/v3.7.8
- dev-bugfix/fix-verbosity-error
- dev-feature/px-metadata-update
- dev-release/v3.7.7
- dev-feature/cookie-origin
- dev-feature/graphql-data-on-all-activities
- dev-release/v3.7.6
- dev-bugfix/sensitive-route-mobile
- dev-feature/graphql-mvp
- dev-release/v3.7.5
- dev-hotfix/login-creds-callback
- dev-release/v3.7.4
- dev-feature/login-creds-extraction-callback
- dev-release/v3.7.3
- dev-bugfix/cookie-origin
- dev-ori-test
- dev-bugfix/lowercase-username-cc
- dev-spec/bypass-monitor-header
- dev-feature/compromised-credentials-header
- dev-release/v3.7.2
- dev-bugfix/pxhd-cookie-warning
- dev-feature/align-to-tests
- dev-release/v3.7.1
- dev-feature/module-mode-alignment
- dev-release/v3.7.0
- dev-bugfix/fix-case-insensitive-for-x-block
- dev-bugfix/is-iterable-fix
- dev-release/v3.6.0
- dev-feature/login-creds-extraction
- dev-bugfix/no-pass-reason
- dev-revert-132-bugfix/no-pass-reason
- dev-feature/px_metadata
- dev-documentation/url-delimiters
- dev-bugfix/static-content
- dev-dev-test-moshe
- dev-documentation-upgrade
- dev-dev-block-template
- dev-dev-new_s2s_call_reason
This package is not auto-updated.
Last update: 2024-09-25 14:26:26 UTC
README
PerimeterX PHP SDK
最新稳定版本: v3.10.2
目录
- 阻止分数
- 提取推荐操作
- 自定义阻止页面
- 自定义阻止操作
- 提取真实IP地址
- 自定义URI
- 过滤敏感头部
- 敏感路由
- API超时
- 活动API超时
- 第一方
- Code Defender的第一方
- 发送页面活动
- 额外的页面活动处理器
- 数据丰富
- 丰富自定义参数
- 提取登录凭证
- 额外的S2S活动
- 日志记录
- 模块模式
- 调试模式
- Guzzle客户端处理器
- 自定义阻止URL
- 延迟活动发送
- 高级阻止响应标志
- 返回响应标志
- 在监控模式下测试阻止流程
依赖项
安装
可以使用Composer进行安装。
$ composer require perimeterx/php-sdk
也可以通过下载此存储库的源代码,并运行composer install
来安装。
基本使用示例
use Perimeterx\Perimeterx; $perimeterxConfig = [ 'app_id' => 'APP_ID', 'cookie_key' => 'COOKIE_SECRET', 'auth_token' => 'AUTH_TOKEN', 'blocking_score' => 60, 'module_mode' => Perimeterx::$ACTIVE_MODE ]; /* Obtain PerimeterX SDK instance */ $px = Perimeterx::Instance($perimeterxConfig); /* run verify at the beginning of a page request */ $px->pxVerify();
升级
从Packagist下载新版本。
有关更多信息,请联系PerimeterX支持。
配置选项
配置所需参数
配置选项在$perimeterxConfig
变量中设置。
所需参数
- app_id
- cookie_key
- auth_token
- module_mode
所有参数均可通过PerimeterX门户获取。(应用程序和政策页面)
更改阻止的最低分数
默认阻止值 100
$perimeterxConfig = [ .. 'blocking_score' => 75 .. ]
自定义阻止操作
为了自定义在有效阻止值上执行的操作,请使用'custom_block_handler'选项,并提供一个用户定义的函数。
自定义处理器应包含在访问者收到高于'blocking_score'值的分数时要采取的操作。常见的自定义选项是显示reCAPTCHA或提供定制的品牌阻止页面。
默认阻止行为:返回HTTP状态码403并服务PerimeterX阻止页面。
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_block_handler'] = function ($pxCtx) { $block_score = $pxCtx->getScore(); $block_uuid = $pxCtx->getUuid(); // user defined logic goes here }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
示例
提供自定义HTML页面
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_block_handler'] = function ($pxCtx) { $block_score = $pxCtx->getScore(); $block_uuid = $pxCtx->getUuid(); $full_url = $pxCtx->getFullUrl(); $html = '<div>Access to ' . $full_url . ' has been blocked.</div> ' + '<div>Block reference - ' . $block_uuid . ' </div> ' + '<div>Block score - ' . $block_score . '</div>'; //echo $html; header("Status: 403"); die(); }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
自定义默认阻止页面
自定义logo插入 通过向pxConfig提供一个custom_logo
键,将自定义logo添加到阻止页面。logo将在阻止页面的顶部div中显示。logo的max-height
属性为150px,宽度设置为auto
custom_logo
键期望一个有效的URL地址,例如https://s.perimeterx.net/logo.png
以下示例
$perimeterxConfig = [ 'app_id' => 'APP_ID', 'cookie_key' => 'COOKIE_SECRET', 'auth_token' => 'AUTH_TOKEN', 'blocking_score' => 60, 'custom_logo' => 'LOGO_URL' ];
** 自定义JS/CSS **
可以通过在 pxConfig
中添加 css_ref
键并提供一个有效的 CSS URL 来自定义块页的 CSS。此外,还可以通过向 pxConfig
添加 js_ref
键并提供一个与块页一起加载的 JS 文件来添加自定义 JS 文件。此键也期望一个有效的 URL。
在这两种情况下,如果 URL 格式无效,将会抛出异常。
以下示例
$perimeterxConfig = [ 'app_id' => 'APP_ID', 'cookie_key' => 'COOKIE_SECRET', 'auth_token' => 'AUTH_TOKEN', 'blocking_score' => 60, 'css_ref' => 'CSS_URL', 'js_ref' => 'JS_URL' ];
旁注:可以一起添加自定义的 logo/js/css。
不阻止,仅监控
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_block_handler'] = function ($pxCtx) $block_score = $pxCtx->getScore(); $block_uuid = $pxCtx->getUuid(); $full_url = $pxCtx->getFullUrl(); // user defined logic goes here }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_block_handler'] = function ($pxCtx) { $block_score = $pxCtx->getScore(); $block_uuid = $pxCtx->getUuid(); $action = $pxCtx->getBlockAction(); /* user defined logic comes here */ error_log('px score for user is ' . $block_score); error_log('px recommended action for user is ' . $action); error_log('px page uuid is ' . $block_uuid); switch ($action) { case "block": log("do block"); break; case "captcha": log("do captcha"); break; default: log("unknown action"); } }
模块模式
默认模式: Perimeterx::$MONITOR_MODE
可能值
Perimeterx::$ACTIVE_MODE
- 模块阻止超过预定义阻止阈值的用户。服务器到服务器的请求是同步发送的。Perimeterx::$MONITOR_MODE
- 模块不会阻止超过预定义阻止阈值的用户。如果提供了 pxCustomBlockHandler 函数,则会在超过定义的阻止阈值时评估它。
$perimeterxConfig = [ .. 'module_mode' => Perimeterx::$ACTIVE_MODE .. ]
提取真实用户 IP 地址
注意:根据您的网络配置,IP 提取非常重要。通常在您的应用程序之上有一个负载均衡器/代理,在这种情况下,PerimeterX 模块会将系统的内部 IP 作为用户的 IP 发送。为了正确执行服务器到服务器调用中的处理和检测,PerimeterX 模块需要真实用户的 IP。
可以通过在 $perimeterxConfig 变量上定义的自定义用户函数,或将要提取真实 IP 的头列表按优先级传递给 PerimeterX 模块来传递用户的 IP。
默认无预定义头: $_SERVER['REMOTE_ADDR']
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_user_ip'] = function ($pxCtx) { $headers = getallheaders(); /* using a socket ip */ $ip = $_SERVER['REMOTE_ADDR']; /* using an ip from a x-forwarded-for header */ $xff = explode(",", $headers['X-Forwarded-For']); $ip = $xff[count($xff)-1]; /* using an ip from a custom header */ $ip = $headers['X-REAL-CLIENT-IP']; return $ip; }; $perimeterxConfig = [ .. 'ip_headers' => ['X-TRUE-IP', 'X-Forwarded-For'] .. ] $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
自定义 URI
可以通过在 $perimeterxConfig 变量上定义的自定义用户函数将 URI 返回给 PerimeterX 模块。
默认: $_SERVER['REQUEST_URI']
/** * @param \Perimeterx\PerimeterxContext $pxCtx */ $perimeterxConfig['custom_uri'] = function ($pxCtx) { return $_SERVER['HTTP_X_CUSTOM_URI']; }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
过滤敏感头
可以配置敏感头列表,以防止将特定的头发送到 PerimeterX 服务器(小写头名称)。默认情况下,会过滤 cookie 头以保护隐私,但可以在 $perimeterxConfig 变量上覆盖。
默认:cookie,cookies
$perimeterxConfig = [ .. 'sensitive_headers' => ['cookie', 'cookies', 'secret-header'] .. ]
敏感路由
路由前缀列表。Perimeterx 模块将始终通过此前缀列表匹配请求 URI,如果找到匹配项,即使 cookie 分数低且有效,也将创建服务器到服务器的调用。
默认:无
$perimeterxConfig = [ .. 'sensitive_routes' => ['/login', '/user/profile'] .. ]
API 超时
注意:控制 PerimeterX 请求的超时。当不存在风险 Cookie、已过期或无效时调用 API。
等待 PerimeterX 服务器 API 响应的 API 超时,以秒(浮点数)为单位。
默认 1
$perimeterxConfig = [ .. 'api_timeout' => 2 .. ]
等待连接到 PerimeterX 服务器 API 的 API 连接超时,以秒(浮点数)为单位。
默认 1
$perimeterxConfig = [ .. 'api_connect_timeout' => 2 .. ]
活动 API 超时
注意:控制 PerimeterX 活动请求的超时。
等待 PerimeterX 服务器 API 响应的活动 API 超时,以秒(浮点数)为单位。
默认 1
$perimeterxConfig = [ .. 'activities_timeout' => 2 .. ]
等待连接到 PerimeterX 服务器 API 的活动 API 连接超时,以秒(浮点数)为单位。
默认 1
$perimeterxConfig = [ .. 'activities_connect_timeout' => 2 .. ]
第一方
一个布尔标志,用于启用/禁用第一方模式。
默认: true
$perimeterxConfig = [ .. 'px_first_party_enabled' => false .. ]
代码防御者的第一方
一个布尔标志,用于启用/禁用代码防御者的第一方模式。
默认: false
$perimeterxConfig = [ .. 'px_cd_first_party_enabled' => true .. ]
发送页面活动
一个布尔标志,用于在每个页面请求中启用或禁用活动数据和指标发送到PerimeterX。启用此功能将为PerimeterX门户提供有价值的数据,例如阻止的请求数量和额外的API使用统计信息。
默认: false
$perimeterxConfig = [ .. 'send_page_activities' => true .. ]
附加页面活动处理程序
通过在'$perimeterxConfig'变量上设置'additional_activity_handler'用户定义的函数来添加额外的活动处理程序。'additional_activity_handler'函数将在将数据发送到PerimeterX门户之前执行。
默认值:仅将活动发送到由'$perimeterxConfig'控制的PerimeterX。
/** * @param string $activityType * @param PerimeterxContext $pxCtx * @param array $details */ $perimeterxConfig['additional_activity_handler'] = function ($activityType, $pxCtx, $details) { // user defined logic comes here }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
附加活动处理程序使用示例
记录活动
/** * @param string $activityType * @param PerimeterxContext $pxCtx * @param array $details */ $perimeterxConfig['additional_activity_handler'] = function ($activityType, $pxCtx, $details) use ($logger) { if ($activityType === 'block') { $logger->warning('PerimeterX {activityType} details', ['activityType' => $activityType, 'details' => $details]); } else { $logger->info('PerimeterX {activityType} details', ['activityType' => $activityType, 'details' => $details]); } }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
将活动发送到statsd
/** * @param string $activityType * @param PerimeterxContext $pxCtx * @param array $details */ $perimeterxConfig['additional_activity_handler'] = function ($activityType, $pxCtx, $details) use ($statsd) { $statsd->increment('perimeterx_activity.' . $activityType); }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
数据丰富
用户可以使用附加活动处理程序通过数据丰富对象检索请求的信息。首先验证数据丰富对象已验证,然后您可以访问其属性。
默认: false
/** * @param string $activityType * @param PerimeterxContext $pxCtx * @param array $details */ $perimeterxConfig['additional_activity_handler'] = function ($activityType, $pxCtx, $details) use ($logger) { if($pxCtx->getDataEnrichmentVerified()) { $pxde = $pxCtx->getDataEnrichment(); if($pxde->f_type == 'blacklist') { $logger->info('Filtered request with id: {$pxde->f_id} at: {$pxde->timestamp}'); } } }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
丰富自定义参数
使用enrich_custom_params
函数,您可以将多达10个自定义参数发送回PerimeterX服务器。设置后,该函数将在每个请求设置PerimeterX服务器上的有效载荷之前被调用。参数应按照正确的顺序(1-10)传递。
默认值:未设置
/** * @param array $customParamsArray */ $perimeterxConfig['enrich_custom_params'] = function ($customParamsArray) { // user defined logic comes here }; $px = Perimeterx::Instance($perimeterxConfig); $px->pxVerify();
丰富自定义参数使用示例
/** * @param array $customParamsArray */ $perimeterxConfig['enrich_custom_params'] = function ($customParamsArray) { $customParamsArray['custom_param1'] = "UserId"; $customParamsArray['custom_param2'] = "SesionId"; return $customParamsArray; };
提取登录凭证
此功能从请求中提取凭证(哈希过的用户名和密码),并将它们作为风险API调用中的附加信息发送到PerimeterX。该功能可以开启或关闭,并且可以应用于任何数量的唯一路径。通过修改$perimeterxConfig
数组上的px_login_credentials_extraction_enabled
和px_login_credentials_extraction
属性来调整设置。
如果发现凭证已被泄露,则将在$_REQUEST
对象中添加字段px-compromised-credentials
,其值为"1"
。您可以使用px_compromised_credentials_header
配置来配置此字段的名称。
默认
px_login_credentials_extraction_enabled: false
px_login_credentials_extraction: []
px_compromised_credentials_header: "px-compromised-credentials"
$perimeterxConfig['px_compromised_credentials_header'] = 'px-comp-creds'; $perimeterxConfig['px_login_credentials_extraction_enabled'] = true; $perimeterxConfig['px_login_credentials_extraction'] = [ [ "path" => "/login", // login path, automatically added to sensitive routes "method" => "POST", // supported methods: POST "sent_through" => "body", // supported sent_throughs: body, header, query-param "pass_field" => "password", // name of the password field in the request "user_field" => "username" // name of the username field in the request ], [ ... ], ... ]
还可以定义一个自定义回调来提取用户名和密码。该函数应返回一个包含键user
和pass
的关联数组。如果提取失败,则函数应返回null
。
$perimeterxConfig['px_enable_login_creds_extraction'] = true; $perimeterxConfig['px_login_creds_extraction'] = [ [ "path" => "/login", // login path "method" => "POST", // supported methods: POST "callback_name" => "extractCreds" // name of custom extraction callback ], ... ]; function extractCreds() { // custom implementation resulting in $username and $password if (empty($username) || empty($password)) { return null; } return [ "user" => $username, "pass" => $password ]; }
附加S2S活动
为了增强对登录凭证提取端点的检测,以下附加信息通过additional_s2s
活动发送到PerimeterX:
- 响应代码 - 响应的数值HTTP状态码。这会自动发送。
- 登录成功 - 一个布尔值,指示登录是否成功完成。有关如何提供此数据的选项,请参阅下面的列表。
- 原始用户名 - 用于登录尝试的原始用户名。为了报告此信息,请确保配置
px_send_raw_username_on_additional_s2s_activity
设置为true
。
登录成功报告
有几种不同的方式可以报告登录尝试的成功或失败。如果为空,则登录成功状态始终报告为false
。
默认值:空
$perimeterxConfig['px_login_successful_reporting_method'] = 'status';
状态
提供表示成功登录的状态或状态数组。如果响应的状态码与提供的值或提供的数组中的任何一个匹配,则登录成功状态设置为true
。否则,设置为false
。
注意:要定义状态的范围,请使用
custom
报告方法。
默认值
px_login_successful_status: 200
$perimeterxConfig['px_login_successful_reporting_method'] = 'status'; $perimeterxConfig['px_login_successful_status'] = [200, 202]; // number or array of numbers
头部
提供头部名称和值。如果响应中存在该头部(通过 headers_list()
函数访问)并且与提供的值匹配,则登录成功状态设置为 true
。如果响应中没有找到该头部,或者头部值与配置中的值不匹配,则登录成功状态设置为 false
。
默认值
px_login_successful_header_name: x-px-login-successful
px_login_successful_header_value: 1
$perimeterxConfig['px_login_successful_reporting_method'] = 'header'; $perimeterxConfig['px_login_successful_header_name'] = 'login-successful'; $perimeterxConfig['px_login_successful_header_value'] = 'true';
自定义
提供返回一个布尔值表示登录是否成功的自定义回调。配置字段的值可以是匿名函数或定义为字符串的函数名。
默认值
px_login_successful_custom_callback: null
$perimeterxConfig['px_login_successful_reporting_method'] = 'custom'; // anonymous callback function $perimeterxConfig['px_login_successful_custom_callback'] = function() { // ... return $isLoginSuccessful; }; // name of defined function as string $perimeterxConfig['px_login_successful_custom_callback'] = 'isLoginSuccessfulCallback'; function isLoginSuccessfulCallback() { // ... return $isLoginSuccessful; }
原始用户名
当启用时,如果(1)凭证被识别为受损,并且(2)登录如上所述报告为成功,则将在登录凭据提取端点上报告给 PerimeterX 的原始用户名。
默认: false
$perimeterxConfig['px_send_raw_username_on_additional_s2s_activity'] = true;
手动发送额外的 S2S 活动
默认情况下,此 additional_s2s
活动会自动发送。如果更喜欢手动发送此活动,可以通过将 px_automatic_additional_s2s_activity_enabled
的值配置为 false
来禁用自动发送。
*默认值: true
$perimeterxConfig['px_automatic_additional_s2s_activity_enabled'] = false;
然后可以通过调用函数 $px->pxSendAdditionalS2SActivity()
手动发送此活动,该函数接受以下参数
示例用法
// $px is an instance of the Perimeterx class function handleLogin() { // login flow resulting in boolean $isLoginSuccessful $px->pxSendAdditionalS2SActivity($isLoginSuccessful ? 200 : 401, $isLoginSuccessful); }
如果需要更多灵活性,可以将 additional_s2s
活动的 JSON 表示添加到 $_REQUEST
数组中。如果需要,可以将此活动发送到其他服务器,解析、修改并通过 XHR POST 以 JSON 格式发送给 PerimeterX。为此,请禁用自动发送并启用附加活动头部配置。
默认值
px_additional_s2s_activity_header_enabled: false
$perimeterxConfig['px_automatic_additional_s2s_activity_enabled'] = false; $perimeterxConfig['px_additional_s2s_activity_header_enabled'] = true;
然后可以通过访问 $_REQUEST['px-additional-activity']
和 $_REQUEST['px-additional-activity-url']
分别获取活动负载和 URL 目的地。
function handleLogin() { // custom flow resulting in boolean $isLoginSuccessful $activity = json_decode($_REQUEST['px-additional-activity'], true); $activity['additional']['http_status_code'] = http_status_code(); $activity['additional']['login_successful'] = $isLoginSuccessful; if ($isLoginSuccessful && $activity['additional']['credentials_compromised']) { $activity['additional']['raw_username'] = $_REQUEST['username']; } $url = $_REQUEST['px-additional-activity-url']; $headers = [ 'Content-Type: application/json', 'Authorization: Bearer ' . $_ENV['PX_AUTH_TOKEN'] ]; $body = json_encode($activity); sendPostRequest($url, $headers, $body); } function sendPostRequest($url, $headers, $body) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); curl_exec($curl); }
记录
通过 \Psr\Log\LoggerInterface
的实现记录日志消息(有关完整接口规范,请参阅 PSR-3)。默认情况下,使用 \Perimeterx\PerimeterxLogger
的实例,它将通过 PHP 的 error_log
函数记录所有消息。
默认: \Perimeterx\PerimeterxLogger
实例
$perimeterxConfig = [ .. 'logger' => new \My\Psr\Log\ConcreteLogger() .. ]
调试模式
启用调试日志模式。
默认: false
$perimeterxConfig = [ .. 'debug_mode' => true .. ]
一旦启用,来自 PerimeterX 的调试消息应采用以下模板
[PerimeterX - DEBUG][APP_ID] - MESSAGE
- 对于调试消息
[PerimeterX - ERROR][APP_ID] - MESSAGE
- 对于错误消息
高分数 Cookie 的示例日志
[Mon Dec 4 14:03:50 2017] [PerimeterX - DEBUG][APP_ID] -Starting request verification
[Mon Dec 4 14:03:50 2017] [PerimeterX - DEBUG][APP_ID] -Request context created successfully
[Mon Dec 4 14:03:50 2017] [PerimeterX - DEBUG][APP_ID] -No Captcha cookie present on the request
[Mon Dec 4 14:03:50 2017] [PerimeterX - DEBUG][APP_ID] -Cookie V3 found, Evaluating
[Mon Dec 4 14:03:50 2017] [PerimeterX - DEBUG][APP_ID] -Cookie evaluation ended successfully, risk score: 100
[Mon Dec 4 14:03:51 2017] [PerimeterX - DEBUG][APP_ID] -Enforcing action: Captcha page is served
Guzzle 客户端处理器
允许设置 Guzzle 客户端对象的处理器。
默认: false
$container = []; $history = Middleware::history($container); $handler = HandlerStack::create(); $handler->push($history); $perimeterxConfig = [ .. 'guzzle_handler' => $handler .. ]
自定义阻止 URL
您可以通过指定阻止页面 HTML 文件的 URL 来自定义阻止页面以符合品牌和信息要求。强制执行器将重定向到 custom_block_url
变量中定义的阻止页面。定义的阻止页面将显示 307(临时重定向)HTTP 响应代码。
默认值:未设置
$perimeterxConfig = [ .. 'custom_block_url' => '/block.html' .. ]
高级阻止响应标志
启用/禁用高级阻止响应功能。
默认: false
$perimeterxConfig = [ .. 'enable_json_response' => true .. ]
返回响应标志
启用/禁用返回响应的能力(对于像 Symfony 这样的框架很有用),而不是运行 die()
。
默认: false
$perimeterxConfig = [ .. 'return_response' => true .. ]
延迟活动发送
指定是否应在关闭之前延迟发送页面活动。
默认: true
$perimeterxConfig = [ .. 'defer_activities' => false .. ]
在监控模式下测试拦截流程
允许你在监控模式下测试拦截器的拦截流程。
当设置头部名称(例如 x-px-block
)并且其值为 1
时,当有拦截响应(例如使用值为 PhantomJS/1.0
的 User-Agent 头部)时,将绕过监控模式并应用完全拦截模式。如果缺少其中一个条件,你将保持在监控模式下。这针对每个请求进行。要保持在监控模式下,请将头部值设置为 0
。
可以使用 bypass_monitor_header
属性配置头部名称。
默认值:未设置
$perimeterxConfig = [ .. 'bypass_monitor_header' => 'x-px-block' .. ]
高级拦截响应
在某些特殊情况下(如XHR POST请求),完全渲染验证码页面可能不是一种选择。在这种情况下,使用高级拦截响应返回包含渲染你自己的验证码挑战实现所需的所有信息的JSON对象,无论是弹出模态、页面上的部分等。当请求包含值为 application/json
的 Accept 头部时,将发生高级拦截响应。以下是一个示例JSON响应
{ "appId": String, "jsClientSrc": String, "firstPartyEnabled": Boolean, "vid": String, "uuid": String, "hostUrl": String, "blockScript": String }
一旦你有了JSON响应对象,你可以将其传递到你的实现中(通过查询字符串或其他解决方案)并渲染验证码挑战。
此外,你可以在验证码页面的window对象上添加 _pxOnCaptchaSuccess
回调函数来根据验证码状态做出反应。例如,当使用模态时,你可以使用此回调在验证码成功解决后关闭模态。
以下是一个使用 _pxOnCaptchaSuccess
回调的示例
window._pxOnCaptchaSuccess = function (isValid) { if (isValid) { alert('yay'); } else { alert('nay'); } };
要启用高级拦截响应,请参阅 高级拦截响应标志 部分。
有关创建自定义验证码页面的详细信息,请参阅 文档
其他信息
URI分隔符
PerimeterX根据RFC 3986处理URI路径,使用通用和子分隔符。通用分隔符(例如,?
、#
)用于分隔URI的部分。子分隔符(例如,$
、&
)不用于分割URI,因为它们被认为是URI路径中的有效字符。
贡献
以下步骤欢迎你为我们的项目做出贡献。
分支/克隆
首先,请创建一个仓库分支,并在本地克隆它。在你的分支上创建一个分支,最好使用一个自我描述性的分支名称。
代码/运行
通过实现缺失的功能、添加功能或修复错误来帮助我们改进项目。
要运行代码,只需遵循安装指南中的步骤。从PerimeterX门户获取密钥,并尝试连续刷新你的页面几次。如果没有覆盖默认行为,你应该会看到PerimeterX拦截页面。解决CAPTCHA来清理自己并重新开始。
你可以查看示例应用程序,以了解项目的概貌。
测试
此项目的测试使用PHPUnit编写。
不要忘记测试。项目高度依赖测试,以确保每个用户都有相同的体验,并且没有新功能破坏代码。在创建任何拉取请求之前,请确保您的项目已通过所有测试,如果任何新功能需要它,请编写自己的。
要运行可用的测试套件中的任何测试,首先打开 bootstrap.php.dist
文件,并根据文件中的说明更改值。然后,将 bootstrap.php.dist
重命名为 bootstrap.php
。最后,运行 phpunit tests/PerimeterxCookieValidatorTest
命令以运行所有测试,或使用 phpunit <testName>
执行特定测试(例如 phpunit PerimeterxCookieTest
)
要运行覆盖率测试,运行 phpunit --coverage-html tests/coverage
。这将创建一个包含 HTML 覆盖率的 tests/coverage 目录以供检查。
拉取请求
完成流程后,请向上游仓库创建拉取请求。请提供完整且详细的描述,解释变更内容。请记住,此代码需要我们的维护者阅读,因此请保持其简单、智能和准确。