93069[TASK] Migrate EXT:form from jQuery to Vanilla JS - $.extend()
Commit message
Review
-
Code review CR +2 Done
- Benjamin Franzke +2
- Benjamin Kott +1
-
Verified V +2 Done
- Benjamin Franzke +2
- Benjamin Kott +1
- core-ci +1 CI
Issues 1
Files 16
- Build/Sources/TypeScript/form/backend/form-editor/core.ts+5 −5
- Build/Sources/TypeScript/form/backend/form-editor/helper.ts+2 −1
- Build/Sources/TypeScript/form/backend/form-editor/inspector-component.ts+3 −1
- Build/Sources/TypeScript/form/backend/form-editor/modals-component.ts+2 −1
- Build/Sources/TypeScript/form/backend/form-editor/stage-component.ts+2 −1
- Build/Sources/TypeScript/form/backend/form-editor/view-model.ts+2 −1
- Build/Sources/TypeScript/form/backend/form-editor.ts2+6 −5
- Build/package-lock.json+18 −0
- Build/package.json+1 −0
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/core.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/helper.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/inspector-component.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/modals-component.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/stage-component.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/view-model.js+1 −1
- typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor.js+1 −1
Review log 2736
Show 811 earlier messages
-
Josua Vogel uploaded patch set 1 03/04/26, 15:37
-
Josua Vogel marked it work in progress 03/04/26, 15:38
-
core-ci voted on patch set 1 V +1 03/04/26, 15:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97337
-
Josua Vogel uploaded patch set 2
V +103/04/26, 16:31 -
Josua Vogel marked it ready for review 03/04/26, 16:32
-
Josua Vogel uploaded patch set 3 03/04/26, 16:37
-
core-ci voted on patch set 2 V +1 03/04/26, 16:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97346
-
core-ci voted on patch set 3 V +1 03/04/26, 16:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97347
-
Benjamin Franzke commented on patch set 3 03/05/26, 04:27
deep cloning can be tricky (security wise) in JS, I just want to mention – without that I had a look at the code yet – that we need to make *extra care* to not introduce property pollution issues as JQuery had in the past (in their `$.extend()` implementation). See: https://nvd.nist.gov/vuln/detail/cve-2019-11358 https://snyk.io/de/blog/after-three-years-of-silence-a-new-jquery-prototype-pollution-vulnerability-emerges-once-again/ also an example here for code that looks "quite" right but it vulnerable: https://medium.com/@appsecwarrior/prototype-pollution-a-javascript-vulnerability-c136f801f9e1#:~:text=attacker%20privileged%20access.-,Example%20of%20Prototype%20Pollution,-Consider%20the%20following I'd ideally love to see if we can achieve whatever is done here with another library (maybe picking lodash parts) or by replacing the deep clone. -
Benjamin Franzke commented on patch set 3 CR -1 03/05/26, 05:24
Reply
Just checked, this code is not safe. Here is a minimal reproduction example that can simply be invoked in the browser console when the patch is checked out: ``` const { deepMerge } = await import('@typo3/form/backend/form-editor/utility/object-utility.js'); const objectFromJson = JSON.parse('{"__proto__": {"evilProperty": "payload"}}'); deepMerge({foo: 'bar'}, objectFromJson); ``` Prototype of Object is polluted: ``` > Object.prototype.evilProperty 'payload' ``` Which results in the problematic behavior that `evilProperty` is available on *every* object: ``` > console.log(({}).evilProperty); 'payload' ```object-utility.ts:58Let's try to always avoid `any`, instead use `unknown` which forces us to use `typeof` prior using the variables.object-utility.ts:70If I am not mistaken this would copy (instead of cloning) references to arrays, which are also objects and are therefore shared in memory. That means in case the resulting object is mutated, the sources would be mutated as well. Here is an exmaple that would combine object-spread and `structuredClone` to avoid mutation, i think that would be more robust: https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6?permalink_comment_id=4594127#gistcomment-4594127 (Although I still think that we should ideally avoid deep merging at all and replace the usages by simpler code) -
Benjamin Franzke commented on patch set 3 03/05/26, 05:29
Reply
And for comparison: JQuery `$.extend()` blocked this attempt (because they fixed this vulnerability in the past): ``` > const { default: $ } = await import('jquery') > const objectFromJson = JSON.parse('{"__proto__": {"evilProperty": "payload"}}'); // Prototype is not polluted yet > Object.prototype.evilProperty undefined > $.extend(true, {foo: 'bar'}, objectFromJson); {foo: 'bar'} > Object.prototype.evilProperty undefined > console.log(({}).evilProperty); undefined ```
-
Josua Vogel uploaded patch set 4
CR -1V +103/05/26, 14:22 -
Josua Vogel commented on patch set 4 03/05/26, 14:24
Reply
tried to solve this without an external library, please have a look again -
core-ci voted on patch set 4 V +1 03/05/26, 14:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97411
-
Josua Vogel updated the commit message in patch set 5
V +103/06/26, 14:14 -
core-ci voted on patch set 5 V +1 03/06/26, 14:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97513
-
Josua Vogel uploaded patch set 6
V +103/12/26, 18:11 -
Josua Vogel commented on patch set 6 03/12/26, 18:13
@ben@bnf.dev I pushed another patch that uses loadash. Please let me know which version you prefer. -
Josua Vogel uploaded patch set 7 03/12/26, 18:14
-
core-ci voted on patch set 6 V -1 03/12/26, 18:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97844
-
core-ci voted on patch set 7 V +1 03/12/26, 18:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97845
-
Josua Vogel updated the commit message in patch set 8
V +103/13/26, 07:35 -
core-ci voted on patch set 8 V +1 03/13/26, 07:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97872
-
Andreas Kienast commented on patch set 8 03/14/26, 14:48
Reply
Pardon my ignorance, but did you consider https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone, if that'd help at all? -
Josua Vogel commented on patch set 8 03/14/26, 14:55
Reply
Yes, I added this as note in a previous commit message: structuredClone() was considered but cannot be used here because the form editor's model class instances (stored in objectData.renderables and objectData.__parentRenderable) contain methods and circular-like references that structuredClone() cannot handle, whereas jQuery's $.extend(true, {}) silently copies them by reference. -
Andreas Kienast commented on patch set 8 03/14/26, 14:56
Reply
Acknowledged, thanks for your explanation. -
Benjamin Franzke commented on patch set 8 V -1 03/16/26, 09:24
Hm, when loading some (not all) existing forms I receive a console error: ``` core.js?bust=9cc7f11…c7825bf6d1a510b4:13 Uncaught (in promise) Error: Invalid parameter "classNameIdentifier" (sortable) (1478803906) at a (core.js?bust=9cc7f11…5bf6d1a510b4:13:278) at P.assert (core.js?bust=9cc7f11…5bf6d1a510b4:13:315) at c.assert (form-editor.js?bust=…bf6d1a510b4:13:1323) at a (helper.js?bust=9cc7f…5bf6d1a510b4:13:733) at Module.y (helper.js?bust=9cc7f…bf6d1a510b4:13:1373) at De (inspector-component.…bf6d1a510b4:13:5857) at Module.Se (inspector-component.…f6d1a510b4:13:11000) at Module.Te (view-model.js?bust=9…f6d1a510b4:13:13268) at Object.func (mediator.js?bust=9cc…bf6d1a510b4:13:7321) at T.publish (core.js?bust=9cc7f11…bf6d1a510b4:13:7040) a @ core.js?bust=9cc7f11…c7825bf6d1a510b4:13 assert @ core.js?bust=9cc7f11…c7825bf6d1a510b4:13 assert @ form-editor.js?bust=…c7825bf6d1a510b4:13 a @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 y @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 De @ inspector-component.…c7825bf6d1a510b4:13 Se @ inspector-component.…c7825bf6d1a510b4:13 Te @ view-model.js?bust=9…c7825bf6d1a510b4:13 (anonymous) @ mediator.js?bust=9cc…c7825bf6d1a510b4:13 publish @ core.js?bust=9cc7f11…c7825bf6d1a510b4:13 q @ inspector-component.…c7825bf6d1a510b4:13 z @ inspector-component.…c7825bf6d1a510b4:13 Ae @ inspector-component.…c7825bf6d1a510b4:13 x @ view-model.js?bust=9…c7825bf6d1a510b4:13 je @ view-model.js?bust=9…c7825bf6d1a510b4:13 (anonymous) @ mediator.js?bust=9cc…c7825bf6d1a510b4:13 publish @ core.js?bust=9cc7f11…c7825bf6d1a510b4:13 (anonymous) @ view-model.js?bust=9…c7825bf6d1a510b4:13 Promise.then pe @ view-model.js?bust=9…c7825bf6d1a510b4:13 ot @ view-model.js?bust=9…c7825bf6d1a510b4:13 viewSetup @ form-editor.js?bust=…c7825bf6d1a510b4:16 bootstrap @ form-editor.js?bust=…c7825bf6d1a510b4:16 run @ form-editor.js?bust=…c7825bf6d1a510b4:13 (anonymous) @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 (anonymous) @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 Promise.then (anonymous) @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 Promise.then dispatchFormEditor @ helper.js?bust=9cc7f…c7825bf6d1a510b4:13 (anonymous) @ java-script-item-pro…c7825bf6d1a510b4:13 (anonymous) @ java-script-item-pro…c7825bf6d1a510b4:13 (anonymous) @ java-script-item-pro…c7825bf6d1a510b4:13 Promise.then a @ java-script-item-pro…c7825bf6d1a510b4:13 javaScriptModuleInstruction @ java-script-item-pro…c7825bf6d1a510b4:13 invoke @ java-script-item-pro…c7825bf6d1a510b4:13 (anonymous) @ java-script-item-pro…c7825bf6d1a510b4:13 processItems @ java-script-item-pro…c7825bf6d1a510b4:13 (anonymous) @ java-script-item-handler.js:13 Promise.then (anonymous) @ java-script-item-handler.js:13 ``` This is my form `fileadmin/form_definitions/ads.form.yaml`: ``` renderingOptions: submitButtonLabel: Submit type: Form identifier: ads label: ads xss <img src=x onerror=alert(1)> prototypeName: standard finishers: - options: subject: Test recipients: test@test.com: '' senderAddress: test@test.com senderName: '' addHtmlPart: true attachUploads: true title: '' templateName: 'Test{@format}.html' templateRootPaths: 1708504268: 'EXT:forms_extended/Resources/Private/Emails/Templates' partialRootPaths: 1708504268: 'EXT:forms_extended/Resources/Private/Emails/Partials' identifier: EmailToSender renderables: - renderingOptions: previousButtonLabel: 'Previous step' nextButtonLabel: 'Next step' type: Page identifier: page-1 label: Step renderables: - defaultValue: '' type: Email identifier: email-1 label: 'Email address' validators: - identifier: EmailAddress - properties: options: '': '' elementDescription: asd type: SingleSelect identifier: singleselect-1 label: 'Single select' ``` I'll try to check what is wrong, but wanted to let you know for now.Reply
Thanks for changing to use `lodash`. Although that brings a bit of overhead using another library, we're still better of using this from a security perspective.form-editor.ts:681Since the error is thrown afterwards, it would appear twice in console. Did you mean to put this `console.error` after the if-condition, to only log the "silenced" error?object-utility.ts:58ReplyCode has been removed. Resolved, thanks!object-utility.ts:70ReplyResolved by switching to lodash. -
Benjamin Franzke commented on patch set 8 03/16/26, 10:30
Reply
I've analyzed what wrong here. It is not directly your code (which is fine), but the way jQuery was used before. Please see how `@typo3/form/backend/form-editor/helper.js` is updating the "current" configuration context (which is called repeatedly by all the sub components, whenever they use the "helper"): https://github.com/TYPO3/typo3/blob/b211f9efdbf5e059f6db51eac1985f07a76f4270/Build/Sources/TypeScript/form/backend/form-editor/helper.ts#L82 ``` configuration = $.extend(true, defaultConfiguration, customConfiguration); ``` Now, when we compare that to what is documented: https://api.jquery.com/jQuery.extend/#jQuery-extend-deep-target-object1-objectN > jQuery.extend( [deep ], target, object1 [, objectN ] ) > > *deep* `Type: Boolean` > If true, the merge becomes recursive (aka. deep copy). Passing false for this argument is not supported. > > *target* `Type: Object` > The object to extend. It will receive the new properties. We see that `defaultConfiguration` was not just a *source*, but is always *mutated* with the custom configuration. That means, the resulting configuration was not just returned, but changed the default configuration of `helper.ts`, which means it caused unreliable side effects. This reveals that the `getHelper().getDomElementClassName('sortable')` call in `form-editor/inspector-component.ts` *only* actually works when `form-editor/stage-component.ts` called the helper at least one times before, in order to initialize the `sortable` value in `domElementClassNames`. This case is easy to fix, by adding `sortable: 'sortable'` to the `defaultConfiguration`, but this reveals: *We need to check each and every `getHelper().get*(…)` usage to check if only configuration options of the current component are used* -
Josua Vogel uploaded patch set 9
V +103/16/26, 11:07 -
core-ci voted on patch set 9 V +1 03/16/26, 11:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98008
-
Benjamin Franzke commented on patch set 9 CR -1 V +1 03/16/26, 11:33
Reply
sorry, I'll block for a moment, to check the other usages (will try to rewrite them to use `keyof …` in order to statically check for valid arguments in a patch that that could be applied additionally to this one) -
Benjamin Franzke commented on patch set 9 CR +1 03/16/26, 12:52
Reply
Found no additional missing key. I think we're good to go now. -
Benjamin Kott voted on patch set 9 CR +1 V +1 03/16/26, 14:12
-
Benjamin Franzke voted on patch set 9 CR +2 V +2 03/16/26, 14:12
-
Benjamin Franzke merged patch set 10 03/16/26, 14:12