Problem/Motivation

#2351015: URL generation does not bubble cache contexts is implementing CSRF tokens as placeholders for links, but a lot of the issues can be tried out for forms, which ensures that Form caching - except for crazy #default_value's is one step nearer and the link CSRF issue will get easier.

Proposed resolution

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#75 push_csrf_tokens_for-2463567-75.patch9.57 KBborisson_
#75 interdiff.txt1.16 KBborisson_
#72 push_csrf_tokens_for-2463567-72.patch9.61 KBborisson_
#69 push_csrf_tokens_for-2463567-69.patch10.11 KBborisson_
#65 push_csrf_tokens_for-2463567-65.patch10.11 KBborisson_
#65 interdiff.txt629 bytesborisson_
#62 push_csrf_tokens_for-2463567-62.patch10.5 KBborisson_
#62 interdiff.txt756 bytesborisson_
#59 push_csrf_tokens_for-2463567-59.patch9.79 KBborisson_
#59 interdiff.txt4.5 KBborisson_
#57 push_csrf_tokens_for-2463567-57.patch5.32 KBborisson_
#55 push_csrf_tokens_for-2463567-55.patch4.93 KBborisson_
#55 interdiff.txt712 bytesborisson_
#53 push_csrf_tokens_for-2463567-53.patch5.62 KBborisson_
#53 interdiff.txt693 bytesborisson_
#51 push_csrf_tokens_for-2463567-51.patch6.3 KBborisson_
#46 interdiff.txt5.04 KBborisson_
#46 push_csrf_tokens_for-2463567-46.patch9.23 KBborisson_
#44 drupal_2463567_44.patch14.28 KBxano
#44 interdiff.txt651 bytesxano
#42 push_csrf_tokens_for-2463567-42.patch13.86 KBborisson_
#42 interdiff.txt1.47 KBborisson_
#38 push_csrf_tokens_for-2463567-38.patch13.76 KBborisson_
#38 interdiff.txt2.7 KBborisson_
#36 push_csrf_tokens_for-2463567-36.patch14.8 KBborisson_
#36 interdiff.txt1.44 KBborisson_
#34 push_csrf_tokens_for-2463567-34.patch14.55 KBborisson_
#34 interdiff.txt1.19 KBborisson_
#32 push_csrf_tokens_for-2463567-32.patch14.31 KBborisson_
#32 interdiff.txt1.32 KBborisson_
#30 interdiff.txt787 bytesborisson_
#30 push_csrf_tokens_for-2463567-30.patch12.99 KBborisson_
#27 push_csrf_tokens_for-2463567-27.patch12.96 KBborisson_
#27 interdiff.txt5.35 KBborisson_
#24 push_csrf_tokens_for-2463567-24.patch9.01 KBborisson_
#24 interdiff.txt6.62 KBborisson_
#24 interdiff_comments.txt1.58 KBborisson_
#20 interdiff.txt742 bytesborisson_
#20 push_csrf_tokens_for-2463567-20.patch3.67 KBborisson_
#18 push_csrf_tokens_for-2463567-18.patch3.6 KBborisson_
#18 interdiff.txt1.01 KBborisson_
#14 push_csrf_tokens_for-2463567-14.patch3.61 KBborisson_
#14 interdiff.txt763 bytesborisson_
#12 push_csrf_tokens_for-2463567-12.patch3.57 KBborisson_
#12 interdiff.txt3.7 KBborisson_
#7 interdiff.txt1.09 KBborisson_
#7 push_csrf_tokens_for-2463567-7.patch3.53 KBborisson_
#5 interdiff.txt1.66 KBwim leers
#5 form_csrf_post_render_cache-2463567-5.patch2.65 KBwim leers
#3 form_csrf_post_render_cache-2463567-3.patch1.94 KBwim leers
#2 form_csrf_post_render_cache-2463567-2-do-not-test.patch2.09 KBwim leers

Comments

wim leers’s picture

Assigned: Unassigned » wim leers

Taking this on.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Active » Needs review
StatusFileSize
new2.09 KB

Super hacky super rough initial version.

This causes an error upon submitting a form: The form has become outdated. Copy any unsaved work in the form below and then reload this page.

We'll need to update the form building/tracking of the token in form state stuff too. But I've mostly forgotten about Form API's internals. (i.e. why it works the way it works…) Pointers are most welcome, so I don't need to spend hours re-learning FAPI.

