0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【警鐘】目に見えない文字でNGワードをすり抜ける

Last updated at Posted at 2024-02-18

掲示板やコメント欄を作るときにNGワードを設定できるようにしたいとする。

仮にNGワードが「竹輪」だったとして、以下のように実装したとする。

JSでの実装イメージ
if (text.includes('竹輪')) {
    alert('不適切なワードが含まれています!');
    return;
}

一見よさそうに見えるが、これでは以下が弾けない。

竹‌輪

なんら変哲もない竹輪という文字列だが、実際はこうなっている。

竹U+200C輪

竹と輪の間にゼロ幅非接合子が入っている。

これにより、単純な文字列比較ではNGワードに引っかからなくすることが出来てしまう。

このような目に見えない文字は以下のサイトにあるように複数存在する。

で?何を言いたいの?

NGワード対策って大変だよね。
ということだけ。
特に解決方法は提示しません。

というか

仮に「竹‌輪」が弾けたとして
悪意あるユーザーは「竹.輪」とかで対応するだろうから
いたちごっこなんだよね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?