Cookie Check Failure
If you encounter a "Cookie Check Failure," it may not directly relate to the plugin itself. The issue could stem from cache or optimization plugins potentially interfering with your session and nonce values. You can refer to the documentation provided here for guidance on resolving this issue.
If after performing the steps from the above documentation you still experience this issue, you can look into these other solutions, but it shouldn’t be needed.
Bypass the Nonce check
This is not recommended for security purposes, but you can always bypass this check by using the following filter:
add_filter( 'mwai_rest_authorized', function($rest_nonce, $request) {
return true;
}, 10, 2);
This will always return true, so the check should never fail.
AI Engine code change
This is not recommended, but it might be worth a try. You can change the clean_params function directly in AI Engine’s code and see if that helps you. Please note that this code will be erased every time you update the plugin. You can find this function in “chatbot.php” line 518.
function is_numeric_no_sci($value) {
// Check if the value is numeric
if (is_numeric($value)) {
// Check if it's in scientific notation by looking for patterns like 1e10, 1E10, etc.
if (preg_match('/[+-]?\\d*\\.?\\d+[eE][+-]?\\d+/', $value)) {
return false; // It's numeric in scientific notation, so we don't accept it
}
return true; // It's numeric and not in scientific notation
}
return false; // It's not numeric at all
}
function clean_params( &$params ) {
foreach ( $params as $param => $value ) {
if ( empty( $value ) || is_array( $value ) ) {
continue;
}
$lowerCaseValue = strtolower( $value );
if ( $lowerCaseValue === 'true' || $lowerCaseValue === 'false' || is_bool( $value ) ) {
$params[$param] = filter_var( $value, FILTER_VALIDATE_BOOLEAN );
}
else if ( $this->is_numeric_no_sci( $value ) ) {
$params[$param] = filter_var( $value, FILTER_VALIDATE_FLOAT );
}
}
return $params;
}
LiteSpeed Servers
If you are operating AI Engine on a LiteSpeed server (with ESI/User very turned on) and are using the latest server and plugin versions, you may be experiencing a higher frequency of Cookie Check Failures. After thorough exploration and discussions with LiteSpeed, it has been identified that a combination of factors has led to LiteSpeed NOT purging the wp_rest
nonce, which AI Engine checks. This issue is expected to be addressed in the upcoming release of LiteSpeed.
Here is a temporary solution, verified by LiteSpeed support:
- Edit the file
/plugins/litespeed-cache/litespeed-cache.php
, around line 138. Locate:
$control = \\LiteSpeed\\ESI::cls()->is_nonce_action($action);
Replace it with:
if ($action == 'wp-rest'){
$control = '';
}
- Create a PHP file in your root WordPress directory (where
wp-config.php
is located) and name itesi_nonce_purge.php
. Insert the following code into the file:
<?php
require( './wp-load.php' );
if ( get_option("litespeed.conf_ols_purge_nonce") === false ) {
$current_nonce_tick = wp_nonce_tick();
add_option( 'litespeed.conf_ols_purge_nonce', $current_nonce_tick);
return;
}
$saved_nonce_tick = (int) get_option( 'litespeed.conf_ols_purge_nonce' );
$current_nonce_tick = (int) wp_nonce_tick();
if ( $saved_nonce_tick !== $current_nonce_tick ) {
update_option( 'litespeed.conf_ols_purge_nonce', $current_nonce_tick );
if (defined( 'LSCWP_V' ) ) {
do_action( 'litespeed_purge', 'ESI.nonce' );
}
}
- Set up a system cron job to run every 1 or 5 minutes:
wget -q -O - https://your_domain.com/esi_nonce_purge.php >/dev/null 2>&1
Ensure to replace your_domain.com
with your actual domain.
This process checks the validity of the nonce and purges the ESI tag for wp_rest
if invalid, allowing it to generate a new nonce. Note that this solution only applies if you are using LiteSpeed Enterprise (not LiteSpeed Open Source, which does not support ESI).