diff options
author | Andrey Andreev <narf@devilix.net> | 2017-01-09 14:18:25 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2017-01-09 14:18:25 +0100 |
commit | e5b31fce3e74c9b28f9fb9a904b4e2f29873293d (patch) | |
tree | 32a66c3a806f34b2c77c96c432f551b27c756e6e /system/core/Security.php | |
parent | e898e565c60617dbc43186c14018519d8ef05042 (diff) | |
parent | 61fd92498db72bc511effa8c15274596afbb5010 (diff) |
Merge branch 'security' into 3.1-stable
Diffstat (limited to 'system/core/Security.php')
-rw-r--r-- | system/core/Security.php | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/system/core/Security.php b/system/core/Security.php index 8b313a9a2..585ed90ec 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -224,12 +224,9 @@ class CI_Security { } } - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]) - OR $_POST[$this->_csrf_token_name] !== $_COOKIE[$this->_csrf_cookie_name]) // Do the tokens match? - { - $this->csrf_show_error(); - } + // Check CSRF token validity, but don't error on mismatch just yet - we'll want to regenerate + $valid = isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]) + && hash_equals($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]); // We kill this since we're done and we don't want to pollute the _POST array unset($_POST[$this->_csrf_token_name]); @@ -245,6 +242,11 @@ class CI_Security { $this->_csrf_set_hash(); $this->csrf_set_cookie(); + if ($valid !== TRUE) + { + $this->csrf_show_error(); + } + log_message('info', 'CSRF token verified'); return $this; } @@ -499,7 +501,7 @@ class CI_Security { * Becomes: <blink> */ $pattern = '#' - .'<((?<slash>/*\s*)(?<tagName>[a-z0-9]+)(?=[^a-z0-9]|$)' // tag start and name, followed by a non-tag character + .'<((?<slash>/*\s*)((?<tagName>[a-z0-9]+)(?=[^a-z0-9]|$)|.+)' // tag start and name, followed by a non-tag character .'[^\s\042\047a-z0-9>/=]*' // a valid attribute character immediately after the tag would count as a separator // optional attributes .'(?<attributes>(?:[\s\042\047/=]*' // non-attribute characters, excluding > (tag close) for obvious reasons |