wim leers’s picture

Issue tags: +Needs tests
StatusFileSize
new1.94 KB

Status: Needs review » Needs work

The last submitted patch, 3: form_csrf_post_render_cache-2463567-3.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new2.65 KB
new1.66 KB

The (majority of the) 199 failures are caused by the tricky way GET forms' input processing is handled by the form builder: their input is only processed in certain scenarios, and because Views happens to $form['form_token']['#access'] = FALSE, Views' exposed filters (GET) form happens to not be one of the scenarios where processing happens, causing these test failures.

This was @effulgentsia's clever work-around :)

Pair-programmed with @effulgentsia.

Status: Needs review » Needs work

The last submitted patch, 5: form_csrf_post_render_cache-2463567-5.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.53 KB
new1.09 KB

The remaining failures are caused because the "form_token" is in a different format than expected: <input value="{value}" type="hidden" name="form_token" /> instead of <input type="hidden" name="form_token" value="{value}">

The attached patch fixes the test for QuickEditAutocompleteTermTest so it uses the actual format of the input. I'm pretty sure this is a bad way of fixing this.

There are 2 options:
- Make the regex more flexibile, so it doesn't matter in what order the attributes of the input are.
- Fix the actual input to have the expected order of attributes.

What is the preferred way forward?

Status: Needs review » Needs work

The last submitted patch, 7: push_csrf_tokens_for-2463567-7.patch, failed testing.

wim leers’s picture

Title: Push CSRF tokens for forms to #post_render_cache » [PP-1] Push CSRF tokens for forms to placeholders + #lazy_builder
Related issues: +#2512132: Make CSRF links cacheable

Now doing exactly this for links: #2512132: Make CSRF links cacheable. Postponing this on that.

wim leers’s picture

Status: Needs work » Postponed
wim leers’s picture

Title: [PP-1] Push CSRF tokens for forms to placeholders + #lazy_builder » Push CSRF tokens for forms to placeholders + #lazy_builder
Status: Postponed » Needs work

#2512132: Make CSRF links cacheable landed. We can apply the same solution.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.7 KB
new3.57 KB

The implementation in the patch in #7 was using #post_render and that didn't work anymore.

