Skip to content
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

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

Merged
merged 1 commit into from Jul 3, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jun 30, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23319
License MIT
Doc PR

Nearly all validators operating on scalar values (except for some special constraints) do ignore empty values. If you want to forbid them, you have to use the NotBlank constraint instead.

@szymach
Copy link

szymach commented Jun 30, 2017

Very nice, but what about UniqueEntityValidator? If the $entity variable is a null, Doctrine will throw an exception when attempting to load metatada for that value.

@xabbuh
Copy link
Member Author

xabbuh commented Jul 1, 2017

Will the UniqueEntityValidator ever be triggered in that case given that the UniqueEntity constraint is added to a class but not a single property?

@szymach
Copy link

szymach commented Jul 1, 2017

@xabbuh Make a form with an entity as data_class, set the UniqueEntityValidator constraint in the form constraints option, then empty_data to null and it should fail.

@xabbuh xabbuh changed the title [Security][Validator] do not validate empty values [DoctrineBridge][Security][Validator] do not validate empty values Jul 2, 2017
@fabpot fabpot changed the base branch from master to 2.7 July 3, 2017 07:35
@fabpot
Copy link
Member

fabpot commented Jul 3, 2017

Thank you @xabbuh.

@fabpot fabpot merged commit fd7ad23 into symfony:2.7 Jul 3, 2017
fabpot added a commit that referenced this pull request Jul 3, 2017
…y values (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23319
| License       | MIT
| Doc PR        |

Nearly all validators operating on scalar values (except for some special constraints) do ignore empty values. If you want to forbid them, you have to use the `NotBlank` constraint instead.

Commits
-------

fd7ad23 do not validate empty values
@xabbuh xabbuh deleted the issue-23319 branch July 3, 2017 08:00
@fabpot fabpot mentioned this pull request Jul 3, 2017
@@ -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).

@lstrojny
Copy link
Contributor

This is quite a dangerous change: when you validate a users current password and you do not specify a NotBlack constraint additionally to the UserPassword constraint, entering no password will pass validation. This change deserves at least a big fat warning in the upgrade guide.

@beberlei
Copy link
Contributor

The type is called UserPassword, I would argue there is no such thing as an empty password, so how other fields work should not be relevant in this use case.

I don't agree about "at least a big fat warning", I would consider this a security problem and would prefer a revert at least on the UserPassword validator related lines.

@lstrojny
Copy link
Contributor

@beberlei Indeed. The more I think about this the more I consider this a serious security problem.

@xabbuh
Copy link
Member Author

xabbuh commented Jul 14, 2017

see #23507

fabpot added a commit that referenced this pull request Jul 17, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Security] validate empty passwords again

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23341 (comment)
| License       | MIT
| Doc PR        |

It looks like this part of #23341 causes serious security issues for some users who rely on the validator to also compare the empty string with their user's password (see for example #23341 (comment)). Thus I suggest to revert this part of #23341.

Commits
-------

878198c [Security] validate empty passwords again
symfony-splitter pushed a commit to symfony/security-core that referenced this pull request Jul 17, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Security] validate empty passwords again

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23341 (comment)
| License       | MIT
| Doc PR        |

It looks like this part of #23341 causes serious security issues for some users who rely on the validator to also compare the empty string with their user's password (see for example symfony/symfony#23341 (comment)). Thus I suggest to revert this part of #23341.

Commits
-------

878198cefa [Security] validate empty passwords again
symfony-splitter pushed a commit to symfony/security that referenced this pull request Jul 17, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Security] validate empty passwords again

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23341 (comment)
| License       | MIT
| Doc PR        |

It looks like this part of #23341 causes serious security issues for some users who rely on the validator to also compare the empty string with their user's password (see for example symfony/symfony#23341 (comment)). Thus I suggest to revert this part of #23341.

Commits
-------

878198cefa [Security] validate empty passwords again
@smcjones
Copy link

smcjones commented Nov 22, 2017

It would be nice to have the option to validate or not validate on empty data, leaving it to the developer. For example, nullable=true|false. Then there is no BC break but there is a new feature I could really use.

@xabbuh
Copy link
Member Author

xabbuh commented Nov 22, 2017

Feel free to open an issue and such a feature could be discussed.

@vaibhavpandeyvpz
Copy link

This line https://github.com/symfony/security-core/blob/master/Validator/Constraints/UserPasswordValidator.php#L43 takes out the freedom unlike other constraints where I would have added a NotBlank when required. It forces the current password to be not-empty and valid even when it's not needed. For example, I have a profile update form with other fields including 3 fields (current password, new password, confirm password) for password change. I only wish to require presence of value in current password when new password is not empty but the UserPassword is hard-coded against regular Symfony validation conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet