Views reset button creates anonymous sessions

Created on 11 August 2025, 2 months ago

Problem/Motivation

When BEF is used within a view that includes a reset button within the exposed filters, BEF is creating anonymous sessions.

This was originally identified as an issue within core that was fixed in in 2025. https://www.drupal.org/project/drupal/issues/3471220 πŸ› Views exposed filter reset creates session for anonymous Active

The specific code that was updated/fixed in core, still exists within the BEF module.

Steps to reproduce

  1. Find a form that includes a reset button and open it in a different browser.
  2. Ping the database using drush sql:cli to get a count on anonymous sessions.
    SELECT count(*) FROM sessions WHERE uid = 0;
    You can use this to look closer at them.
    SELECT * FROM sessions WHERE uid = 0 ORDER BY timestamp DESC;
  3. Click the reset button.
  4. Run the 2 sql:cli commands again.
  5. Note the sessions count increases, and a new session is created in the database.

Proposed resolution

Within docroot/modules/contrib/better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php, make the same changes that were made within core.

Here is a snippet from the core issue:

The code in question is in \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::resetForm

  $session = $this->view->getRequest()->getSession();
    $views_session = $session->get('views', []);
    if (isset($views_session[$this->view->storage->id()][$display_id])) {
      unset($views_session[$this->view->storage->id()][$display_id]);
    }
    $session->set('views', $views_session);

The issue is the unqualified call to set the session

$session->set('views', $views_session);

This should be

if (!empty($views_session)) {
    $session->set('views', $views_session);
}
else {
    $session->remove('views');
}

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tregonia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024