返信する: PC/WEBの話題
- これでいいかナ?(Re:xmobile& protectorスパム誤判定)
- 投稿者: なーお 投稿日時: 2007/10/19 8:47
結局、上のロジックの判定文字列数下限値を「80」とし、更に150以上のsinglebyte文字列があれば無条件にアウト、にて様子を見ています。
・文字数が150以上:日本語文字が無いデータが1つあればSPAM(下表の「拒否3」)
・キー名称が'message','com_text','excerpt'で日本語文字がある2文字以上データが1つあれば許可(「許可1」)
・文字数80以上150未満:日本語文字があるデータが1つあれば許可(「許可2」)ループを抜けた段階で「拒否」が優先処理され、「許可」も「拒否」も無いばあいは
(1)判定文字数以上の文字列が無かった場合は「許可」
(2)判定文字数以上の文字列が有った場合「拒否」となる。まとめると、以下の感じです。
1 2 3 4 5 6 7 8
凡例:★=キー名称が'message','com_text','excerpt'のデータ △=その他の文字列 文字byte数 1?2 3?80 81?150 150? ★マルチbyte無 無 無 無 拒否3 ★マルチbyte有 無 許可1 ← ← △マルチbyte無 無 無 無 拒否3 △マルチbyte有 無 無 許可2 ←
d3forumでスルーになった原因は、返信フォームのpost文字列中に「引用」用の文字列がそのまま割り込んで送信されてくるため、上記表の「許可1」の部分に当たったのでした。
singlebyteスパムのほとんどはロボットでしょうから、その場合は「引用」部分は送信されてこないので問題なくブロックされるはずです。
まあ、オリジナルのロジックで判定文字列数下限値を「150」とするのとどちらが良いのか、一概には決められません。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php // Don't enable this for site using single-byte // Perhaps, japanese, schinese, tchinese, and korean can use it class protector_postcommon_post_need_multibyte extends ProtectorFilterAbstract { function execute() { global $xoopsUser ; if( ! function_exists( 'mb_strlen' ) ) return true ; // registered users always pass this plugin if( is_object( $xoopsUser ) ) return true ; $multibyte_cheked = false ; $multibyte_ok = false ; $multibyte_ng = false ; $check_length2 = 150 ; $lengths = array( 0 => 80 , // 'message' => 2 , 'com_text' => 2 , 'excerpt' => 2 , ) ; foreach( $_POST as $key => $data ) { // dare to ignore arrays/objects if( ! is_string( $data ) ) continue ; $check_length = isset( $lengths[ $key ] ) ? $lengths[ $key ] : $lengths[ 0 ] ; if( strlen( $data ) > $check_length ) { $multibyte_cheked = true ; if( strlen( $data ) > mb_strlen( $data )) { $multibyte_ok = true ; } } if(( strlen( $data ) > $check_length2 ) && ( strlen( $data ) == mb_strlen( $data ) )) { $multibyte_ng = true ; break; } } if((($multibyte_checked == true ) && ($multibyte_ok == false )) || $multibyte_ng == true ) { $this->protector->message .= "No multibyte character was found ($data)\n" ; $this->protector->output_log( 'Singlebyte SPAM' , 0 , false , 128 ) ; die( 'Protector rejects your post, because your post looks like SPAM' ) ; } return true ; } } ?>