Skip to content

[DoctrineBridge][Security][Validator] do not validate empty values #23341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function validate($entity, Constraint $constraint)
throw new ConstraintDefinitionException('At least one field has to be specified.');
}

if (null === $entity) {
return;
}

if ($constraint->em) {
$em = $this->registry->getManager($constraint->em);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function validate($password, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
}

if (null === $password || '' === $password) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks FOSUserBundle's current_password field used in ChangePasswordFormType and ProfileFormType allowing to send empty passwords instead of the user's current one.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well they would receive an exception, so I am not sure that is a proper way of handling the case anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to get the proper constraint message rendered with the form, no exception.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because you ran it on PHP lower than 5.6, before function hash_equals was used. If that gets a null in comparison, it breaks.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here to be specfic.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, you are right, 2.8 is the first version that uses hash_equals. Not sure how this should be resolved though. Should not you use NotBlank validator anyway?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this change only standardizes the usage of the validator, since it already ignored empty strings. It is pretty obvious a null cannot be a password, so I would simply do a fix on the side of FOSUB

Copy link
Contributor

@symfonyaml symfonyaml Jul 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now if using FOSUserBundle's ChangePasswordFormType, then logged in users can change their own password without typing the current password. I created a pull request:
FriendsOfSymfony/FOSUserBundle#2582

Copy link
Contributor

@craue craue Jul 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR really shouldn't have been merged as-is in older branches due to this BC break.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still believe that this is an implementation error on FOS side, not a BC break. Empty values should be checked by a specific validator, not by one which by default should not handle them (as I have said before, a null can not be a password).

}

$user = $this->tokenStorage->getToken()->getUser();

if (!$user instanceof UserInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url');
}

if (null === $value) {
if (null === $value || '' === $value) {
return;
}

Expand Down