Problem/Motivation

Forms are an important part of Drupal, but most have them have CSRF tokens, which make them uncacheable, but they're not marked as such.

Proposed resolution

Mark forms' CSRF token inputs as uncacheable.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new682 bytes
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Its correct.

wim leers’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.94 KB
new2.3 KB

And test coverage. The test-only patch is also the interdiff.

wim leers’s picture

In other words: the patch verifies that max-age = 0 is only set if a form token is indeed present, and *if* a form token is present, that it's always max-age=0.

effulgentsia’s picture

Since the form token is added conditionally on $user->isAuthenticated(), should we also add the 'user.roles:authenticated' context to $form?

The last submitted patch, 4: 2559011-4-test-only-FAIL.patch, failed testing.

wim leers’s picture

StatusFileSize
new2.92 KB
wim leers’s picture

StatusFileSize
new4.84 KB
new4.46 KB

#6: indeed. That was unnecessary in #2526472: Ensure forms are marked max-age=0, but have a way to opt-in to being cacheable, and I failed to analyze the logic used for generating form tokens sufficiently, or I'd have caught that fact.

Status: Needs review » Needs work

The last submitted patch, 9: 2559011-9.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new6.19 KB
new1.44 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2559011-11.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new7.12 KB
new2.62 KB

Green.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Looks great. Thanks.

fabianx’s picture

RTBC + 1

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 30fceb5 on 8.0.x
    Issue #2559011 by Wim Leers: Ensure form tokens are marked max-age=0
    
wim leers’s picture

Hurray!

This was the last blocker for #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!). It was split off from #2526472: Ensure forms are marked max-age=0, but have a way to opt-in to being cacheable, and uses a more granular, more precise approach to ensure SmartCache doesn't cache forms that should not be cached.

So, I tested #2429617-339: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!) + #13 (the patch here that just got committed), to see if SmartCache would still be green. But, unfortunately, the answer is no: #2560959-4: Testing issue for #2429617 is red.

Because of the more granular (and better!) approach taken by this issue compared to #2526472, we need one more step: #2561775: Forms without $form['#action'] set get their action automatically generated based on current path + query args: cacheability metadata is missing. Then forms will have sufficient cacheability metadata. Hopefully see you there!

Status: Fixed » Closed (fixed)

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