I recently wrote a plugin and now I'm backtracking a bit to sanitize any and all user input. I know that I should sanitize anything that comes from $_GET
or $_POST
as a user can insert malicious scripts into that.
I also am sanitizing anything I'm calling via get_options
that the user inputted just to be safe (not sure if the options.php
API sanitizes but that's another question).
But what about cookies? Do these need to be sanitized? If so how? Here is my function:
$get_cookie_check = wp_kses($_GET['view_full_site'],null); //sanitize user input
$site_url = site_url();
$domain = parse_url($site_url, PHP_URL_HOST);
if($get_cookie_check =='true'){
//set the cookie
setcookie("nifty_cookie", 1, time()+86400, "/", $domain);
$_COOKIE['nifty_cookie'] = 1;
}
}
//cookie variable
$full_site_cookie= $_COOKIE['nifty_cookie'];
I'm not thinking I need to sanitize anything here because I'm the one setting the cookie value (in this case to 1) via PHP. Is this a correct thought?