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

[Cookbook] Make registration_form follow best practices #4773

Merged
merged 1 commit into from Feb 7, 2016

Conversation

xelaris
Copy link
Contributor

@xelaris xelaris commented Jan 5, 2015

Q A
Doc fix? yes
New docs? no
Applies to 2.3+
Fixed tickets

@@ -45,7 +45,7 @@ You have a simple ``User`` entity mapped to the database::
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Assert\Length(max = 4096)
* @Assert\Length(max=4096)
Copy link
Member

Choose a reason for hiding this comment

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

Don't you think it's time to remove this constraint? Thinking about a password longer than 4,000 chars is ridiculous and the Security component already has this constraint hardcoded: https://github.com/symfony/symfony/blob/eee117285ae84b9aa859814d6d0cef9fd7f05baa/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php#L23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a note about that in the unchanged text

Why the 4096 Password Limit?

Notice that the plainPassword field has a max length of 4096 characters. For security purposes (CVE-2013-5750), Symfony limits the plain password length to 4096 characters when encoding it. Adding this constraint makes sure that your form will give a validation error if anyone tries a super-long password.

I agree that a password longer than 4000 chars is ridiculous, but for me, it sounds like the constraint is still reasonable to provide a user friendly validation error. As I write this... a friendly user would never enter 4000 chars and a malicious user don't need a user friendly error message.

Copy link
Member

Choose a reason for hiding this comment

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

@xelaris to avoid getting an exception when trying to encode it (a malicious user should still receive a 400 status code rather than a 500)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof I agree, responding with 500 in this case would be neat. But if I am not wrong, without further changes the form with validation error will be shown along with status code 200. Anyway I agree the 4096 constraint makes sense to avoid 500.

While testing this, I saw an other issue with the example. Although the note mentions that the limit is relevant when it comes to encoding the password, in the current version, where the password is stored in plain text, the user gets a 500 response due to a PDOException, when entering a password longer than the table field but shorter than 4096.

What about expanding this chapter to store an encoded password? Alternatively either the column length should be set to match the constraint (e.g. 4096) or vice versa (e.g. 255). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Wait, we are storing the plain password ? This must be fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I re-read the preamble of this entry. Thereby I become unsure about what the actual topic of this entry is. On the one hand it resides in the doctrine category and is about "extra fields whose values don't need to be stored in the database", on the other hand it's about a registration form and thus related to security.
The more I think about it... maybe this entry should be splitted into two entries. One to fulfill the preamble of the current entry and one to implement a comprehensive registration form like the headline promises. Therefore it requires another example/usecase for the doctrine/form related entry. The new entry about a registration form wouldn't need the embedded form, because the "terms accepted" can be ignored there. Assuming that the registration from would operate with the security system (e.g. an entity that implements the UserInterface of the Security component and using the recommended bcrypt encoder via security.yml) it would not be as "simple" as the current registration form. I think it would be nice to complement http://symfony.com/doc/current/cookbook/security/form_login_setup.html and http://symfony.com/doc/current/cookbook/security/entity_provider.html with the new entry about a registration from since the latter one already describes the required User implementing the UserInterface and the security.yml.
What are your opinions?

@xelaris
Copy link
Contributor Author

xelaris commented Jan 7, 2015

PR has been updated to address the comments from @stof and @javiereguiluz. The password is now encoded before storing it into the database. This makes the chapter more security related than before. As mentioned in #4773 (comment) IMO splitting this chapter should be considered.

@wouterj
Copy link
Member

wouterj commented Jan 16, 2015

Sorry, I'm a bit lost. Is this PR now ready to merge, or does it wait on comments?

@xelaris
Copy link
Contributor Author

xelaris commented Jan 16, 2015

I think my last changes, which introduced the encoding of the password, should be reviewed. If the changes are approved, this PR could be merged IMO. Anyway, I think it would be a good idea to split the entry, but this could be done in a later PR if someone agrees with my opinion.

@@ -10,13 +11,13 @@ database. For example, you may want to create a registration form with some
extra fields (like a "terms accepted" checkbox field) and embed the form
that actually stores the account information.

The simple User Model
---------------------
The simple User Entity
Copy link
Member

Choose a reason for hiding this comment

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

it's not your fault, but this should actually be: The Simple User Entity

And can you please add a placeholder for the old headline:

.. _the-simple-user-model:

The Simple User Entity
----------------------

Copy link
Member

Choose a reason for hiding this comment

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

Simple could also be changed in the same way in the main headline (line 6).

@xelaris
Copy link
Contributor Author

xelaris commented Jan 18, 2015

Thank you for the review @wouterj @xabbuh. I updated the PR.

@xelaris
Copy link
Contributor Author

xelaris commented Mar 29, 2015

IMO this is ready to merge, isn't it?

@javiereguiluz
Copy link
Member

@xelaris 👍 indeed it looks ready to be merged. Thanks!

@@ -36,7 +39,7 @@ You have a simple ``User`` entity mapped to the database::
protected $id;

/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, unique=true)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to also add a UniqueEntity constraint then?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, it's already part of the folded code above.

@xabbuh
Copy link
Member

xabbuh commented May 23, 2015

@wouterj As you added the "In Progress" label after the last change: What do you think needs to be done here?

@xabbuh
Copy link
Member

xabbuh commented Dec 17, 2015

Do we still have to do something here or is it ready to be merged?

@wouterj
Copy link
Member

wouterj commented Dec 17, 2015

👍 (a rebase is needed though)

@xabbuh
Copy link
Member

xabbuh commented Dec 23, 2015

closing in favour of #6073

@xabbuh xabbuh closed this Dec 23, 2015
@xabbuh
Copy link
Member

xabbuh commented Dec 28, 2015

reopening here as #6073 was closed

@xabbuh xabbuh reopened this Dec 28, 2015
@xelaris
Copy link
Contributor Author

xelaris commented Dec 29, 2015

I rebased this PR and took a look into the overlap with #5214. Most of the changes made in this PR where already covered or obsoleted by #5214. There are only some tweaks remaining and a focus on encoding with bcrypt including the detailed example on how to configure the encoding algorithm.

Related to the comments made in #6073: The handling of the plain text password is still relevant, as the entity class holds both, the plain and the encoded password. In contrast to the first version of this PR, a password property was introduced in #5214 for persistence and the plainPassword gets stopped from being persisted, but kept relevant for form handling and validation. Actually there was a Registration DTO before #5214.

@wouterj
Copy link
Member

wouterj commented Feb 7, 2016

👍 As far as I can see, this one looks ready to me.

@xabbuh
Copy link
Member

xabbuh commented Feb 7, 2016

Thank you @xelaris.

@xabbuh xabbuh merged commit b7ab3e4 into symfony:2.3 Feb 7, 2016
xabbuh added a commit that referenced this pull request Feb 7, 2016
…xelaris)

This PR was merged into the 2.3 branch.

Discussion
----------

[Cookbook] Make registration_form follow best practices

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.3+
| Fixed tickets |

Commits
-------

b7ab3e4 [Cookbook] Tweaking registration_form (e.g. bcrypt)
@xelaris xelaris deleted the reg-form branch October 31, 2022 12:17
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

5 participants