= 7) { return substr($digits, 0, 3) . '****' . substr($digits, -4); } return self::account($value); } public static function emailList($value) { return self::maskList($value, [self::class, 'email']); } public static function ipList($value) { return self::maskList($value, [self::class, 'ip']); } public static function accountList($value) { return self::maskList($value, [self::class, 'account']); } public static function ipIfAddress($value) { $value = trim((string) $value); if (!self::shouldMask() || $value === '') { return $value; } return filter_var($value, FILTER_VALIDATE_IP) ? self::ip($value) : $value; } public static function ipsInText($value) { $value = (string) $value; if (!self::shouldMask() || $value === '') { return $value; } $value = preg_replace_callback('/(? $value) { $normalizedKey = preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', (string) $key); $normalizedKey = trim((string) preg_replace('/[^a-z0-9]+/i', '_', strtolower($normalizedKey)), '_'); $secretSuffix = preg_match( '/(?:^|_)(?:pass|password|passwd|password_hash|private_key|secret_key|app_secret|api_secret|access_secret|merchant_secret|signing_secret|signing_key|webhook_secret|client_secret|api_key|apikey|access_key|merchant_key|client_key|auth_key|api_token|apitoken|access_token|refresh_token|auth_token|bearer_token|session_token|csrf_token|relay_token|private_token|secret_token|token|token_hash|key_preview|key_hint|token_hint|authorization_header|credential_key|credential|credentials)$/', $normalizedKey ) === 1; if (in_array($normalizedKey, $secretKeys, true) || $secretSuffix) { unset($data[$key]); continue; } if (is_array($value)) { $data[$key] = self::sanitizeArray($value); continue; } if (!is_scalar($value) && $value !== null) { continue; } if (in_array($normalizedKey, ['email', 'user_email', 'invite_email'], true)) { $data[$key] = self::email($value); } elseif (in_array($normalizedKey, ['ip', 'user_ip', 'request_ip', 'report_ip', 'ip_address', 'reg_ip'], true)) { $data[$key] = self::ip($value); } elseif (in_array($normalizedKey, ['user_name', 'username', 'account', 'apple_id'], true)) { $data[$key] = self::account($value); } elseif (in_array($normalizedKey, [ 'payment_account', 'zhifubao', 'alipay_account', 'wallet_address', 'receive_address', 'from_address', 'to_address', ], true)) { $data[$key] = self::paymentAccount($value); } elseif (in_array($normalizedKey, [ 'server', 'node_ip', 'access_addr', 'access_host', 'base_url', 'url', 'uri', 'path', 'request_path', 'landing_path', 'query', 'request_url', 'request_domain', 'target_url', 'landing_url', 'referrer', 'referer', 'referrer_host', 'site_host', 'host', 'domain', 'endpoint', ], true)) { $data[$key] = self::sensitiveText($value); } elseif (in_array($normalizedKey, [ 'message', 'last_check_message', 'error', 'error_message', 'last_error', 'details', 'reason', 'remark', 'description', 'content', 'user_agent', 'request_user_agent', ], true)) { $data[$key] = self::sensitiveText($value); } } return $data; } private static function maskList($value, $callback) { $value = (string) $value; if (!self::shouldMask() || trim($value) === '') { return $value; } return preg_replace_callback('/[^\s,;]+/', function ($matches) use ($callback) { return call_user_func($callback, $matches[0]); }, $value); } private static function length($value) { return function_exists('mb_strlen') ? mb_strlen($value, 'UTF-8') : strlen($value); } private static function substr($value, $start, $length = null) { if (function_exists('mb_substr')) { return $length === null ? mb_substr($value, $start, null, 'UTF-8') : mb_substr($value, $start, $length, 'UTF-8'); } return $length === null ? substr($value, $start) : substr($value, $start, $length); } }