Reading through the source code
|
switch ($type) { |
|
case 'sid': |
|
return $value === csrf_hash(session_id(), $time); |
|
case 'cookie': |
|
$n = $GLOBALS['csrf']['cookie']; |
|
if (!$n) return false; |
|
if (!isset($_COOKIE[$n])) return false; |
|
return $value === csrf_hash($_COOKIE[$n], $time); |
|
case 'key': |
|
if (!$GLOBALS['csrf']['key']) return false; |
|
return $value === csrf_hash($GLOBALS['csrf']['key'], $time); |
|
// We could disable these 'weaker' checks if 'key' was set, but |
|
// that doesn't make me feel good then about the cookie-based |
|
// implementation. |
|
case 'user': |
|
if (!csrf_get_secret()) return false; |
|
if ($GLOBALS['csrf']['user'] === false) return false; |
|
return $value === csrf_hash($GLOBALS['csrf']['user'], $time); |
|
case 'ip': |
I was wondering how to use the key or user feature. Could you provide an example of how to create a static secret to put into a form?
Background is having an automatic login into a form-based authentication that has csrf protection.
Reading through the source code
csrf-magic/csrf-magic.php
Lines 306 to 324 in 7d3527a
Background is having an automatic login into a form-based authentication that has csrf protection.