aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/CSRFProtection.php
diff options
context:
space:
mode:
authorAndré Noack <noack@data-quest.de>2024-12-12 14:52:00 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-12-12 14:52:00 +0000
commit940d2aaa8638b4e0c764579cb3977e7be527c81f (patch)
tree79bd2d7f02359e1bb24931b33513e082f8404a91 /lib/classes/CSRFProtection.php
parent3a2a88172ccbe97aaecf4ea32b97cd07b92dcb11 (diff)
StEP 1552 closes #1552
Closes #1552 Merge request studip/studip!1137
Diffstat (limited to 'lib/classes/CSRFProtection.php')
-rw-r--r--lib/classes/CSRFProtection.php36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/classes/CSRFProtection.php b/lib/classes/CSRFProtection.php
index 05532d4..036aa93 100644
--- a/lib/classes/CSRFProtection.php
+++ b/lib/classes/CSRFProtection.php
@@ -66,7 +66,7 @@ class CSRFProtection
if (!isset(self::$storage)) {
// w/o a session, throw an exception since we cannot use it
if (session_id() === '') {
- throw new SessionRequiredException();
+ throw new SessionRequiredException();
}
self::$storage =& $_SESSION;
@@ -180,4 +180,38 @@ class CSRFProtection
arrayToHtmlAttributes($attributes)
);
}
+
+ /**
+ * returns a random string token for XSRF prevention
+ * the string is stored in the session
+ *
+ * @static
+ * @return string
+ */
+ public static function sessionticket()
+ {
+ $storage = &self::getStorage();
+
+ if (empty($storage['studipticket'])) {
+ $storage['studipticket'] = md5(uniqid('studipticket', 1));
+ }
+ return $storage['studipticket'];
+ }
+
+ /**
+ * checks the given string token against the one stored
+ * in the session
+ *
+ * @static
+ * @param string $studipticket
+ * @return bool
+ */
+ public static function verifySessionticket($studipticket)
+ {
+ $storage = &self::getStorage();
+
+ $check = (isset($storage['studipticket']) && $storage['studipticket'] === $studipticket);
+ $storage['studipticket'] = null;
+ return $check;
+ }
}