Search code examples
phpcodeignitercodeigniter-2hmac

CodeIgniter 2.2.0 HMAC mismatch error


UPDATE: Even after downloading the "fixed" 2.2.0, update log files are still filling up with:

Session: HMAC mismatch. The session cookie data did not match what was expected.

After upgrading from CodeIgniter 2.1.3 to 2.2.0 I am getting the error:

Session: HMAC mismatch. The session cookie data did not match what was expected.

The Mcrypt extension is enabled. If I set $config['sess_encrypt_cookie'] = FALSE; (not an option for production) there is no error. Any help greatly appreciated.


Solution

  • CI_Input->_sanitize_globals() function sometimes break encrypted session to fix this problem, I changed /system/core/Input.php (version 2.2, line 636)

    $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
    

    to

    if(!(config_item('sess_encrypt_cookie') === TRUE) || $key!=config_item('sess_cookie_name'))
        $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);