Webforms with a source entity get cached wrongly

Created on 28 May 2025, 15 days ago

Problem/Motivation

A webform with a source entity (i. e. using the webform_group module) gets cached for anonymous users with max age -1 not respecting the source entity. If it is defined via query string parameters for the entity.webform.canonical route using Drupal\webform\Plugin\WebformSourceEntity\QueryStringWebformSourceEntity, the first user calling /form/[webform_name]?source_entity_type=[entity_type]&source_entity_id=[entity_id] with entity id 4 (label: "Group A") after rebuilding caches sees "Group A", the next user calling the same url but with entity id 19 (label: "Group X") should see "Group X" but sees "Group A".

Steps to reproduce

  1. Create a webform depending on a source entity. There are multiple options like webform_node or webform_group.
  2. Add a webform field to the respective entity type and set the field display format to "Url".
  3. Create two entities with different titles, referencing the same webform.
  4. As anonymous user click on the webform link of the first entity, this should redirect you to a url of the form /form/[webform_name]?source_entity_type=[entity_type]&source_entity_id=[entity_id] and check the title.
  5. In a different browser session, as anonymous user click on the webform link of the second entity and compare the title with the one from the previous step. They should differ, but are the same.

Proposed resolution

There are two options:

  1. Disable caching for the whole webform page (entity.webform.canonical and eventually other affected routes like webform preview) when the request includes query string parameters defined by Drupal\webform\Plugin\WebformSourceEntity\QueryStringWebformSourceEntity. Maybe this should be made controllable via an option per webform.
  2. When the request includes query string parameters defined by Drupal\webform\Plugin\WebformSourceEntity\QueryStringWebformSourceEntity, add corresponding cache tags for the source entity, to cache requests depending on them. I'm not sure though, if this works correctly with query string parameters for browsers and proxies.
🐛 Bug report
Status

Active

Version

6.2

Component

Code

Created by

🇦🇹Austria mvonfrie

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

Comments & Activities

Production build 0.71.5 2024