Only requirement to do this bug: have pictures for users activated.

Well when a user edits their profile, it should call hook_user where the first parameter is 'validate'. But it does not. So take like changing the name. When you register it checks if the name is valid. But when you edit your name and save with something invalid like double spaces, it does not validate.
Note: I only used edit name as an example, I was working on a module when this happened.

So I search through the code. It was this line in user.module:

    $form['#validate'][] = 'user_validate_picture';

What happens is that it overwrites the default validate function, user_profile_form_validate. Without calling user_profile_form_validate, then the hook_user would be called with 'validate'

Right now I only added in user.pages.inc:

  $form['#validate'][] = 'user_profile_form_validate';

After:

  $form['#attributes']['enctype'] = 'multipart/form-data';
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

v1nce’s picture

Version: 6.1 » 6.8
Priority: Normal » Critical
FileSize
807 bytes

I ran into this issue while updating Imagecache Profiles to the 6.x branch. It seems the default validate hook is not getting called for the user_profile_form. The user module is adding in a custom validation callback when profile pictures are enabled:

$form['#validate'][] = 'user_validate_picture';

By default, d5 forms would call a function if defined like $form_id_validate(), but user_profile_form_validate() is not getting executed. The only #validate element defined in the $form when pictures are enabled is 'user_validate_picture'. This means the default fields are not being validated and any additional fields that use the validate $op of hook_user() are also not getting run.

Looking at how a form is prepared in drupal_prepare_form() we see:

  if (!isset($form['#validate'])) {
    if (function_exists($form_id .'_validate')) {
      $form['#validate'] = array($form_id .'_validate');
    }
  }

So, since user.module is defining a #validate function to use in user_edit_form() when profile pictures are enabled, the default #validate function is not set. This is a critical security issue.

Dave Reid’s picture

Version: 6.8 » 6.9
Status: Active » Fixed
pwolanin’s picture

Title: Missing validation for hook_user » SA-CORE-2009-001: Missing validation for hook_user
Version: 6.9 » 7.x-dev
Status: Fixed » Needs review
FileSize
807 bytes

This issue was fixed in the last core release and needs to be ported to HEAD. Hopefully the 6x patch applies.

Also, we should discuss for HEAD (and 6.x) as a separate issue whether the FAPI behavior of omitting the default validation function is correct/desirable.

Dave Reid’s picture

We should probably just fix the FAPI behavior instead of a temporary fix.

pwolanin’s picture

Well, I'd agree, but others may not. In any case, the 1-line fix above will do no harm in either case.

Dave Reid’s picture

Status: Needs review » Reviewed & tested by the community

Fair enough. I've posted my fix in #361702: drupal_prepare_form() should always add default validate and submit handlers. Either way, the important thing is that this SA gets fixed. :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

pwolanin’s picture

tagging

mfb’s picture

mfb’s picture

Status: Needs work » Needs review
FileSize
2.54 KB

Updated above patch and added a test.

r.villetet’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch works great!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Fields in Core, -Security Advisory follow-up

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