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:
@@ -17,8 +17,6 @@ class SMS {
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
add_action('wp_ajax_aksrt_send_sms_code', [$this, 'ajax_send_code']);
|
||||
add_action('wp_ajax_nopriv_aksrt_send_sms_code', [$this, 'ajax_send_code']);
|
||||
add_action('wp_ajax_aksrt_sms_test', [$this, 'ajax_test_provider']);
|
||||
add_action('wp_ajax_aksrt_sms_status', [$this, 'ajax_provider_status']);
|
||||
}
|
||||
@@ -250,60 +248,6 @@ class SMS {
|
||||
* AJAX Handlers
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* 手机号格式校验(对齐 legacy:支持中国号和国际号)
|
||||
*/
|
||||
private function validate_phone(string $phone): bool {
|
||||
$config = $this->get_provider_config();
|
||||
$limit_ch = !isset($config['sms_number_limit_ch']) || !empty($config['sms_number_limit_ch']);
|
||||
|
||||
if ($limit_ch) {
|
||||
// 仅中国大陆手机号
|
||||
return (bool) preg_match('/^1[3-9]\d{9}$/', $phone);
|
||||
}
|
||||
|
||||
// 国际手机号:5 位以上数字,可选 + 前缀
|
||||
return (bool) preg_match('/^(?:\d{5,}|\+\d{6,})$/', $phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX 发送验证码
|
||||
*/
|
||||
public function ajax_send_code(): void {
|
||||
check_ajax_referer('aksrt_sms', '_nonce');
|
||||
|
||||
$phone = sanitize_text_field((string) ($_POST['phone'] ?? ''));
|
||||
if (!$this->validate_phone($phone)) {
|
||||
wp_send_json_error(['message' => __('手机号格式不正确', 'aksrt')]);
|
||||
}
|
||||
|
||||
$scene = sanitize_key((string) ($_POST['scene'] ?? 'register'));
|
||||
if (!array_key_exists($scene, function_exists('aksrt_captcha_scenes') ? aksrt_captcha_scenes() : [])) {
|
||||
$scene = 'register';
|
||||
}
|
||||
if (function_exists('aksrt_require_captcha')) {
|
||||
$captcha_result = aksrt_require_captcha($scene, wp_unslash($_POST));
|
||||
if ($captcha_result !== true) {
|
||||
wp_send_json_error(['message' => $captcha_result ?: __('人机验证失败', 'aksrt')]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->send_code($phone);
|
||||
|
||||
if ($result['success']) {
|
||||
wp_send_json_success([
|
||||
'message' => $result['message'],
|
||||
'remaining_time' => $result['remaining_time'] ?? 60,
|
||||
]);
|
||||
}
|
||||
|
||||
$error_data = ['message' => $result['message']];
|
||||
if (isset($result['remaining_time'])) {
|
||||
$error_data['remaining_time'] = $result['remaining_time'];
|
||||
}
|
||||
wp_send_json_error($error_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: Test SMS provider (admin only).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user