Currently, if a form token fails to validate, the user is shown a warning message, but there is nothing in the watchdog to help a site admin track down the problem or even know it's occurring. The attached patches log a message to the with a link to the path causing the error.
Comments
Comment #1
deviantintegral commentedMy patches look to have vanished, lets try this again.
Comment #2
dries commentedI don't think %user is necessary as the watchdog automatically captures the username. Just not in the description.
Comment #3
deviantintegral commentedHere's an update changing the text to just
'Form token %sent_token was sent, %expected_token was expected.'.Comment #4
alexjarvis commentedLooks good.
Comment #5
deviantintegral commented#3: 740986_form_token_error_watchdog_7.x_3.patch queued for re-testing.
Comment #6
marcingy commented#3: 740986_form_token_error_watchdog_7.x_3.patch queued for re-testing.
Comment #7
aspilicious commented#3: 740986_form_token_error_watchdog_7.x_3.patch queued for re-testing.
Comment #8
dries commentedI think the watchdog message should be clarified so that non-developers can make sense of it.
Comment #9
deviantintegral commentedAnyone know of a handbook entry that has information about debugging token issues? I think if we want to make it clearer we don't want to have a several sentence error message.
Comment #10
deviantintegral commentedHow's this?
Form token validation failed during form submission. %sent_token was sent, %expected_token was expected. The form submission has been ignored. This could be caused by a malicious user or a misconfigured proxy. For information on debugging this issue, see the <a href="http://drupal.org/support">support page</a> on drupal.org.Comment #11
deviantintegral commentedThis needs to happen in 8.x first.
Comment #12
xjmzendoodles and I spoke about this on IRC. I think #10 is a bit too long for watchdog, and the link to the d.o support page probably isn't a good idea. However, the first part is much improved.
I would suggest only:
because malicious users and misconfigured proxies aren't the only reasons it might fail.
Comment #13
ZenDoodles commentedUpdated patch for Drupal 8 and used new text.
Comment #14
xjmThis looks good to me. However, there's one thing I didn't notice before, that we should potentially change... should we use
request_path()in place of$_GET['q']?Also, note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.
Comment #15
xjmOops, forgot to set status again.
Comment #16
xjmHi @ZenDoodles,
Thanks for taking this on. Are you still working on this issue? If not, we'll unassign it in a day or two so that someone else can give it a try. (Feel free to assign it back to yourself if you'd still like to work on it, as well.) Thanks!
Comment #17
noisetteprod commentedUpdated path with the new core directory and switch $_GET['q'] with request_path()
Comment #18
xjmThanks @noisetteprod! The reroll looks great.
Should we add an automated test asserting that the message gets logged?
Comment #19
deviantintegral commentedHere's an updated patch that tests for both the watchdog() call as well as the form error itself.
Comment #20
deviantintegral commentedOops, missed updating the namespace when I copied from FormTest.
Comment #21
socketwench commentedNovice issue cleanup.
Comment #23
jhedstromSadly this needs yet another reroll.
Comment #24
heykarthikwithuComment #25
drupradunassigned due to no update since long time
Comment #26
mohit_aghera commentedInitial attempt to re-roll patch for 8.2.x branch.
Comment #27
jhedstromCoding standards have removed
@filedocblocks from class/interface/trait files.This information is now conveyed using
@groupin the class docblock, and the method is no longer called.It's odd that this test is passing since the patch contains none of the functional changes from the previous patch in #20.
Comment #28
mohit_aghera commented@jhedstrom
updated doc block comments and few issues from other test cases related to form.
Comment #29
mohit_aghera commentedComment #43
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
I feel this is probably still relevant in D10 (could be wrong).
Looking at the patches though and starting at #26 appears the fix is just including the test and not the fix (was the fix not needed anymore). And if the fix was not needed are the tests still needed?
Think with the confusion this could use an IS update.