You are here

public function CsrfAccessCheck::access in Zircon Profile 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/Access/CsrfAccessCheck.php \Drupal\Core\Access\CsrfAccessCheck::access()
  2. 8 core/modules/rest/src/Access/CSRFAccessCheck.php \Drupal\rest\Access\CSRFAccessCheck::access()
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Access/CsrfAccessCheck.php \Drupal\Core\Access\CsrfAccessCheck::access()

Checks access based on a CSRF token for the request.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/lib/Drupal/Core/Access/CsrfAccessCheck.php, line 54
Contains \Drupal\Core\Access\CsrfAccessCheck.

Class

CsrfAccessCheck
Allows access to routes to be controlled by a '_csrf_token' parameter.

Namespace

Drupal\Core\Access

Code

public function access(Route $route, Request $request, RouteMatchInterface $route_match) {
  $parameters = $route_match
    ->getRawParameters();
  $path = ltrim($route
    ->getPath(), '/');

  // Replace the path parameters with values from the parameters array.
  foreach ($parameters as $param => $value) {
    $path = str_replace("{{$param}}", $value, $path);
  }
  if ($this->csrfToken
    ->validate($request->query
    ->get('token'), $path)) {
    $result = AccessResult::allowed();
  }
  else {
    $result = AccessResult::forbidden();
  }

  // Not cacheable because the CSRF token is highly dynamic.
  return $result
    ->setCacheMaxAge(0);
}