Changeset 3847089
- Timestamp:
- 12/06/2026 03:16:56 AM (less than one hour ago)
- Location:
- mute-spam-blocker/trunk
- Files:
-
- 2 edited
-
mute-spam-blocker.php (modified) (17 diffs)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mute-spam-blocker/trunk/mute-spam-blocker.php
r3840216 r3847089 4 4 * Plugin URI: https://mute-it.com/en/ 5 5 * Description: Automatically blocks spam from contact forms. No CAPTCHA. No friction. Just one script. 6 * Version: 1.2. 196 * Version: 1.2.20 7 7 * Author: Ryu-Raku Inc. 8 8 * Author URI: https://www.ryu-raku.co.jp/ … … 15 15 if ( ! defined( 'ABSPATH' ) ) { exit; } 16 16 17 define( 'MUTE_VERSION', '1.2. 19' );17 define( 'MUTE_VERSION', '1.2.20' ); 18 18 define( 'MUTE_API_BASE', 'https://api.mute-it.com' ); 19 19 define( 'MUTE_VERIFY_URL', MUTE_API_BASE . '/verify' ); … … 51 51 // バージョンを添える。MUTE側の管理画面で、古いまま止まっているサイトを見つけるため。 52 52 $url = add_query_arg( 'v', MUTE_VERSION, MUTE_STATUS_URL ); 53 // このサイトの鍵で署名する。 54 $ts = (string) time(); 53 55 $response = wp_remote_get( $url, array( 54 56 'timeout' => $timeout, 55 'headers' => array( 'Origin' => get_site_url() ), 57 'headers' => array( 58 'Origin' => get_site_url(), 59 'X-MUTE-Ts' => $ts, 60 'X-MUTE-Sig' => hash_hmac( 'sha256', $ts . '.status|' . strtolower( mute_home_domain() ), mute_site_key() ), 61 ), 56 62 ) ); 57 63 if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { … … 404 410 } 405 411 412 // 無効化したら、予約した処理(鍵の登録・スパムIPの報告)を残さない 413 register_deactivation_hook( __FILE__, 'mute_clear_scheduled' ); 414 function mute_clear_scheduled() { 415 wp_unschedule_hook( 'mute_bind_key_event' ); 416 wp_unschedule_hook( 'mute_report_spam_ip_event' ); 417 } 418 406 419 register_uninstall_hook( __FILE__, 'mute_uninstall' ); 407 420 function mute_uninstall() { 421 mute_clear_scheduled(); 408 422 delete_transient( MUTE_STATUS_TRANSIENT ); 409 423 delete_transient( MUTE_STATUS_STR_TRANSIENT ); … … 672 686 } 673 687 688 // スパムIPの報告を、WP-Cron の予約に回す(送信への応答を待たせない)。 689 // 予約が MUTE_REPORT_QUEUE_MAX 件を超えたとき・WP-Cron が無効のときは、予約せずにその場で送る(待たない送り方)。 690 define( 'MUTE_REPORT_QUEUE_MAX', 20 ); 691 function mute_queue_spam_ip_report( $ip, $reason = '' ) { 692 $send_now = ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ); 693 if ( ! $send_now ) { 694 if ( wp_next_scheduled( 'mute_report_spam_ip_event', array( $ip ) ) ) return; 695 $queued = 0; 696 if ( function_exists( '_get_cron_array' ) ) { 697 foreach ( (array) _get_cron_array() as $hooks ) { 698 if ( isset( $hooks['mute_report_spam_ip_event'] ) ) $queued += count( $hooks['mute_report_spam_ip_event'] ); 699 } 700 } 701 $send_now = $queued >= MUTE_REPORT_QUEUE_MAX; 702 } 703 if ( $send_now ) { 704 $data = array( 'ip' => $ip, 'domain' => wp_parse_url( home_url(), PHP_URL_HOST ) ); 705 if ( '' !== $reason ) $data['reason'] = $reason; 706 mute_report_post( $data, 1, false ); 707 return; 708 } 709 wp_schedule_single_event( time(), 'mute_report_spam_ip_event', array( $ip ) ); 710 } 711 674 712 // バックグラウンドでスパムIPを報告するWP-Cronイベント 675 713 add_action( 'mute_report_spam_ip_event', 'mute_report_spam_ip' ); … … 680 718 } 681 719 682 // Cloudflare の公式IPレンジ(https://www.cloudflare.com/ips/ /2026-08-27 取得)。 720 // Cloudflare の公式IPレンジ(https://www.cloudflare.com/ips/ /2026-08-27 取得・2026-12-06 確認:変更なし)。 721 683 722 function mute_cloudflare_ranges() { 684 723 return array( … … 753 792 'reason' => $reason, 754 793 'ft' => $ft, 794 'bh' => mute_body_hash(), 755 795 'ua' => $ua, 756 796 'country' => $country, … … 769 809 'reason' => $reason, 770 810 'ft' => $ft, 811 'bh' => mute_body_hash(), 771 812 'ua' => $ua, 772 813 'country' => $country, … … 774 815 } 775 816 776 // トークンを照合する。戻り値: 'ok'(通す)/ 'ng'(不正)/ 'spam_ip'(スパムIPからの送信) 817 // トークンを照合する。戻り値: 'ok'(通す)/ 'ng'(不正)/ 'spam_ip'(スパムIPからの送信)/ 'spam_body'(スパムと同じ文面) 777 818 function mute_verify_token( $token, $ip = '' ) { 778 819 if ( empty( $token ) ) return 'ng'; … … 781 822 // このサイトのドメインを添える。 782 823 $url .= '&d=' . rawurlencode( mute_home_domain() ); 824 // 送信の文面の指紋 825 $bh = mute_body_hash(); 826 if ( $bh ) $url .= '&bh=' . rawurlencode( $bh ); 783 827 $response = wp_remote_get( $url, array( 784 828 'timeout' => 3, … … 789 833 $body = json_decode( wp_remote_retrieve_body( $response ), true ); 790 834 if ( isset( $body['ok'] ) && $body['ok'] === true ) return 'ok'; 791 return ( isset( $body['r'] ) && 'spam_ip' === $body['r'] ) ? 'spam_ip' : 'ng'; 835 if ( isset( $body['r'] ) && in_array( $body['r'], array( 'spam_ip', 'spam_body' ), true ) ) return $body['r']; 836 return 'ng'; 792 837 } 793 838 … … 797 842 $domain = preg_replace( '/^www\./i', '', (string) wp_parse_url( home_url(), PHP_URL_HOST ) ); 798 843 $response = wp_remote_get( add_query_arg( array( 'ip' => rawurlencode( $ip ), 'd' => rawurlencode( $domain ) ), MUTE_API_BASE . '/wp/ip-check' ), array( 799 'timeout' => 3,844 'timeout' => 2, 800 845 ) ); 801 846 if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) return false; 802 847 $body = json_decode( wp_remote_retrieve_body( $response ), true ); 803 848 return ! empty( $body['block'] ); 849 } 850 851 // フォームの送信らしい POST か(本文がフォームの形式で、中身のある項目が2つ以上)。 852 function mute_looks_like_form_post() { 853 $ct = isset( $_SERVER['CONTENT_TYPE'] ) ? strtolower( sanitize_text_field( wp_unslash( $_SERVER['CONTENT_TYPE'] ) ) ) : ''; 854 if ( false === strpos( $ct, 'application/x-www-form-urlencoded' ) && false === strpos( $ct, 'multipart/form-data' ) ) return false; 855 $filled = 0; 856 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only counts non-empty fields; values are not used. 857 foreach ( $_POST as $v ) { 858 if ( ( is_string( $v ) && '' !== trim( $v ) ) || ( is_array( $v ) && ! empty( $v ) ) ) $filled++; 859 if ( $filled >= 2 ) return true; 860 } 861 return false; 804 862 } 805 863 … … 824 882 return null; 825 883 // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 884 } 885 886 // ── 送信の文面の指紋 ──────────────────────────────────────────────────────────── 887 // いちばん長い入力欄(ふつうは本文)を、元に戻せない指紋にする。本文そのものは送らない。 888 define( 'MUTE_BODY_MIN_LEN', 50 ); 889 890 function mute_body_hash() { 891 $vals = array(); 892 // phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Only a one-way fingerprint of the submitted text is computed; nothing is stored or output. 893 $collect = static function ( $data, $key = '' ) use ( &$collect, &$vals ) { 894 if ( is_array( $data ) ) { 895 foreach ( $data as $k => $v ) { 896 $k = (string) $k; 897 if ( '' !== $k && ( '_' === $k[0] || 0 === strpos( $k, 'mute_' ) || preg_match( '/^(hp_[0-9a-f]{10}|tk_\d{8}|action|nonce|g-recaptcha-response|h-captcha-response|cf-turnstile-response)$/', $k ) ) ) continue; 898 $collect( $v, $k ); 899 } 900 } elseif ( is_string( $data ) ) { 901 $vals[] = $data; 902 } 903 }; 904 $collect( wp_unslash( $_POST ) ); 905 if ( isset( $_POST['action'], $_POST['data'] ) && 'fluentform_submit' === $_POST['action'] && is_string( $_POST['data'] ) ) { 906 parse_str( wp_unslash( $_POST['data'] ), $fields ); 907 $collect( $fields ); 908 } 909 if ( isset( $_POST['action'], $_POST['formData'] ) && 'nf_ajax_submit' === $_POST['action'] && is_string( $_POST['formData'] ) ) { 910 $nf = json_decode( wp_unslash( $_POST['formData'] ), true ); 911 if ( is_array( $nf ) && isset( $nf['fields'] ) && is_array( $nf['fields'] ) ) { 912 foreach ( $nf['fields'] as $f ) if ( is_array( $f ) && isset( $f['value'] ) && is_string( $f['value'] ) ) $vals[] = $f['value']; 913 } 914 } 915 // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash 916 $text = ''; 917 foreach ( $vals as $v ) if ( strlen( $v ) > strlen( $text ) ) $text = $v; 918 $text = str_replace( "\r\n", "\n", $text ); 919 if ( class_exists( 'Normalizer' ) ) { 920 $n = Normalizer::normalize( $text, Normalizer::FORM_C ); 921 if ( false !== $n && null !== $n ) $text = $n; 922 } 923 $ws = '[\s\x{00a0}\x{1680}\x{2000}-\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}\x{feff}]'; 924 $text = (string) preg_replace( '/^' . $ws . '+|' . $ws . '+$/u', '', $text ); 925 if ( '' === $text || ! function_exists( 'mb_convert_encoding' ) ) return ''; 926 $units = array_values( unpack( 'v*', mb_convert_encoding( $text, 'UTF-16LE', 'UTF-8' ) ) ); 927 if ( count( $units ) < MUTE_BODY_MIN_LEN ) return ''; 928 $fnv = static function ( $seed ) use ( $units ) { 929 $h = $seed; 930 foreach ( $units as $u ) { $h ^= $u; $h = ( $h * 0x01000193 ) & 0xFFFFFFFF; } 931 return $h; 932 }; 933 return 'v1:' . sprintf( '%08x%08x%x', $fnv( 0x811c9dc5 ), $fnv( ( 0x811c9dc5 ^ 0x5bf03635 ) & 0xFFFFFFFF ), count( $units ) ); 826 934 } 827 935 … … 1021 1129 'form' => $form_type, 1022 1130 'skip' => ( true === apply_filters( 'mute_skip_header_score', false ) ), 1131 'bh' => mute_body_hash(), 1023 1132 'h' => array( 1024 1133 'referer' => $header( 'HTTP_REFERER' ), … … 1092 1201 } 1093 1202 if ( 'cf7' === $form_type && $ip ) { 1094 if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { 1095 $domain = wp_parse_url( home_url(), PHP_URL_HOST ); 1096 mute_report_post( array( 1097 'ip' => $ip, 1098 'domain' => $domain, 1099 'reason' => 'cf7_token_missing', 1100 ), 1, false ); 1101 } elseif ( ! wp_next_scheduled( 'mute_report_spam_ip_event', array( $ip ) ) ) { 1102 wp_schedule_single_event( time(), 'mute_report_spam_ip_event', array( $ip ) ); 1103 } 1203 mute_queue_spam_ip_report( $ip, 'cf7_token_missing' ); 1104 1204 } 1105 1205 return; … … 1137 1237 // ただし、スパムIPからの送信はトークンの有無にかかわらず止める(ログイン中のユーザーは対象外)。 1138 1238 if ( null === $token ) { 1239 if ( ! mute_looks_like_form_post() ) return; 1139 1240 if ( ! is_user_logged_in() && mute_is_blocking_enabled() ) { 1140 1241 $ip = mute_client_ip(); … … 1159 1260 // 遮断はブロックが有効なときのみ。 1160 1261 if ( mute_is_blocking_enabled() ) { 1161 mute_report_block( $ip, 'spam_ip' === $verified ? 'spam_ip': 'token_invalid' ); // IPの通知を兼ねる1262 mute_report_block( $ip, in_array( $verified, array( 'spam_ip', 'spam_body' ), true ) ? $verified : 'token_invalid' ); // IPの通知を兼ねる 1162 1263 status_header( 200 ); 1163 1264 exit; 1164 1265 } 1165 1266 if ( mute_is_observing() ) { 1166 mute_report_miss( $ip, 'spam_ip' === $verified ? 'spam_ip': 'token_invalid' ); // IPの通知を兼ねる1267 mute_report_miss( $ip, in_array( $verified, array( 'spam_ip', 'spam_body' ), true ) ? $verified : 'token_invalid' ); // IPの通知を兼ねる 1167 1268 return; 1168 1269 } 1169 1270 1170 1271 // WP-Cronでバックグラウンド実行(フォーム送信レスポンスに影響しない) 1171 if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { 1172 // WP-Cron無効時はフォールバック(blocking:false・失敗しても無視) 1173 $domain = wp_parse_url( home_url(), PHP_URL_HOST ); 1174 mute_report_post( array( 'ip' => $ip, 'domain' => $domain ), 1, false ); 1175 } elseif ( ! wp_next_scheduled( 'mute_report_spam_ip_event', array( $ip ) ) ) { 1176 wp_schedule_single_event( time(), 'mute_report_spam_ip_event', array( $ip ) ); 1177 } 1272 mute_queue_spam_ip_report( $ip ); 1178 1273 } 1179 1274 // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended -
mute-spam-blocker/trunk/readme.txt
r3840216 r3847089 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.2. 197 Stable tag: 1.2.20 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 13 13 == Description == 14 14 15 **NEWS:** Stronger spam protection for Spectra, SureForms, FormLayer, and JetFormBuilder (version 1.2.19).15 **NEWS:** Improved spam protection and security (version 1.2.20). 16 16 17 17 **Supported form plugins:** Contact Form 7, WPForms, Elementor Forms, Ninja Forms, Jetpack Forms, Forminator, Snow Monkey Forms, MW WP Form, Fluent Forms, MetForm, Formidable Forms, Everest Forms, Kadence Blocks, Spectra, SureForms, FormLayer, JetFormBuilder … … 100 100 * **Your email address and company or site name** — only when you press the "Start for free" button, to create your MUTE account. 101 101 * **A random key created by the plugin for your site** — used to connect your site to the service securely. 102 * **Information about form submissions on your site** — the sender's IP address, browser and request information, country and a one-time verification valuemay be sent to detect and block spam. IP addresses of blocked submissions are kept for up to 90 days.102 * **Information about form submissions on your site** — the sender's IP address, browser and request information, country, a one-time verification value, and a one-way fingerprint of the message text (the text itself is never sent) may be sent to detect and block spam. IP addresses of blocked submissions are kept for up to 90 days. 103 103 104 104 A script from the service is also loaded on your public pages to run spam detection. … … 184 184 == Changelog == 185 185 186 = 1.2.20 = 187 * Improved spam protection. 188 * Security improvements. 189 186 190 = 1.2.19 = 187 191 * Stronger spam protection for Spectra, SureForms, FormLayer, and JetFormBuilder. … … 322 326 == Upgrade Notice == 323 327 328 = 1.2.20 = 329 Improved spam protection and security. Update recommended. 330 324 331 = 1.2.19 = 325 332 Stronger spam protection for Spectra, SureForms, FormLayer, and JetFormBuilder. Update recommended.
Note:
See TracChangeset
for help on using the changeset viewer.