Closed miya0001 closed 4 years ago
たまたま目についたのでつっこみを。笑
esc_url()
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L34
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L52
esc_attr()
esc_html()
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L138-L139
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L71-L72
wp-
file_put_contents()
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L89
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L105
esc_url_raw()
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L125
エスケープは実際にそれが必要かどうかに関係なく使うシチュエーションにあわせてとりあえずやると決めるのが良いです。たとえばHTMLの属性に使うなら esc_attr() 、リンクに使用する URL なら esc_url() などのように利用目的に応じて問答無用でエスケープするのがよいです。
あとファイルに書き込むとかファイルを読み込むとかする場合は、特に慎重にやったほうがいいです。 https://ja.wikipedia.org/wiki/%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%83%88%E3%83%A9%E3%83%90%E3%83%BC%E3%82%B5%E3%83%AB
@miya0001 わかりやすくありがとうございます!直してみます!
Escaping is my pain point that I haven't studied enough. 😭 Thanks for helping!
たまたま目についたのでつっこみを。笑
esc_url()
でエスケープするべきhttps://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L34
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L52
esc_attr()
とesc_html()
でエスケープするべき。https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L138-L139
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L71-L72
wp-
に続く文字は半角英数以外(?)を想定する必要が無いのでは?この正規表現ではスラッシュも含めたすべての文字を通してしまうので、その後のfile_put_contents()
で任意のファイルをぶっ壊すことができる可能性があります。(実際にできるかどうかではなく、そういう心配をしなくてもいいようにするべき。)https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L89
https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L105
esc_url_raw()
でエスケープするべき。(esc_url()
じゃないよ)https://github.com/mayukojpn/force-update-translations/blob/master/force-update-translations.php#L125
エスケープは実際にそれが必要かどうかに関係なく使うシチュエーションにあわせてとりあえずやると決めるのが良いです。たとえばHTMLの属性に使うなら
esc_attr()
、リンクに使用する URL ならesc_url()
などのように利用目的に応じて問答無用でエスケープするのがよいです。あとファイルに書き込むとかファイルを読み込むとかする場合は、特に慎重にやったほうがいいです。 https://ja.wikipedia.org/wiki/%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%83%88%E3%83%A9%E3%83%90%E3%83%BC%E3%82%B5%E3%83%AB