feat(captcha): 打通人机验证 11 个场景的前后端完整链路
- 统一验证入口 aksrt_require_captcha(),返回 true|WP_Error,启用场景配置缺失时 fail-closed 拒绝 - 前端公共 API 重构为 window.AKSRTCaptcha(verify/collect/reset/run),单飞锁防并发重复验证,一次性 proof 绑定浏览器 cookie+场景+服务商+主机名 - challenge/exchange REST 端点:challenge 原子占用防票据放大厂商调用,增加频率限制 - 新增 OAuth bind pass:服务端签发 5 分钟一次性令牌,绑定用户+服务商+浏览器,微信扫码延迟消费 - 覆盖场景:评论、登录、注册、绑定第三方、绑定手机、找回密码、修改密码、更改邮箱、资料下载、签到、前台投稿 - 移除 Service 层重复验证与 _auth_code_verified/_defer_login 等客户端可伪造标志,删除下载共享 pass 死代码 - 修复腾讯 TC3 签名 scope、Cloudflare action/cdata/hostname 严格校验、阿里云验签错误码映射 - 后台 Schema 保存对 secret 字段做掩码/保留合并;导入导出过滤 aksrt_captcha_config - 重建 public bundle 与 admin SPA;新增 captcha 运行时/安全/业务契约测试与 harness
This commit is contained in:
+21
-4
@@ -29,6 +29,13 @@ class Moderation {
|
||||
*/
|
||||
private $forced_approved_map = [];
|
||||
|
||||
/**
|
||||
* Request-local depth for comment submissions already admitted by the REST controller.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $captcha_verified_comment_request_depth = 0;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
@@ -50,6 +57,14 @@ class Moderation {
|
||||
add_action('manage_comments_custom_column', [$this, 'render_comments_custom_column'], 10, 2);
|
||||
}
|
||||
|
||||
public function begin_captcha_verified_comment_request(): void {
|
||||
$this->captcha_verified_comment_request_depth++;
|
||||
}
|
||||
|
||||
public function end_captcha_verified_comment_request(): void {
|
||||
$this->captcha_verified_comment_request_depth = max(0, $this->captcha_verified_comment_request_depth - 1);
|
||||
}
|
||||
|
||||
public function get_config(): array {
|
||||
$defaults = [
|
||||
'enabled' => false,
|
||||
@@ -90,17 +105,19 @@ class Moderation {
|
||||
);
|
||||
}
|
||||
|
||||
// 人机验证:覆盖 REST 与原生 wp-comments-post 两条提交合同(与审核开关无关)
|
||||
if (function_exists('aksrt_require_captcha')) {
|
||||
// 人机验证:原生 wp-comments-post 必须验证;REST 已在 Controller 准入时验证一次。
|
||||
if ($this->captcha_verified_comment_request_depth === 0) {
|
||||
$payload = is_array($_POST ?? null) ? wp_unslash($_POST) : [];
|
||||
if (isset($payload['captcha']) && is_array($payload['captcha'])) {
|
||||
$payload = array_merge($payload, $payload['captcha']);
|
||||
}
|
||||
$captcha_result = aksrt_require_captcha('comment', $payload);
|
||||
if ($captcha_result !== true) {
|
||||
$msg = is_string($captcha_result) ? $captcha_result : __('人机验证失败', 'aksrt');
|
||||
$msg = is_wp_error($captcha_result)
|
||||
? $captcha_result->get_error_message()
|
||||
: __('人机验证失败', 'aksrt');
|
||||
wp_die(
|
||||
esc_html($msg),
|
||||
esc_html($msg !== '' ? $msg : __('人机验证失败', 'aksrt')),
|
||||
esc_html__('评论提交失败', 'aksrt'),
|
||||
['response' => 400, 'back_link' => true]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user