I've changed this to use a #lazy_builder callback, this is till WIP and doesn't work yet.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -657,15 +675,22 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +        $placeholder = hash('sha1', $form['#token']);
    

    Just use cre32, this is what we use in other places ...

  2. +++ b/core/lib/Drupal/Core/Render/Element/Token.php
    @@ -29,12 +29,18 @@ public function getInfo() {
    +  public static function something($element) {
    

    Do we have a better name for this?

borisson_’s picture

StatusFileSize
new763 bytes
new3.61 KB

#13

  1. In #2512132: Make CSRF links cacheable and #2504139: Blocks containing a form include the form action in the cache, so they always submit to the first URL the form was viewed at we're also using hash('sha1', ...), so for consistency I also went for that here, I can change this if you want.
  2. You're right, this should be more descriptive. I went for preRenderSetPlaceholderAsValue

Attached patch doesn't functionally change anything compared to #12, there's only the method rename.

The last submitted patch, 12: push_csrf_tokens_for-2463567-12.patch, failed testing.

wim leers’s picture

#14.1: Yes, let's change that to crc32(). I discussed that with dawehner; crc32() is sufficient here; we should also update all other cases (i.e. the issue you linked to and \Drupal\Core\Render\Renderer::createPlaceholder() — if you open an issue for the latter, I'll RTBC it :)).

@borisson_: Thanks for taking this one on! When I saw it fly by just now, I immediately though of you, since it's related to that other issue. But clearly you're alredy working on it :P

Status: Needs review » Needs work

The last submitted patch, 14: push_csrf_tokens_for-2463567-14.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB
new3.6 KB

This should a bunch of the current failures.

Status: Needs review » Needs work

The last submitted patch, 18: push_csrf_tokens_for-2463567-18.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.67 KB
new742 bytes

I removed too much code in the previous patch.

wim leers’s picture

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,24 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +   * #post_render_cache callback; render form csrf token.
    

    s/#post_render_cache/#lazy_builder/
    s/render/renders/
    s/csrf/CSRF/

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,24 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +      '#cache' => [
    +        'contexts' => [
    +          'session',
    +        ],
    +        'max-age' => 0
    +      ],
    

    Just the session cache context should be sufficient.

  3. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +674,23 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +        $placeholder = crc32($form_id);
    +        $form['#token'] = $placeholder;
    ...
    +        $form['#attached']['placeholders'][$placeholder] = [
    +          '#lazy_builder' => ['form_builder:renderFormTokenPlaceholder', [$placeholder]]
    

    This could use some comments, much like those in #2504139: Blocks containing a form include the form action in the cache, so they always submit to the first URL the form was viewed at.

Status: Needs review » Needs work

The last submitted patch, 20: push_csrf_tokens_for-2463567-20.patch, failed testing.

wim leers’s picture

The test failures are simple: just missing the session cache context :)

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB
new6.62 KB
new9.01 KB

This patch contains fixes for #21 (interdiff_comments.txt) and fixes for the tests.

fabianx’s picture

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,23 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +      '#markup' => \Drupal::csrfToken()->get($path),
    

    $this->csrfToken->get($path);

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +673,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +        // Generates a placeholder based on the form id.
    +        $placeholder = crc32($form_id);
    

    $placeholder = 'form_token_placeholder_' . crc32($form_id);

    e.g. we need to 'namespace' our placeholders somewhat.

  3. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +673,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +          '#default_value' => $this->csrfToken->get($placeholder),
    

    Are we sure we want to get() that value, I guess it does not matter as its invalid anyway, but just asking.

    Might need a little comment.

  4. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +673,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +          '#placeholder' => $placeholder,
    

    Does this clash with HTML5 placeholder?

Here are the comments.

I can't yet see how this can work in form validation, but I guess I will see once this is green :).

Great work!

Status: Needs review » Needs work

The last submitted patch, 24: push_csrf_tokens_for-2463567-24.patch, failed testing.

borisson_’s picture

StatusFileSize
new5.35 KB
new12.96 KB

#25

  1. fixed
  2. fixed
  3. I don't think it's needed, let's see what the bot says
  4. I don't think so, this is a hidden field. In \Drupal\Core\Render\Element\Token::preRenderSetPlaceholderAsValue this placeholder gets copied to the value.

This also fixes the failures in QuickEditLoadingTest

borisson_’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: push_csrf_tokens_for-2463567-27.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new12.99 KB
new787 bytes

Status: Needs review » Needs work

The last submitted patch, 30: push_csrf_tokens_for-2463567-30.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB
new14.31 KB

This makes sure that a session is set so the test can use it, this fixes the last test failure in CommentDefaultFormatterCacheTagsTest

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,23 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +   * @param string $path
    +   * @return array
    

    Incomplete docblock.

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +673,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +        // Generates a placeholder based on the form id.
    

    Nit: s/id/ID/

  3. +++ b/core/lib/Drupal/Core/Render/Element/Token.php
    @@ -29,12 +29,18 @@ public function getInfo() {
    +  public static function preRenderSetPlaceholderAsValue($element) {
    

    Needs docblock.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.19 KB
new14.55 KB

#33

  1. Not sure what docblock you mean.
  2. Fixed.
  3. added a docblock.
wim leers’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

1. The one I quoted! Note how it just lists the params without documentation.


+++ b/core/lib/Drupal/Core/Render/Element/Token.php
@@ -36,6 +36,12 @@ public function getInfo() {
+  /**
+   * Sets the Token's #placeholder as the #value.
+   *
+   * @param $element
+   * @return mixed
+   */

This one is also incomplete for the same reason.

(Yes, I know, our docs standards are quite silly for cases like these.)


We still have the "needs tests" issue tag. Do we really need tests for this though? We have a gazillion implicit tests anyway, right? So I think we're fine in that regard.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB
new14.8 KB

Updated the docblocks of both methods.

---
I agree, I think we have sufficient implicit tests for this.

wim leers’s picture

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,25 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +   * @param string $path a string containing the path we need to get the
    +   *  CSRF token for from the CsrfTokenGenerator.
    +   * @return array
    +   *   A renderable array containing the CSRF token.
    
    +++ b/core/lib/Drupal/Core/Render/Element/Token.php
    @@ -36,6 +37,19 @@ public function getInfo() {
    +   * @param array $element A form element that needs to have it's #value
    +   *  updated.
    +   * @return array
    +   *   The updated form element.
    

    These docblocks are wrong.

    We always have a blank line between the last @param and @return.

    And we never put the documentation for a parameter on the same line, always on a new line.

    See the many thousands of examples in the rest of core :)

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -603,6 +603,25 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +  public function renderFormTokenPlaceholder($path) {
    ...
    +      '#markup' => $this->csrfToken->get($path),
    

    Hrm, the $path parameter does not actually make sense.

  3. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +675,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +          '#default_value' => $this->csrfToken->get($placeholder),
    

    Hrm, we're still using the CSRF token generator here. That seems wrong. (I know it is a remnant from my early patch in #5, but that doesn't make it right :))

    @Fabianx already asked for its removal in #25.3, you already did that in #27, but because it caused test failures, you restored it in #30.

    But that just means we need to figure out why #27 failed so badly.

    This is IMHO the biggest blocker.

  4. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -656,16 +675,28 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +          '#placeholder' => $placeholder,
    
    +++ b/core/lib/Drupal/Core/Render/Element/Token.php
    @@ -29,6 +29,7 @@ public function getInfo() {
    +        [$class, 'preRenderSetPlaceholderAsValue'],
    
    @@ -36,6 +37,19 @@ public function getInfo() {
    +  public static function preRenderSetPlaceholderAsValue(array $element) {
    +    $element['#attributes']['value'] = $element['#placeholder'];
    +    return $element;
    +  }
    

    This is the clever work-around invented by @effulgentsia, as I wrote in #5. We need to document why and how this works, because I sure don't understand it (anymore).

borisson_’s picture

StatusFileSize
new2.7 KB
new13.76 KB

#37

  1. Remaining docblock should be standard-proof now. :-)
  2. It didn't make sense that this was called $path, renamed it, see .3
  3. I now better understand the code so this is simplified a little bit.

    This needed to be the CSRF token because previously, this ran after the #lazy_builder and otherwise the CsrfTokenGenerator::validate call returned false.
    It is now removed, as well as the '#placeholder', so the confusion in #25.4 doesn't happen anymore.

  4. Removed.

Locally, all forms still work and can be submitted, I'd like to see what happens with the test-suite.

Status: Needs review » Needs work

The last submitted patch, 38: push_csrf_tokens_for-2463567-38.patch, failed testing.

borisson_’s picture

So, the current failures are all entity listings that fail, and as far as I can see, they are failing because of the filters that are on these listings.

If I debug $token and $this->computeToken($seed, $value) in \Drupal\Core\Access\CsrfTokenGenerator::validate then it shows that they aren't the same.

Example:

string 'token: form_token_placeholder_4107625689' (length=40)
string 'computed token: CI2j2pPZ_YeGSTxEHTlenlkdTFM19qXlvyAnc6zn-CM' (length=59)

So, the #lazy_builder hasn't ran yet for the filter form. This is what needs to be solved for the failures to be resolved.

xano’s picture

@borisson_ and I went through the code this morning and we discovered a few interesting things:
ExposedFormPluginBase::renderExposedForm() and DisplayPluginBase::elementPreRender() build complete forms using the form builder, while their return values should be embeddable forms.This means there are multiple form token elements in the final form, all of which say their value is stored in FormStateInterface::getValue('form_token'). As form tokens are based on form IDs, all elements have different token values, and as such only one of them can possibly match the token in the form state, causing the other elements to fail validation.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB
new13.86 KB

Attached a reroll, also changed the placeholder to be attached to the form_token element, not the parent form build array.

Status: Needs review » Needs work

The last submitted patch, 42: push_csrf_tokens_for-2463567-42.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new651 bytes
new14.28 KB

The reason for the test failures is that GET forms unnecessarily received form token elements, but GET forms are validated before rendering/submission, so the CSRF token was never set, because lazy builders are part of the rendering process.

Because GET forms are immutable, which means they don't need CSRF protection, we can safely prevent CSRF token elements from being added to such forms.

Status: Needs review » Needs work

The last submitted patch, 44: drupal_2463567_44.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new9.23 KB
new5.04 KB

I had introduced the changes to QuickEditLoadingTest and QuickEditAutocompleteTermTest earlier in this patch, reverted these back to the state of HEAD and they pass again.

borisson_’s picture

Issue tags: +Needs security review

The current approach removes CSRF tokens for get forms completely. Is this a security concern?

If it is, we might be able to also fix the the failures of #42 by reverting the changes in #44 and setting #token to false for exposed filter forms.

wim leers’s picture

I pinged @effulgentsia for review.

Status: Needs review » Needs work

The last submitted patch, 46: push_csrf_tokens_for-2463567-46.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.3 KB

Patch no longer applied, this one does, let's see what kind of failures we're getting now.

Status: Needs review » Needs work

The last submitted patch, 51: push_csrf_tokens_for-2463567-51.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new693 bytes
new5.62 KB

Status: Needs review » Needs work

The last submitted patch, 53: push_csrf_tokens_for-2463567-53.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new712 bytes
new4.93 KB

Status: Needs review » Needs work

The last submitted patch, 55: push_csrf_tokens_for-2463567-55.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new5.32 KB

Status: Needs review » Needs work

The last submitted patch, 57: push_csrf_tokens_for-2463567-57.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new4.5 KB
new9.79 KB

FormBuilderTest will still fail, looking into fixing that.

Status: Needs review » Needs work

The last submitted patch, 59: push_csrf_tokens_for-2463567-59.patch, failed testing.

borisson_’s picture

I looked into fixing the remaining failure in FormBuilderTest, but I can't figure it out yet, I'll have another look tomorrow.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new756 bytes
new10.5 KB

Rerolled the patch and fixes the FormBuilderTest.

wim leers’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -677,6 +698,7 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
+      $form['#token'] = FALSE;

I think we should split this off into a separate issue, and block this issue on that new issue.

That's an API change in line with #2502785: Remove support for $form_state->setCached() for GET requests and fully sensible, but this issue really is only about improving how CSRF tokens are rendered. This change is something else entirely.

Also, if we do this, then we should also remove all manual calls that set $form['#token'] = FALSE in GET forms. E.g. \Drupal\search\Form\SearchBlockForm::buildForm() does this.

borisson_’s picture

Status: Needs work » Postponed
borisson_’s picture

StatusFileSize
new629 bytes
new10.11 KB

Attached patch removes the code quoted in #63.

This will not work before #2571995: GET forms shouldn't have CSRF tokens by default is in.

borisson_’s picture

Related issues: +#2571995: GET forms shouldn't have CSRF tokens by default
borisson_’s picture

Issue tags: -Needs security review

Moving 'needs security review' tag to #2571995: GET forms shouldn't have CSRF tokens by default.

borisson_’s picture

Status: Postponed » Needs work
borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new10.11 KB

Attached patch is the same as in #65.

Status: Needs review » Needs work

The last submitted patch, 69: push_csrf_tokens_for-2463567-69.patch, failed testing.

The last submitted patch, 69: push_csrf_tokens_for-2463567-69.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new9.61 KB

Rebased.

wim leers’s picture

Component: cache system » forms system
Status: Needs review » Reviewed & tested by the community
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -725,15 +746,29 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
           '#cache' => [
             'max-age' => 0,
           ],

This patch presents a big step forward; it opens the door towards cacheable forms. But let's keep marking forms uncacheable for now, because that requires a broader discussion.

So:

  1. Let's get this in; this does not affect security in any way.
  2. Let's file a follow-up issue where we try get rid of this max-age=0, but doing so requires further discussion.
effulgentsia’s picture

Status: Reviewed & tested by the community » Needs work

Patch looks great, but a couple of nits:

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -652,6 +652,27 @@ public function renderPlaceholderFormAction() {
    +   * @param string $placeholder
    +   *  A string containing a placeholder. This could've been a different value,
    +   *  as long as it matches the value of the form's #token.
    

    I don't understand this comment. "could've been different" from what?

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -725,15 +746,29 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
    +        $placeholder = 'form_token_placeholder_' . crc32($form_id);
    

    Elsewhere we use hash('crc32b') instead of crc32(), possibly due to the portability warning in http://php.net/manual/en/function.crc32.php. Let's switch to that here as well.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.16 KB
new9.57 KB

Fixes both comments of #74.

Status: Needs review » Needs work

The last submitted patch, 75: push_csrf_tokens_for-2463567-75.patch, failed testing.

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

PIFR was having MySQL troubles it seems. Re-testing. DrupalCI came back green already though. Back to RTBC.

  • effulgentsia committed 804d879 on 8.0.x
    Issue #2463567 by borisson_, Wim Leers, Xano: Push CSRF tokens for forms...
effulgentsia’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Pushed to 8.0.x.

Status: Fixed » Closed (fixed)

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