Fix CR observations.
This commit is contained in:
davidcallizaya
2017-10-13 10:49:45 -04:00
parent 086cc31982
commit 69b2370ba6
2 changed files with 14 additions and 1 deletions

View File

@@ -261,7 +261,7 @@ class SkinEngine
$template = new TemplatePower($templateFile);
$template->prepare();
$header = '<meta name="csrf-token" content="'. csrfToken().'" />' . "\n" . $header;
$header = '<meta name="csrf-token" content="' . csrfToken() . '" />' . "\n" . $header;
$template->assign('header', $header);
$template->assign('styles', $styles);
$template->assign('bodyTemplate', $body);

View File

@@ -376,6 +376,12 @@ function initUserSession($usrUid, $usrName)
$_SESSION['USR_CSRF_TOKEN'] = Str::random(40);
}
/**
* Verify token for an incoming request.
*
* @param type $request
* @throws TokenMismatchException
*/
function verifyCsrfToken($request)
{
$headers = getallheaders();
@@ -386,11 +392,18 @@ function verifyCsrfToken($request)
: null);
$match = is_string($_SESSION['USR_CSRF_TOKEN'])
&& is_string($token)
&& !empty($_SESSION['USR_CSRF_TOKEN'])
&& hash_equals($_SESSION['USR_CSRF_TOKEN'], $token);
if (!$match) {
throw new TokenMismatchException();
}
}
/**
* Get the current user CSRF token.
*
* @return string
*/
function csrfToken()
{
return isset($_SESSION['USR_CSRF_TOKEN']) ? $_SESSION['USR_CSRF_TOKEN'] : '';