70 $session_id = $this->session->getID();
77 $returnval = $request->
elgg()->events->triggerResults(
'action_gatekeeper:permissions:check',
'all', [
85 throw new CsrfException($request->
elgg()->translator->translate(
'actiongatekeeper:pluginprevents'));
89 if ($request->
isXhr()) {
91 'js:security:token_refresh_failed',
92 [$this->config->wwwroot]
95 throw new CsrfException($request->
elgg()->translator->translate(
'actiongatekeeper:timeerror'));
100 if ($request->
isXhr()) {
101 throw new CsrfException($request->
elgg()->translator->translate(
'js:security:token_refresh_failed', [$this->config->wwwroot]));
103 throw new CsrfException($request->
elgg()->translator->translate(
'actiongatekeeper:tokeninvalid'));
107 $error_msg = $request->
elgg()->translator->translate(
'actiongatekeeper:missingfields');
137 return ($timeout == 0 || (
$ts > $now - $timeout) && (
$ts < $now + $timeout));
152 if ($this->config->hasValue(
'action_token_timeout')) {
154 $timeout = $this->config->action_token_timeout;
159 return (
int) ((float) $timeout * $hour);
175 return $this->crypto->areEqual(
$token, $required_token);
188 if (!$session_token) {
189 $session_token = $this->session->get(
'__elgg_session');
190 if (!$session_token) {
196 ->getHmac([(
int)
$timestamp, $session_token],
'md5')
isValidToken($token, $ts)
Basic token validation.
getActionTokenTimeout()
Returns the action token timeout in seconds.
trait TimeUsing
Adds methods for setting the current time (for testing)
getParam($key, $default=null, $filter=true)
Get an element of the params array.
isXhr()
Is the route access with XmlHttpRequest.
getCurrentTime($modifier= '')
Get the (cloned) time.
__construct(Config $config,\ElggSession $session, Crypto $crypto, HmacFactory $hmac)
Constructor.
validateTokenTimestamp($ts)
Is the token timestamp within acceptable range?
validateTokenOwnership($token, $timestamp, $session_token= '')
Was the given token generated for the session defined by session_token?
Thrown when CSRF tokens mismatch.
elgg()
Get the DI container.
validate(Request $request)
Validate CSRF tokens present in the request.
$ts
CSRF security token view for use with secure forms.
generateActionToken($timestamp, $session_token= '')
Generate a token from a session token (specifying the user), the timestamp, and the site key...
Provides a factory for HMAC objects.