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

[Form] Add hash_mapping option to PasswordType#42883

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

Closed

Conversation

@Seb33300
Copy link
Contributor

@Seb33300Seb33300 commentedSep 4, 2021
edited
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#29066
LicenseMIT
Doc PRsymfony/symfony-docs#15872

Following#42807 with a different implementation.

This PR adds a newhash_mapping option toPasswordType.

Thehash_mapping option can be set with a property path where we want to store the hashed password.

Some questions I have:

  • Is it better to move this out from theCore to a dedicatedPasswordHasher extension? (same asCsrf,Validator, ...)
  • Not sure if this can be made generic and not only forPasswordAuthenticatedUserInterface entities (is it possible withPasswordHasher component?)
  • Should we automatically generate a new salt if the entity is using a legacy algorithm?

I am submitting this PR to get feedback for now, and if they are positive, I will continue the work to add tests.

Copy link
Member

@ycerutoyceruto left a comment

Choose a reason for hiding this comment

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

I continue thinking that this hashing process does not belong to the Form flow (at least under the current possibilities it gives us) because this must be done after validation passed successfully (and not only validations linked to this password field itself but the entire form must be valid). Doing this before it causes security issues and doing this after it looks out of Form's responsibility to modify directly the underlying data without any standard Form's mechanism (data mapper, etc).

publicstaticfunctiongetSubscribedEvents()
{
return [
FormEvents::SUBMIT => ['hashPassword', -256],
Copy link
Member

Choose a reason for hiding this comment

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

ifhash_mapping is referring to the same property path as the mapped field then we are hashing the plain password before validating it, which looks wrong.

Copy link
Member

Choose a reason for hiding this comment

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

Also, if something goes wrong during plain password validation you can end up with a wrong hashed password (from#42807 (review)in the DB if your object is a Doctrine entity and you flush changes, but also potentially when serializing the user in the session if the edited user is the currently authenticated user)

Copy link
ContributorAuthor

@Seb33300Seb33300Sep 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

The purpose of this PR is to store the password hash in a different property.
I did the change sohash_mapping cannot refer to itself.

And thePasswordType field should be unmapped. Maybe I should force it ifhash_mapping is used?

Also, if some validation constraints are put on the entity password property (the hashed one), for example aNotBlank, the hash needs to be populated before the validation to work.

And regarding your second comment, if something goes wrong during the validation, "the issue" you described is not really specific to this feature.
All others fields of the form are also already populate in the entity before validation. The same behavior already happens even if we don't use this new feature.

{
$resolver->setDefaults([
'always_empty' =>true,
'hash_mapping' =>null,
Copy link
Member

Choose a reason for hiding this comment

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

In this new approachhash_mapping must be different fromproperty_path to avoid the issue explained above.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes you are right, and this is also the reason we cannot use the previous PR.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed

@Seb33300Seb33300 changed the title[Form] Add a hash_mapping option to PasswordType[Form] Add hash_mapping option to PasswordTypeSep 5, 2021
@Seb33300Seb33300force-pushed thepassword-hash-mapping branch 2 times, most recently from599f112 to300928cCompareSeptember 7, 2021 04:38
@nicolas-grekasnicolas-grekas added this to the5.4 milestoneSep 7, 2021
{
if ($options['hash_mapping']) {
if ($options['hash_mapping'] ==$builder->getName()) {
thrownewInvalidConfigurationException('The hash_mapping property must be a different.');
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure if I had to useInvalidConfigurationException orInvalidOptionsException

@Seb33300
Copy link
ContributorAuthor

I created the documentation PR.

@Seb33300
Copy link
ContributorAuthor

Closed for#46224

fabpot added a commit that referenced this pull requestOct 22, 2022
…e` (Seb33300)This PR was merged into the 6.2 branch.Discussion----------[Form] Add `hash_property_path` option to `PasswordType`| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       |Fix#29066| License       | MIT| Doc PR        |symfony/symfony-docs#15872Same as#42883 but using a Form Extension and rebased to 6.1 & tests.This PR adds a new `hash_mapping` option to `PasswordType`.The `hash_mapping` option can be set with a property path where we want to set the hashed password.The `hash_mapping` option can only be used on unmapped fields to minimize plain password leak.Commits-------7065dfe [Form] Add hash_mapping option to PasswordType
@Seb33300Seb33300 deleted the password-hash-mapping branchApril 26, 2024 09:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@ycerutoycerutoyceruto requested changes

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

Auto Password Encoder

6 participants

@Seb33300@OskarStark@yceruto@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp