Problem/Motivation
CsrfTokenGenerator::validate() has an optional parameter $skip_anonymous defaulting to FALSE. Setting it to TRUE will skip token validation for anonymous users.
Grepping through core turns up no single use of this parameter. This is not only the case in 8.x but also in 7.x, 6.x and 5.x. As far as I can see this parameter was last used in Drupal 4.7.
In fact the function drupal_valid_token was introduced as part of the Drupal 4.7.4 security release, see the commitdiff. The parameter was then used in poll.module<code>, <code>user.module and some other places. The same function was introduced into Drupal 5 in #90508: Introduce tokens by default in forms including the optional parameter, however it was never used since then.
Proposed resolution
Remove the parameter and remove the dependency of CsrfTokenGenerator from the current user service.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2245117-remove-optional-skip-anon-from-csrf-token-validate.diff | 4.59 KB | znerol |
Comments
Comment #1
znerol commentedComment #2
znerol commentedComment #3
znerol commentedComment #4
dawehnerI really like this research!
Comment #5
catchI found one usage in devel (the user switcher), but that's easy to workaround. Very nice find!
Comment #7
znerol commentedThis probably warrants a change record. Should this be mentioned in drupal_get_private_key() and drupal_get_token()/drupal_valid_token() got replaced by 'private_key' and 'csrf_token' service?
Comment #8
catchJust updating that to add a one-liner seems fine.
Comment #9
damiankloip commentedSorry, I've been away. Looks great!