最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Sanitize $_GET variable when comparing

programmeradmin0浏览0评论

I know when I want to save data in database, I must sanitize data but what about following case which is a simple comparison. Should I sanitize?

if ( ! isset( $_GET['page'] ) ) {
        return;
}

if ( 'google' === $_GET['page'] ) {
    wp_redirect( '' );
    exit;
}

if ( 'facebook' === $_GET['page'] ) {
    wp_redirect( '' );
    exit;
}

I know when I want to save data in database, I must sanitize data but what about following case which is a simple comparison. Should I sanitize?

if ( ! isset( $_GET['page'] ) ) {
        return;
}

if ( 'google' === $_GET['page'] ) {
    wp_redirect( 'https://google' );
    exit;
}

if ( 'facebook' === $_GET['page'] ) {
    wp_redirect( 'https://facebook' );
    exit;
}
Share Improve this question asked May 27, 2019 at 3:08 user3631047user3631047 1731 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

No, it's not necessary to sanitise in this case.

If you were redirecting to the value directly, or outputting it in some way, you would definitely need to, but since you're just comparing its value against a white list (essentially) no sanitising or escaping is necessary.

发布评论

评论列表(0)

  1. 暂无评论