Problem/Motivation

Some forms are repeated over and over across a site, each one with a slightly different form-id. A good example is the commerce add-to-cart form. By default Drupal generates a unique CSRF form token for each instance (i.e. for each product display). In order to receive form tokens on cached pages for authenticated users, one request is generated for each of them by default.

Proposed resolution

The form API allows the customization of the CSRF token value. It is possible to alter that value form within a hook_form_alter. A good candidate as the form token value is the form_base_id.

Remaining tasks

User interface changes

API changes

Comments

znerol’s picture

Status: Active » Needs review
StatusFileSize
new1.22 KB
znerol’s picture

StatusFileSize
new2.05 KB
new2.89 KB

Note we need to do that on both cacheable as well as uncacheable versions of the page. Otherwise form-processing will not work as soon as the form is submitted.

znerol’s picture

StatusFileSize
new4.93 KB
new4.48 KB

Implemented an admin interface. No need to provide the possibility to restrict this feature to a selected set of roles, therefore removed that. The names of possibly affected modules are shown in the fieldset description, that should make it easier for people to assess the impact.

The feature now kicks in for all authcache-enabled users if the base form id matches a whitelist (defaults to "*").

znerol’s picture

StatusFileSize
new6 KB
new10.47 KB

Adding tests.

  • znerol committed 34f6f5a on
    Issue #2352239 by znerol: Use base form id for deriving form tokens
    
znerol’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.