From 51996606944feffbf81ad0e7f51425a1be2153eb Mon Sep 17 00:00:00 2001 From: JeiHO Date: Fri, 8 Mar 2024 16:40:24 -0600 Subject: [PATCH] Added unsetToken and unsetSessionIndex methods to AntiCSRF class --- src/AntiCSRF.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/AntiCSRF.php b/src/AntiCSRF.php index 37a996c..64a9308 100644 --- a/src/AntiCSRF.php +++ b/src/AntiCSRF.php @@ -549,4 +549,46 @@ protected static function noHTML(string $untrusted): string { return \htmlentities($untrusted, ENT_QUOTES, 'UTF-8'); } + + /** + * @param string $formIndex + * @return bool + */ + public function unsetToken(string $formIndex): bool + { + if ($this->useNativeSession) { + if (isset($_SESSION[$this->getSessionIndex()][$this->post[$formIndex]])) { + unset($_SESSION[$this->getSessionIndex()][$this->post[$formIndex]]); + return true; + } + return false; + } + + if (isset($this->session[$this->getSessionIndex()][$this->post[$formIndex]])) { + unset($this->session[$this->getSessionIndex()][$this->post[$formIndex]]); + return true; + } + return false; + } + + /** + * @param string $sessionIndex + * @return bool + */ + public function unsetSessionIndex(string $sessionIndex): bool + { + if ($this->useNativeSession) { + if (isset($_SESSION[$sessionIndex])) { + unset($_SESSION[$sessionIndex]); + return true; + } + return false; + } + + if (isset($this->session[$sessionIndex])) { + unset($this->session[$sessionIndex]); + return true; + } + return false; + } }