Do We Need to Validate, Sanitize, or Filter Simple Numerical Superglobals (Cookies and Post)?

Without reading the question, just from the title, the answer is YES. Any input from the outside world should be validated and sanitized where appropriate, and this include inpude the server recieves the fact that it might have been generated in a form you designed is irrelevant. Input should never be trusted. Now about internal … Read more

Unset a Cookie on Successful Gravity Forms form Submission [closed]

I ran this code to try setting a cookie on the gform_after_submission hook and it worked as expected. add_action( ‘gform_after_submission’, function() { setcookie( ‘boom’, ‘boom’, time() + 3600, “https://wordpress.stackexchange.com/” ); } ); The headers should not already be sent when the gform_after_submission action is triggered. If you’re getting a warning about this, there might be … Read more

wp_validate_logged_in_cookie

wp_validate_logged_in_cookie() comment from source: /** * Validates the logged-in cookie. * * Checks the logged-in cookie if the previous auth cookie could not be * validated and parsed. * * This is a callback for the {@see ‘determine_current_user’} filter, rather than API. * * @since 3.9.0 * * @param int|bool $user_id The user ID (or … Read more

How to sanitize my cookie name

Assuming $from_page is a string value and not an array or object, sanitize_key() should do the trick, it allows only a-z0-9_- and I believe is used for permalink. $cookiename = sanitize_key( ‘unrestrict_’.$from_page ); setcookie( cookiename, 1 … there’s a whole bunch of wordpress sanitizing functions, reference available in the docs.

Auth cookie value security risk?

Can they for example simply copy the cookie and “be” logged in as the user who was the original cookie owner? Yes! with the cookie they basically have your login session. You do not want 3rd parties to get the cookie. Keep in mind there is more than 1 cookie, for frontend and for backend. … Read more

Passing a borrowed nonce through Postman fails

For remote apps (cURL, Postman, etc.), or when not using the browser, you should use an authentication plugin like Application Passwords instead of sending the cookies. But if you’d rather send the cookies, then copy and send the WordPress logged-in cookie named wordpress_logged_in_<hash>. Example in cURL: curl -H “X-WP-Nonce: <nonce>” -X POST https://example.com/wp-json/wp/v2/posts -d “Data … Read more

Show greetings on first time visitors?

if you are not looking at coding it yourself then WP Greet Box(http://wordpress.org/extend/plugins/wp-greet-box/) could be used to achieve this. This plugin automatically loads a greeting message based on the referrer and it even allows you to customize the greetings, set time out to auto close the greeting etc. The only problem I see(from your question) … Read more

Set authentication cookies to be shorter but then extend with every page load

You do not need to rewrite wp_set_auth_cookie(), it allows you to change the expiration time of the cookie: add_filter( ‘auth_cookie_expiration’, ‘wpse101378_change_expire_time’, 3 ); function wpse101378_change_expire_time( $expire, $user_id, $remember ){ //The $remember variable indicates whether the user has elected //to be ‘remembered’. //By default, if true, WP sets expire to 14 days if false, 2 days … Read more

Deleting cookie to logout

You can log out the current user with wp_logout() function: I think it is much better approach. wp_logout() destroys current session, clears authorization cookie and call wp_logout action. Also, it is a pluggable function, which means can be redefined by plugins. You can miss important stuff, specially when working in combination with other plugins. If … Read more