Plugin Directory

Changeset 3847089


Ignore:
Timestamp:
12/06/2026 03:16:56 AM (less than one hour ago)
Author:
rrk14mat
Message:

Release 1.2.20: improved spam protection and security.

Location:
mute-spam-blocker/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mute-spam-blocker/trunk/mute-spam-blocker.php

    r3840216 r3847089  
    44 * Plugin URI:  https://mute-it.com/en/
    55 * Description: Automatically blocks spam from contact forms. No CAPTCHA. No friction. Just one script.
    6  * Version:           1.2.19
     6 * Version:           1.2.20
    77 * Author:      Ryu-Raku Inc.
    88 * Author URI:  https://www.ryu-raku.co.jp/
    … …  
    1515if ( ! defined( 'ABSPATH' ) ) { exit; }
    1616
    17 define( 'MUTE_VERSION',    '1.2.19' );
     17define( 'MUTE_VERSION',    '1.2.20' );
    1818define( 'MUTE_API_BASE',   'https://api.mute-it.com' );
    1919define( 'MUTE_VERIFY_URL', MUTE_API_BASE . '/verify' );
    … …  
    5151    // バージョンを添える。MUTE側の管理画面で、古いまま止まっているサイトを見つけるため。
    5252    $url = add_query_arg( 'v', MUTE_VERSION, MUTE_STATUS_URL );
     53    // このサイトの鍵で署名する。
     54    $ts = (string) time();
    5355    $response = wp_remote_get( $url, array(
    5456        '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        ),
    5662    ) );
    5763    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    … …  
    404410}
    405411
     412// 無効化したら、予約した処理(鍵の登録・スパムIPの報告)を残さない
     413register_deactivation_hook( __FILE__, 'mute_clear_scheduled' );
     414function mute_clear_scheduled() {
     415    wp_unschedule_hook( 'mute_bind_key_event' );
     416    wp_unschedule_hook( 'mute_report_spam_ip_event' );
     417}
     418
    406419register_uninstall_hook( __FILE__, 'mute_uninstall' );
    407420function mute_uninstall() {
     421    mute_clear_scheduled();
    408422    delete_transient( MUTE_STATUS_TRANSIENT );
    409423    delete_transient( MUTE_STATUS_STR_TRANSIENT );
    … …  
    672686}
    673687
     688// スパムIPの報告を、WP-Cron の予約に回す(送信への応答を待たせない)。
     689// 予約が MUTE_REPORT_QUEUE_MAX 件を超えたとき・WP-Cron が無効のときは、予約せずにその場で送る(待たない送り方)。
     690define( 'MUTE_REPORT_QUEUE_MAX', 20 );
     691function 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
    674712// バックグラウンドでスパムIPを報告するWP-Cronイベント
    675713add_action( 'mute_report_spam_ip_event', 'mute_report_spam_ip' );
    … …  
    680718}
    681719
    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
    683722function mute_cloudflare_ranges() {
    684723    return array(
    … …  
    753792        'reason'  => $reason,
    754793        'ft'      => $ft,
     794        'bh'      => mute_body_hash(),
    755795        'ua'      => $ua,
    756796        'country' => $country,
    … …  
    769809        'reason'  => $reason,
    770810        'ft'      => $ft,
     811        'bh'      => mute_body_hash(),
    771812        'ua'      => $ua,
    772813        'country' => $country,
    … …  
    774815}
    775816
    776 // トークンを照合する。戻り値: 'ok'(通す)/ 'ng'(不正)/ 'spam_ip'(スパムIPからの送信)
     817// トークンを照合する。戻り値: 'ok'(通す)/ 'ng'(不正)/ 'spam_ip'(スパムIPからの送信)/ 'spam_body'(スパムと同じ文面)
    777818function mute_verify_token( $token, $ip = '' ) {
    778819    if ( empty( $token ) ) return 'ng';
    … …  
    781822    // このサイトのドメインを添える。
    782823    $url .= '&d=' . rawurlencode( mute_home_domain() );
     824    // 送信の文面の指紋
     825    $bh = mute_body_hash();
     826    if ( $bh ) $url .= '&bh=' . rawurlencode( $bh );
    783827    $response = wp_remote_get( $url, array(
    784828        'timeout' => 3,
    … …  
    789833    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    790834    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';
    792837}
    793838
    … …  
    797842    $domain   = preg_replace( '/^www\./i', '', (string) wp_parse_url( home_url(), PHP_URL_HOST ) );
    798843    $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,
    800845    ) );
    801846    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) return false;
    802847    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    803848    return ! empty( $body['block'] );
     849}
     850
     851// フォームの送信らしい POST か(本文がフォームの形式で、中身のある項目が2つ以上)。
     852function 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;
    804862}
    805863
    … …  
    824882    return null;
    825883    // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     884}
     885
     886// ── 送信の文面の指紋 ────────────────────────────────────────────────────────────
     887//   いちばん長い入力欄(ふつうは本文)を、元に戻せない指紋にする。本文そのものは送らない。
     888define( 'MUTE_BODY_MIN_LEN', 50 );
     889
     890function 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 ) );
    826934}
    827935
    … …  
    10211129            'form' => $form_type,
    10221130            'skip' => ( true === apply_filters( 'mute_skip_header_score', false ) ),
     1131            'bh'   => mute_body_hash(),
    10231132            'h'    => array(
    10241133                'referer'        => $header( 'HTTP_REFERER' ),
    … …  
    10921201        }
    10931202        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' );
    11041204        }
    11051205        return;
    … …  
    11371237    //   ただし、スパムIPからの送信はトークンの有無にかかわらず止める(ログイン中のユーザーは対象外)。
    11381238    if ( null === $token ) {
     1239        if ( ! mute_looks_like_form_post() ) return;
    11391240        if ( ! is_user_logged_in() && mute_is_blocking_enabled() ) {
    11401241            $ip = mute_client_ip();
    … …  
    11591260        // 遮断はブロックが有効なときのみ。
    11601261        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の通知を兼ねる
    11621263            status_header( 200 );
    11631264            exit;
    11641265        }
    11651266        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の通知を兼ねる
    11671268            return;
    11681269        }
    11691270
    11701271        // 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 );
    11781273    }
    11791274    // phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
  • mute-spam-blocker/trunk/readme.txt

    r3840216 r3847089  
    55Tested up to:      7.1
    66Requires PHP:      7.4
    7 Stable tag:        1.2.19
     7Stable tag:        1.2.20
    88License:           GPL-2.0-or-later
    99License URI:       https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    1313== Description ==
    1414
    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).
    1616
    1717**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
    … …  
    100100* **Your email address and company or site name** — only when you press the "Start for free" button, to create your MUTE account.
    101101* **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 value may 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.
    103103
    104104A script from the service is also loaded on your public pages to run spam detection.
    … …  
    184184== Changelog ==
    185185
     186= 1.2.20 =
     187* Improved spam protection.
     188* Security improvements.
     189
    186190= 1.2.19 =
    187191* Stronger spam protection for Spectra, SureForms, FormLayer, and JetFormBuilder.
    … …  
    322326== Upgrade Notice ==
    323327
     328= 1.2.20 =
     329Improved spam protection and security. Update recommended.
     330
    324331= 1.2.19 =
    325332Stronger spam protection for Spectra, SureForms, FormLayer, and JetFormBuilder. Update recommended.
Note: See TracChangeset for help on using the changeset viewer.