76002[FEATURE] Add TCA field control „passwordGenerator“
Commit message
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
- Build/Sources/TypeScript/backend/form-engine/field-control/password-generator.tsnew+92 −0
- typo3/sysext/backend/Classes/Form/FieldControl/PasswordGenerator.phpnew+67 −0
- typo3/sysext/backend/Classes/Form/NodeFactory.php+1 −0
- typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php+6 −0
- typo3/sysext/backend/Resources/Public/JavaScript/form-engine/field-control/password-generator.jsnew+13 −0
- typo3/sysext/core/Classes/Controller/PasswordGeneratorController.php3new+72 −0
- typo3/sysext/core/Classes/Crypto/Random.php8+80 −0
- typo3/sysext/core/Classes/Exception/InvalidPasswordRulesException.phpnew+27 −0
- typo3/sysext/core/Configuration/Services.yaml+3 −0
- typo3/sysext/core/Documentation/Changelog/12.1/Feature-98540-NewFieldControlPasswordGenerator.rst2new+110 −0
- typo3/sysext/core/Resources/Private/Language/locallang_core.xlf+6 −0
Review log 5977
Show 3852 earlier messages
-
Frank Nägler uploaded patch set 1 10/07/22, 14:16
-
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
-
Frank Nägler commented on patch set 1 CR -1 10/07/22, 14:31
still on it -
Frank Nägler marked it work in progress 10/07/22, 14:32
-
Frank Nägler uploaded patch set 2 10/07/22, 14:52
-
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
-
Frank Nägler uploaded patch set 3 10/07/22, 15:02
-
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
-
Frank Nägler rebased onto patch set 4 10/08/22, 06:30
-
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
-
Frank Nägler uploaded patch set 5 10/10/22, 07: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
-
Frank Nägler marked it ready for review 10/10/22, 11:20
-
Chris Müller uploaded patch set 6 10/10/22, 13:38
-
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
-
Christian Kuhn commented on patch set 6 CR -1 10/11/22, 05:07
FormSecretAjaxController.php:27please add more information which TCA config triggers this.SecretElement.php:104i'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:46that'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:77see my comments on templates in the element class. -
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:89Seems 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:42Why 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:56allows to write over boundaries... `tt_content1234field` - what is `pageId`, what is `recordId`? → use `json_encode` for separation and escapingFormSecretAjaxController.php:58all parameters - assert type and that index actually exists (PHP8)FormSecretAjaxController.php:66use specific pepper, e.g. `FormSecretAjaxController::class`DataHandler.php:1924There 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:46ReplyIt looks to me, that "secret" is actually the same as "password" - at least this is how it is handled currently. -
Frank Nägler commented on patch set 6 10/11/22, 12:29
secret-element.ts:89ReplyThe 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:42ReplyThat 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:56ReplySorry, 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:104ReplyI 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:46Reply> 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. -
Frank Nägler uploaded patch set 7 10/11/22, 13:22
-
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. -
Frank Nägler commented on patch set 7 10/11/22, 13:24
FormSecretAjaxController.php:27ReplyAck -
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
-
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:89ReplyIt'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:42ReplyI'd go for a higher entropy than 16 bytes. The password required to be unique? Is it used for identifying any originator?FormSecretAjaxController.php:56ReplyIn 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:46ReplyIf 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... -
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. -
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:89Replyok, I will use this, I was unaware of this function.FormSecretAjaxController.php:42ReplySee the middleware in the other patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75482/30/typo3/sysext/reactions/Classes/Http/Middleware/ReactionHandler.php#67FormSecretAjaxController.php:56ReplyAck, now I get your point. I already removed the hmac, because and if we go with the JavaScript generator, this not required anymore. -
Frank Nägler uploaded patch set 8 10/12/22, 09:17
-
Frank Nägler commented on patch set 7 CR -1 10/12/22, 09:17
Reply
DoneSo, 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:89ReplyDoneFormSecretAjaxController.php:42ReplyDoneFormSecretAjaxController.php:58ReplyDoneFormSecretAjaxController.php:66ReplyDoneDataHandler.php:1924ReplyDoneFeature-98540-NewTCATypeSecret.rst:46ReplyDone -
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
-
Frank Nägler uploaded patch set 9 10/12/22, 11:42
-
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/358SecretElement.php:104ReplyDoneFeature-98540-NewTCATypeSecret.rst:77ReplyDone -
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
-
Oliver Hader commented on patch set 9 10/12/22, 15:20
secret-element.ts:44Why 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:56I 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. -
Frank Nägler commented on patch set 9 CR -1 10/12/22, 19:59
secret-element.ts:56ReplySee lines 61-62, but it not works, will check that tomorrow -
Frank Nägler uploaded patch set 10 10/13/22, 13:38
-
Frank Nägler commented on patch set 10 10/13/22, 13:39
Reply
DoneSo, now as lit component and it also marks the field as changed.secret-element.ts:44ReplyDonesecret-element.ts:56ReplyDone -
Frank Nägler updated the commit message in patch set 11 10/13/22, 13:42
-
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
-
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
-
Stefan Bürk updated the commit message in patch set 12 10/13/22, 15:54
-
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
-
Chris Müller commented on patch set 12 10/13/22, 21:32
Feature-98540-NewTCARenderTypePasswordGenerator.rst:14A 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? -
Stefan Bürk commented on patch set 12 10/13/22, 21:52
SecretElement.php:104ReplyWhat 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. -
Frank Nägler commented on patch set 12 10/14/22, 12:05
SecretElement.php:104ReplyHi 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. -
Christian Kuhn commented on patch set 12 10/14/22, 22:07
PasswordGeneratorElement.php:85isn't request within $this->data? -
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. -
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 -
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. -
Oli Bartsch uploaded patch set 13 11/04/22, 11:39
-
Oli Bartsch uploaded patch set 14 11/04/22, 11:42
-
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. -
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
-
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
-
Oli Bartsch uploaded patch set 15 11/04/22, 12:29
-
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
-
Oli Bartsch updated the commit message in patch set 16 11/04/22, 14:05
-
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 -
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
-
Benni Mack commented on patch set 16 11/04/22, 14:51
SecretElement.php:104ReplyDoneFeature-98540-NewTCARenderTypePasswordGenerator.rst:14ReplyDoneFeature-98540-NewTCARenderTypePasswordGenerator.rst:20ReplyDone -
Benni Mack commented on patch set 16 V +1 CR +1 11/04/22, 15:57
Reply
DonePasswordGeneratorElement.php:85ReplyDone -
Christian Kuhn commented on patch set 16 11/04/22, 16:44
PasswordGeneratorController.php:42we 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? -
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.phpFeature-98540-NewFieldControlPasswordGenerator.rst:39This 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. -
Oliver Hader voted on patch set 16 CR -1 11/04/22, 20:11
-
Oli Bartsch uploaded patch set 17 11/07/22, 18:10
-
Oli Bartsch commented on patch set 17 11/07/22, 18:11
Reply
As discussed, this is resolved with the "random" option.PasswordGeneratorController.php:42ReplyI 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:106ReplyChange the code to use `random_int`.Feature-98540-NewFieldControlPasswordGenerator.rst:39ReplyI adjusted the naming accordingly and introduced the special "random" option to the "passwordRules". -
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
-
Christian Kuhn commented on patch set 17 11/07/22, 19:17
PasswordGeneratorController.php:42Replyok. thx. -
Benni Mack uploaded patch set 18 11/07/22, 19:34
-
Benni Mack voted on patch set 18 V +1 CR +1 11/07/22, 19:35
-
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
-
Oliver Hader voted on patch set 18 CR +1 11/07/22, 19:48
-
Georg Ringer voted on patch set 18 V +2 CR +2 11/07/22, 20:03
-
Georg Ringer merged patch set 19 11/07/22, 20:03
-
Oliver Hader commented on patch set 19 11/07/22, 20:05
-1 -
Oliver Hader commented on patch set 19 11/07/22, 20:07
Random.php:114out of bounds, needs to be one lessRandom.php:119out of bounds, needs to be one less -
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)]; ``` -
Oli Bartsch commented on patch set 19 11/07/22, 20:12
Reply
Thanks, already on it.Random.php:114ReplyWill push a follow up.Random.php:119ReplyWill push a follow up. -
Oli Bartsch commented on patch set 19 11/07/22, 22:24
Reply
Please have a look at https://review.typo3.org/c/Packages/TYPO3.CMS/+/76461Random.php:114ReplyDoneRandom.php:119ReplyDone