Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:2.7fromxabbuh:issue-23319
Jul 3, 2017

Conversation

@xabbuh
Copy link
Member

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#23319
LicenseMIT
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 theNotBlank constraint instead.

Hanmac, linaori, and apfelbox reacted with thumbs up emoji
@szymach
Copy link

Very nice, but what aboutUniqueEntityValidator? If the$entity variable is anull, Doctrine will throw an exception when attempting toload metatada for that value.

@xabbuh
Copy link
MemberAuthor

Will theUniqueEntityValidator ever be triggered in that case given that theUniqueEntity constraint is added to a class but not a single property?

@szymach
Copy link

@xabbuh Make a form with an entity asdata_class, set theUniqueEntityValidator constraint in the formconstraints option, thenempty_data tonull and it should fail.

@xabbuhxabbuh changed the title[Security][Validator] do not validate empty values[DoctrineBridge][Security][Validator] do not validate empty valuesJul 2, 2017
@fabpotfabpot changed the base branch frommaster to2.7July 3, 2017 07:35
@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commitfd7ad23 intosymfony:2.7Jul 3, 2017
fabpot added a commit that referenced this pull requestJul 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
@xabbuhxabbuh deleted the issue-23319 branchJuly 3, 2017 08:00
@fabpotfabpot mentioned this pull requestJul 3, 2017
}

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'scurrent_password field used inChangePasswordFormType andProfileFormType allowing to send empty passwords instead of the user's current one.

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.

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 functionhash_equals was used. If that gets a null in comparison, it breaks.

Choose a reason for hiding this comment

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

Here to be specfic.

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 useshash_equals. Not sure how this should be resolved though. Should not you useNotBlank validator anyway?

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 anull cannot be a password, so I would simply do a fix on the side ofFOSUB

Copy link
Contributor

@symfonyamlsymfonyamlJul 5, 2017
edited
Loading

Choose a reason for hiding this comment

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

Now if usingFOSUserBundle'sChangePasswordFormType, 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

@crauecraueJul 5, 2017
edited
Loading

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.

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, anull can not be a password).

jaylinski reacted with thumbs up emoji
@lstrojny
Copy link
Contributor

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

jusurb, beberlei, apfelbox, colinodell, and murilolobato reacted with thumbs up emoji

@beberlei
Copy link
Contributor

The type is calledUserPassword, 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.

apfelbox reacted with thumbs up emoji

@lstrojny
Copy link
Contributor

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

@xabbuh
Copy link
MemberAuthor

see#23507

fabpot added a commit that referenced this pull requestJul 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 requestJul 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 examplesymfony/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 requestJul 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 examplesymfony/symfony#23341 (comment)). Thus I suggest to revert this part of #23341.Commits-------878198cefa [Security] validate empty passwords again
@smcjones
Copy link

smcjones commentedNov 22, 2017
edited
Loading

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
MemberAuthor

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

@vaibhavpandeyvpz
Copy link

This linehttps://github.com/symfony/security-core/blob/master/Validator/Constraints/UserPasswordValidator.php#L43 takes out the freedom unlike other constraints where I would have added aNotBlank 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 theUserPassword is hard-coded against regular Symfony validation conventions.

pawel956 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+5 more reviewers

@crauecrauecraue left review comments

@szymachszymachszymach left review comments

@symfonyamlsymfonyamlsymfonyaml left review comments

@ogizanagiogizanagiogizanagi approved these changes

@SimperfitSimperfitSimperfit approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

12 participants

@xabbuh@szymach@fabpot@lstrojny@beberlei@smcjones@vaibhavpandeyvpz@craue@ogizanagi@Simperfit@symfonyaml@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp