ALL form values in user data

pwolanin - August 21, 2006 - 13:57
Project:Drupal
Version:4.7.x-dev
Component:user.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

There is a bug in 4.7 and HEAD since ALL form values (e.g. "submit") get saved in the data field of the user table. For example:

a:4:{s:11:"destination";s:22:"admin/user/user/create";s:6:"notify";i:0;s:6:"submit";s:18:"Create new account";s:7:"form_id";s:13:"user_register";}

I think the problem occurs in function user_register_submit on this line:

  $account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'roles' => $roles, 'status' => ($admin || variable_get('user_register', 1) == 1))));

#1

killes@www.drop.org - August 21, 2006 - 14:01

can confirm this, the analysis looks ok too.

#2

pwolanin - August 21, 2006 - 15:11

Patch attch which tries to unset all those vales as per function user_edit_submit.

also, leaving out 'destination' on this assumption that this patch: http://drupal.org/node/79809
will be applied.

I think patch should apply to 4.7 also (after changing path to module)

AttachmentSizeStatusTest resultOperations
clean_user_data_2.diff917 bytesIgnoredNoneNone

#3

pwolanin - August 21, 2006 - 15:12
Status:active» needs review

setting status- patch works for me.

#4

drumm - August 23, 2006 - 07:42
Status:needs review» needs work

I managed to get a 'destination' in my user data somehow while creating an account from the admin page.

#5

pwolanin - August 23, 2006 - 12:21
Status:needs work» needs review

The patch here: http://drupal.org/node/79809

removes the (usused) 'destination' field. However, I'd be happy to add it to this patch instead

#6

pwolanin - August 24, 2006 - 01:59

This patch also cuts out the 'destination' field from the form definition. As far as I can tell, this isn't actually used- the array key would need to be '#redirect' to have an effect, right?

AttachmentSizeStatusTest resultOperations
clean_user_data_6.diff1.27 KBIgnoredNoneNone

#7

drumm - August 24, 2006 - 08:52
Status:needs review» needs work

Don't try sneaking other behaviors into this patch.

#8

pwolanin - August 24, 2006 - 11:29

Well, I didn't think I was sneaking!

Does that 'description' code have any actual effect? I can see any from following the code or testing. If not, then I think removing it is just as valid a solution as unsetting the array element.

#9

pwolanin - September 20, 2006 - 01:57

@drumm - again, I don't think that code has has any effect, so why not just remove it?

#10

pwolanin - September 24, 2006 - 21:12
Status:needs work» needs review

in regards in the 'destination' form value, after playing more, I see that it does have an effect. So, the attached patch adds that and the addition form values 'op' to the list of things to unset.

Below the effect of this is demonstrated. Users 1 & 2 were created before the patch. User 4 was created by the admin after the patch, user 5 was self-registered after the patch.

mysql> select uid, data from users where uid > 0;
+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| uid | data                                                           |
+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   1 | a:3:{s:2:"op";s:6:"Submit";s:6:"submit";s:18:"Create new account";s:7:"form_id";s:13:"user_register";}                                                           |
|   2 | a:5:{s:11:"destination";s:5:"admin";s:6:"notify";i:0;s:2:"op";s:18:"Create new account";s:6:"submit";s:18:"Create new account";s:7:"form_id";s:13:"user_register";} |
|   4 | a:0:{}                                                           |
|   5 | a:0:{}                                                           |
+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+

AttachmentSizeStatusTest resultOperations
clean_user_data_10.diff.txt1023 bytesIgnoredNoneNone

#11

pwolanin - September 24, 2006 - 23:54

same code, just moved it down closer to the user_save call.

AttachmentSizeStatusTest resultOperations
clean_user_data_11.diff.txt1.11 KBIgnoredNoneNone

#12

pwolanin - September 24, 2006 - 23:57

a very similar patch for the 4.7 branch

AttachmentSizeStatusTest resultOperations
clean_user_data47_12.diff.txt1.09 KBIgnoredNoneNone

#13

pwolanin - November 13, 2006 - 03:19
Version:x.y.z» 5.x-dev
Status:needs review» reviewed & tested by the community

attached patch is updated for current HEAD, and now also takes care of the new 'form_token' in the form. This is really a trivial patch and the basic problem/solution confirmed by killes in #1, so setting RTBC.

AttachmentSizeStatusTest resultOperations
clean_user_data50_13.diff.txt1.14 KBIgnoredNoneNone

#14

drumm - November 14, 2006 - 06:39
Status:reviewed & tested by the community» needs work

The existing place this is done is in the user_edit_submit() function. These two places need to have similar lists (such as add form_token to user_edit_submit()).

#15

pwolanin - November 14, 2006 - 13:57

Can I propose a more robust solution- what not make a $form['data']['#tree'] = TRUE; element, and only save into the data field those form elements specifically entered under there?

Are there even any modules that use this feature of saving values to the data field?

#16

pwolanin - November 15, 2006 - 00:17
Status:needs work» needs review

new patch attached that addresses both user_register and user_edit for 5.x via the simple unset(). However, this is still not robust, since modules like Organic groups that add items to the registration forms still can easily cause this to happen.

AttachmentSizeStatusTest resultOperations
clean_user_data50_16.txt1.8 KBIgnoredNoneNone

#17

drumm - November 16, 2006 - 09:02
Status:needs review» fixed

Of course its not robust; the whole $user->data serialized soup is a bad and unnormalized concept.

Committed to HEAD.

#18

pwolanin - November 16, 2006 - 13:09
Version:5.x-dev» 4.7.x-dev
Status:fixed» reviewed & tested by the community

setting to 4.7 for backporting

#19

pwolanin - November 28, 2006 - 16:47
Status:reviewed & tested by the community» patch (to be ported)

#20

killes@www.drop.org - December 5, 2006 - 13:20
Status:patch (to be ported)» fixed

applied

#21

pwolanin - December 6, 2006 - 03:02

@killes - I hope this means you backported the 5.x patch, since I'm not sure the 4.7.x one from #12 included everthing (especially 'form_token').

#22

Anonymous - December 20, 2006 - 03:16
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.