Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Anonymous CSRF Token

514 sites Security covered
View on drupal.org

This module generates and validates CSRF tokens for anonymous users, providing an extra layer of security for forms and actions that don't require user authentication. By default, Drupal only provides CSRF protection for logged-in users, but this module extends that protection to anonymous visitors.

This module generates and validates CSRF tokens for anonymous users.

By default Drupal generates CSRF tokens only for authenticated users.

See also Anonymous forms vulnerable to CSRF not considered a vulnerability and #1803712: Allow form tokens to be used on anonymous forms in some cases.

7.x-1.x

1. Install and activate module
2. Check CSRF token for anonymous users

8.x-1.x

See CSRF Anonymous Token for the Drupal 8 variant of this module's 7.x-1.x branch.

2.x / 3.x

The 2.x release of this module is completely different in design, implementation, and purpose. Version 2.0+ of this module does not wire up anonymous CSRF protection automatically. Rather, you must explicitly wire up each route you wish to protect *.routing.yml and enable CSRF token protection for each route via specifying _anonymous_csrf_token: 'TRUE' in the route's declaration.

You will also need to call this module's AnonymousCsrfTokenGenerator service that wraps the CsrfTokenGenerator from Core in order to complete the implementation:

/** @var \Drupal\anonymous_token\Access\AnonymousCsrfTokenGenerator $csrf_token_service */
$csrf_token_service = \Drupal::service('anonymous_token.csrf_token');

// The path is an optional argument for generating and validating CSRF tokens.
$path = 'example-path';

// Generate a CSRF token.
$csrf_token = $csrf_token_service->get($path);

// Example manual CSRF token validation, if not via the route access checker.
if ($csrf_token_service->validate($csrf_token, $path) === FALSE) {
  throw new AccessDeniedHttpException('Invalid token');
}

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jan 2025
Latest release
11 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

Version Type Core Release date
3.0.0-beta3 Pre-release 9–11 Sep 24, 2025
3.0.0-beta2 Pre-release 9–11 Jan 22, 2025