Review main Merged

76002[FEATURE] Add TCA field control „passwordGenerator“

Frank Nägler CR +2 V +2 Hard +477 −0 updated 11/07/22, 22:24

Commit message

This patch adds a new TCA field control "passwordGenerator" for
TCA type "password", which can be used to generate a random
password, based on defined password rules.

The field control will be used in EXT:reactions the first time.

In the future the field control might be combined with the
existing password policies functionality. Therefore, most
of the new functions and classes are marked as internal
for now.

Another feature to be added in the future will be (according
to #69190) a modal / wizard, which will allow to change rules
for the password to be generated.

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Oliver Hader +1
    • Benni Mack +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 2

Files 11

Review log 5977

Show 3852 earlier messages
  1. Frank Nägler uploaded patch set 1 10/07/22, 14:16

  2. core-ci voted on patch set 1 V -1 10/07/22, 14:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32072

  3. Frank Nägler commented on patch set 1 CR -1 10/07/22, 14:31

    still on it
  4. Frank Nägler marked it work in progress 10/07/22, 14:32

  5. Frank Nägler uploaded patch set 2 10/07/22, 14:52

  6. core-ci voted on patch set 2 V -1 10/07/22, 15:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32075

  7. Frank Nägler uploaded patch set 3 10/07/22, 15:02

  8. core-ci voted on patch set 3 V +1 10/07/22, 15:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32076

  9. Frank Nägler rebased onto patch set 4 10/08/22, 06:30

  10. core-ci voted on patch set 4 V +1 10/08/22, 06:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32097

  11. Frank Nägler uploaded patch set 5 10/10/22, 07:12

  12. core-ci voted on patch set 5 V +1 10/10/22, 07:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32136

  13. Frank Nägler marked it ready for review 10/10/22, 11:20

  14. Chris Müller uploaded patch set 6 10/10/22, 13:38

  15. core-ci voted on patch set 6 V +1 10/10/22, 13:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32145

  16. Christian Kuhn commented on patch set 6 CR -1 10/11/22, 05:07

    FormSecretAjaxController.php:27

    please add more information which TCA config triggers this.

    SecretElement.php:104

    i'm not a fan of having too many fluid templates within FormEngine: * Single elements are tailored for *one* use, and not for re-use. The FormEngine API allows overriding of elements and adding own ones. * Having many fluid renderings within FormEngine can be a significant permormance penalty * Using StandaloneView here and not BackendViewFactory defeats v12 feature #96812 Imho: drop fluid rendering and declare "if you want to change it, substitute the element with an own one" using FormEngine API.

    Feature-98540-NewTCATypeSecret.rst:46

    that's api misuse, isn't it? it breaks when the default hash is changed? shouldn't passwordhashfactory->get() be used instead?

    Feature-98540-NewTCATypeSecret.rst:77

    see my comments on templates in the element class.
  17. Oliver Hader commented on patch set 6 CR -1 10/11/22, 08:54

    Not sure whether "secret" is correct here, feels more like a special "password".

    secret-element.ts:89

    Seems to be overhead to let the server create the "token" (which is actually the secret key). Why not generating a random secret key just via JavaScript? Currently the server creates a key, puts it into a form and sends it back to the server as well...

    FormSecretAjaxController.php:42

    Why 16 bytes? And actually this is the "secret" not the token, isn't it? Choosing proper length of a secret key depends on the cryptographic algorithm or scope it should be used for...

    FormSecretAjaxController.php:56

    allows to write over boundaries... `tt_content1234field` - what is `pageId`, what is `recordId`? → use `json_encode` for separation and escaping

    FormSecretAjaxController.php:58

    all parameters - assert type and that index actually exists (PHP8)

    FormSecretAjaxController.php:66

    use specific pepper, e.g. `FormSecretAjaxController::class`

    DataHandler.php:1924

    There is no check on a minimum requirement for a secret key (length, entropy). And thinking about that, it actually is more like a password, which is generated randomly.

    Feature-98540-NewTCATypeSecret.rst:46 Reply

    It looks to me, that "secret" is actually the same as "password" - at least this is how it is handled currently.
  18. Frank Nägler commented on patch set 6 10/11/22, 12:29

    secret-element.ts:89 Reply

    The reason is to use the crypto functionality from PHP instead of any javascript stuff. I think the random implementation is the core is the more secure variant.

    FormSecretAjaxController.php:42 Reply

    That is the same part I used in the EXT:reactions patch. We can also use a UUID as a token/secret or whatever you want. The idea is still the same, a random generated and unique string that is shown only once and then stored encrypted in the database.

    FormSecretAjaxController.php:56 Reply

    Sorry, don't understand that remark. I found the same logic in other places to build and validate the hmac for an ajax call. But by reading the code again, I am not sure if we need the hmac at all. I guess we can remove/skip the hmac part here.

    SecretElement.php:104 Reply

    I was unaware of BackendViewFactory and still have no idea how to use it. Regarding the template at all, I will think about my use case.

    Feature-98540-NewTCATypeSecret.rst:46 Reply

    > It looks to me, that "secret" is actually the same as "password" - at least this is how it is handled currently. Sure, that is exactly what we talked about, the token/secret is like a password and should be handled or stored like a password. So at the moment I don't know what I should do with this comment.
  19. Frank Nägler uploaded patch set 7 10/11/22, 13:22

  20. Frank Nägler commented on patch set 7 CR -1 10/11/22, 13:22

    the -1 one from Lolli and Oliver are still valid and need clarfification.
  21. Frank Nägler commented on patch set 7 10/11/22, 13:24

    FormSecretAjaxController.php:27 Reply

    Ack
  22. core-ci voted on patch set 7 V -1 10/11/22, 13:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32208

  23. Oliver Hader commented on patch set 7 10/11/22, 15:42

    Quote from one of my comments: "Make the current "password" type configurable, to show the "password generator", which is the random hex thingy..." (Just an) Example: ``` 'password' => [ 'label' => 'Secret Key', 'config' => [ 'type' => 'password', 'size' => 20, 'required' => true, 'policy' => 'random-secret-key', ], ], ``` The first step of "password policies" in TYPO3 v12 was done with https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-97388-ConfigurablePasswordPolicies.html - there's probably more, e.g. password generators shown in FormEngine.

    secret-element.ts:89 Reply

    It's not that complicated in JavaScript: `SecurityUtility.getRandomHexValue(40)`, see https://github.com/TYPO3/typo3/blob/main/Build/Sources/TypeScript/core/security-utility.ts#L29-L39 The benefit of using a JavaScript-only approach here, is that the server-side complexity can be avoided completely.

    FormSecretAjaxController.php:42 Reply

    I'd go for a higher entropy than 16 bytes. The password required to be unique? Is it used for identifying any originator?

    FormSecretAjaxController.php:56 Reply

    In the example above, pageId could be `1` and recordId could be `234`. If pageId would be `123` and recordId would be `4` the hash would still be the same - however it is referring to different input parameters. If that's the case in the core like that, it should be enhanced there as well...

    Feature-98540-NewTCATypeSecret.rst:46 Reply

    If it is a password, why reintroducing another storage mechanism with a different name that is doing the same? Suggestion: Make the current "password" type configurable, to show the "password generator", which is the random hex thingy...
  24. Oliver Hader commented on patch set 7 10/11/22, 15:44

    Reply

    For the first step, it probably just would be an additional field-wizard for type `password` that is showing the random hex generator.
  25. Frank Nägler commented on patch set 7 10/11/22, 17:51

    Reply

    ok, will check that. But in that case, the JavaScript generator will make no sense anymore.

    secret-element.ts:89 Reply

    ok, I will use this, I was unaware of this function.

    FormSecretAjaxController.php:56 Reply

    Ack, now I get your point. I already removed the hmac, because and if we go with the JavaScript generator, this not required anymore.
  26. Frank Nägler uploaded patch set 8 10/12/22, 09:17

  27. Frank Nägler commented on patch set 7 CR -1 10/12/22, 09:17

    Reply

    Done
    So, I pushed now an update and resolved most comments. Still open: 1) Template: - I still think building markup in PHP should be prevented when possible. However, we have a template engine, which is a good alternative for such complex markup. - Regarding the BackendViewFactory: We can't use DI here (or correct me if I am wrong). The NodeInterface defines the __construct() method (which looks wrong to me, but that is another topic). If someone can tell me how to use this class here, I will do an update, 2) Password policy - I found the feature description but no current usage in the core. Is this correct? Then this should be implemented in a separate patch.

    secret-element.ts:89 Reply

    Done

    FormSecretAjaxController.php:42 Reply

    Done

    FormSecretAjaxController.php:58 Reply

    Done

    FormSecretAjaxController.php:66 Reply

    Done

    DataHandler.php:1924 Reply

    Done

    Feature-98540-NewTCATypeSecret.rst:46 Reply

    Done
  28. core-ci voted on patch set 8 V +1 10/12/22, 09:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32236

  29. Frank Nägler uploaded patch set 9 10/12/22, 11:42

  30. Frank Nägler commented on patch set 8 10/12/22, 11:42

    I added a demo to the styleguide extension: https://github.com/TYPO3/styleguide/pull/358

    SecretElement.php:104 Reply

    Done

    Feature-98540-NewTCATypeSecret.rst:77 Reply

    Done
  31. core-ci voted on patch set 9 V +1 10/12/22, 11:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32246

  32. Oliver Hader commented on patch set 9 10/12/22, 15:20

    secret-element.ts:44

    Why not using a lit-element for that? The `<button>` can be created natively, and event listeners would be unregistered automatically as well.

    secret-element.ts:56

    I guess `FormEngine` or `FormEngineValidation` are offering something here in JavaScript. At least the state should be changed, since an element value was changed. Otherwise once can just close the form, even if it has modifications.
  33. Frank Nägler commented on patch set 9 CR -1 10/12/22, 19:59

    secret-element.ts:56 Reply

    See lines 61-62, but it not works, will check that tomorrow
  34. Frank Nägler uploaded patch set 10 10/13/22, 13:38

  35. Frank Nägler commented on patch set 10 10/13/22, 13:39

    Reply

    Done
    So, now as lit component and it also marks the field as changed.

    secret-element.ts:44 Reply

    Done

    secret-element.ts:56 Reply

    Done
  36. Frank Nägler updated the commit message in patch set 11 10/13/22, 13:42

  37. core-ci voted on patch set 10 V +1 10/13/22, 13:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32291

  38. core-ci voted on patch set 11 V +1 10/13/22, 13:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32292

  39. Stefan Bürk updated the commit message in patch set 12 10/13/22, 15:54

  40. core-ci voted on patch set 12 V +1 10/13/22, 16:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32300

  41. Chris Müller commented on patch set 12 10/13/22, 21:32

    Feature-98540-NewTCARenderTypePasswordGenerator.rst:14

    A new TCA renderType :php:`passwordGenerator` for the type "password" ...

    Feature-98540-NewTCARenderTypePasswordGenerator.rst:20

    "TsConfig" => "page TSconfig" But how can it be overridden? Please give an example. Or is this sentence outdated?
  42. Stefan Bürk commented on patch set 12 10/13/22, 21:52

    SecretElement.php:104 Reply

    What lolli meant was to avoid fluid rendering at all. Should be done like all the others. And if someone needs to override the template of a form element, cloneing the element and adding as a additional/custom type is the way to go instead of overriding the template (which would be installation wide anyway). Ok, you switched to the BackendViewFactory already - but I want to reask here, why using fluid here ? If we do that for all element types this may end in a performance desaster in the backend for form renderings. Would favorise here to omit fluid reanding at all and do it in php like all the other form elements.
  43. Frank Nägler commented on patch set 12 10/14/22, 12:05

    SecretElement.php:104 Reply

    Hi Stefan, Building markup in PHP is ugly and painful and has the potential to be insecure if you don't take care of escaping correctly. I have no measuring regarding performance, but I can't imagine that is so a big impact. The last time I saw numbers, the cached templates were very fast. If I have to clone the field for my EXT:reaction patch, then we don't need this pre-patch. btw, Benni told me today that he will maybe update the patch today.
  44. Christian Kuhn commented on patch set 12 10/14/22, 22:07

    PasswordGeneratorElement.php:85

    isn't request within $this->data?
  45. Oli Bartsch commented on patch set 12 V -1 11/03/22, 13:02

    On it. This should be implemented as a FieldControl instead of a new renderType. This makes duplicating the password elements' code superflouse and also allows to provide more options, e.g. using password policy API.
  46. Georg Ringer commented on patch set 12 11/03/22, 14:14

    is it a secret generator or a password generator? as we have now password rules the generated password must follow the allowed rules. the wizard would be then great for regular password fields as well
  47. Torben Hansen commented on patch set 12 V -1 11/04/22, 08:11

    I want to point out the open tasks for the global password policy implementation (see #97387). It is planned to implement password policy validation to dataHandler (for TCA type=password fields of the tables be_users and fe_users). So if the password generator in this patch will be used to create a password for a backend or frontend user, we need to ensure, that the generated password matches the configured password policy. Since password policies are extendable with custom requirements (e.g. site administrator can add an own validator, which checks a password against a password deny-list), this must somehow be taken into account (which IMO is not easily possible). AFAICS is the main purpose of this patch to create a token for the upcoming webhook feature in TYPO3. Although this token should be treated like a password (randomnes, length, saved as hash to DB), it should not follow globally configured password policy rules for user passwords. IMO it will be better to name this component e.g. "tokenGenerator" and to make it completely independent from everything that has to do with user passwords.
  48. Oli Bartsch uploaded patch set 13 11/04/22, 11:39

  49. Oli Bartsch uploaded patch set 14 11/04/22, 11:42

  50. Oli Bartsch commented on patch set 14 11/04/22, 11:46

    Reply

    Thanks for your input. I agree and therefore implemented the new field control in a way that it's possible to define password rules but without any connection to the password policy functionality. I marked all those new classes @internal for now. This allows to extend / change the internal handling in the future in case we want to connect those two things somehow.
  51. core-ci voted on patch set 13 V -1 11/04/22, 11:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33105

  52. core-ci voted on patch set 14 V -1 11/04/22, 11:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33106

  1. Oli Bartsch uploaded patch set 15 11/04/22, 12:29

  2. core-ci voted on patch set 15 V +1 11/04/22, 12:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33112

  3. Oli Bartsch updated the commit message in patch set 16 11/04/22, 14:05

  4. Oliver Hader commented on patch set 16 11/04/22, 14:17

    Concerning the password policy interaction, please find a draft of how that might be configured at https://forge.typo3.org/issues/97389
  5. core-ci voted on patch set 16 V +1 11/04/22, 14:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33128

  6. Benni Mack commented on patch set 16 11/04/22, 14:51

    SecretElement.php:104 Reply

    Done

    Feature-98540-NewTCARenderTypePasswordGenerator.rst:14 Reply

    Done

    Feature-98540-NewTCARenderTypePasswordGenerator.rst:20 Reply

    Done
  7. Benni Mack commented on patch set 16 V +1 CR +1 11/04/22, 15:57

    Reply

    Done

    PasswordGeneratorElement.php:85 Reply

    Done
  8. Christian Kuhn commented on patch set 16 11/04/22, 16:44

    PasswordGeneratorController.php:42

    we may want to transfer a hmack of the rules along with the rules and check this here: users should not be able to change rule-settings my manipulating input data?
  9. Oliver Hader commented on patch set 16 11/04/22, 20:11

    Using `random_bytes()` is somehow missing - which is much simpler and secure than manually shuffling a reduce alphabet...

    Random.php:106

    `array_rand` is not PRNG secure, use `random_int` instead, like in https://github.com/lamansky/secure-shuffle/blob/master/src/functions.php

    Feature-98540-NewFieldControlPasswordGenerator.rst:39

    This is different to the names of existing password policies. Can't that be unified? see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-97388-ConfigurablePasswordPolicies.html#typo3cmscorepasswordpolicyvalidatorcorepasswordvalidator Besides that, having a way just use `bin2hex(random_bytes(20))` would be great.
  10. Oliver Hader voted on patch set 16 CR -1 11/04/22, 20:11

  11. Oli Bartsch uploaded patch set 17 11/07/22, 18:10

  12. Oli Bartsch commented on patch set 17 11/07/22, 18:11

    Reply

    As discussed, this is resolved with the "random" option.

    PasswordGeneratorController.php:42 Reply

    I got your point. However, this controller does not persist any data but is only used as a client feature to generate a password based on defined rules. The user is usually still able to edit / overwrite such password. Verification of the submitted password will then always happen on the server side. This means, in case a user intentionally manipulates the rules, this does not matter since the then generated password shouldn't be accepted by the server in such case.

    Random.php:106 Reply

    Change the code to use `random_int`.

    Feature-98540-NewFieldControlPasswordGenerator.rst:39 Reply

    I adjusted the naming accordingly and introduced the special "random" option to the "passwordRules".
  13. core-ci voted on patch set 17 V +1 11/07/22, 18:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33222

  14. Christian Kuhn commented on patch set 17 11/07/22, 19:17

    PasswordGeneratorController.php:42 Reply

    ok. thx.
  15. Benni Mack uploaded patch set 18 11/07/22, 19:34

  16. Benni Mack voted on patch set 18 V +1 CR +1 11/07/22, 19:35

  17. core-ci voted on patch set 18 V +1 11/07/22, 19:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33224

  18. Oliver Hader voted on patch set 18 CR +1 11/07/22, 19:48

  19. Georg Ringer voted on patch set 18 V +2 CR +2 11/07/22, 20:03

  20. Georg Ringer merged patch set 19 11/07/22, 20:03

  21. Oliver Hader commented on patch set 19 11/07/22, 20:05

    -1
  22. Oliver Hader commented on patch set 19 11/07/22, 20:07

    Random.php:114

    out of bounds, needs to be one less

    Random.php:119

    out of bounds, needs to be one less
  23. Oliver Hader commented on patch set 19 11/07/22, 20:08

    ``` diff --git a/typo3/sysext/core/Classes/Crypto/Random.php b/typo3/sysext/core/Classes/Crypto/Random.php index 8de171374c..09476c72f4 100644 --- a/typo3/sysext/core/Classes/Crypto/Random.php +++ b/typo3/sysext/core/Classes/Crypto/Random.php @@ -111,12 +111,12 @@ class Random } foreach ($characterSets as $characterSet) { - $password .= $characterSet[random_int(0, strlen($characterSet))]; + $password .= $characterSet[random_int(0, strlen($characterSet) - 1)]; } $charactersCount = count($characters); for ($i = 0; $i < $passwordLength - count($characterSets); $i++) { - $password .= $characters[random_int(0, $charactersCount)]; + $password .= $characters[random_int(0, $charactersCount - 1)]; ```
  24. Oli Bartsch commented on patch set 19 11/07/22, 20:12

    Reply

    Thanks, already on it.

    Random.php:114 Reply

    Will push a follow up.

    Random.php:119 Reply

    Will push a follow up.
  25. Oli Bartsch commented on patch set 19 11/07/22, 22:24

    Random.php:114 Reply

    Done

    Random.php:119 Reply

    Done