Created on 20 October 2022, almost 2 years ago
Updated 15 July 2024, about 2 months ago

Problem/Motivation

The module is being useful to me but I found the following problem in the registry

Path: /jsnlog/log?token=2c-0DMghP4f2xD7dcVN6bltHYxXbDOlX-iCwRsNxRs8. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: 'csrf_token' URL query argument is invalid. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 121 of /var/www/example.com/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I have confirmed the bug still exists.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    This could be caused by anonymous users. csrf tokens are only generated for authenticated users.

    I think a route subscriber is needed to remove _csrf_token from the route requirements if logging is enabled for anonymous users.

  • #3 and how could I do that or in the medol some extra configuration must be done

  • This patch removes _csrf_token from the route requirements for anonymous AND authenticated users and also removes the token from the JSNLog library URL.

    diff --git a/jsnlog.module b/jsnlog.module
    index dfe8438..30756c3 100644
    --- a/jsnlog.module
    +++ b/jsnlog.module
    @@ -58,8 +58,7 @@ function jsnlog_page_attachments(array &$page) {
     
       if ($jsnlog_access->visibilityPages() && $jsnlog_access->visibilityRoles($account)) {
         $url = Url::fromRoute('jsnlog.ajax_log');
    -    $token = \Drupal::csrfToken()->get($url->getInternalPath());
    -    $url->setOptions(['absolute' => TRUE, 'query' => ['token' => $token]]);
    +    $url->setOptions(['absolute' => TRUE]);
     
         $page['#attached']['library'][] = 'jsnlog/jsnlog';
         $page['#attached']['drupalSettings']['jsnlog'] = [
    diff --git a/jsnlog.routing.yml b/jsnlog.routing.yml
    index 6e99268..2d77910 100644
    --- a/jsnlog.routing.yml
    +++ b/jsnlog.routing.yml
    @@ -14,4 +14,3 @@ jsnlog.ajax_log:
       requirements:
         _permission: 'access content'
         _jsnlog_ajax_log_access: 'TRUE'
    -    _csrf_token: 'TRUE'
    
  • Merge request !13Resolve #3316692 "Error token" β†’ (Merged) created by bluegeek9
  • Pipeline finished with Skipped
    2 months ago
    #213157
  • Issue was unassigned.
  • Status changed to Fixed 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024