medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
439 stars 210 forks source link

Crash in enketo-core - TypeError: Cannot read property 'length' of undefined #8102

Closed kennsippell closed 10 months ago

kennsippell commented 1 year ago
  "info": {
    "stack": "TypeError: Cannot read property 'length' of undefined
    at Object._isNotPrintableKey (https://disc-mali.ml/main.js?_sw-precache=8f55ed87ae50fe146c589063bf3860e3:1:1304311)
    at HTMLFormElement.<anonymous> (https://disc-mali.ml/main.js?_sw-precache=8f55ed87ae50fe146c589063bf3860e3:1:1303639)
    at R.value (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:25487)
    at Object.onInvokeTask (https://disc-mali.ml/main.js?_sw-precache=8f55ed87ae50fe146c589063bf3860e3:1:2387800)
    at R.value (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:25408)
    at R.value (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:19663)
    at R.value [as invoke] (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:27446)
    at W (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:40372)
    at re (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:40764)
    at HTMLFormElement.ue (https://disc-mali.ml/polyfills.js?_sw-precache=c733963449ad3697030f3b3aed9c299e:1:40962)",
    "message": "Cannot read property 'length' of undefined"
  },

The function _isNotPrintableKey from top of stack is (was?) present in enketo-core https://github.com/enketo/enketo-core/blob/827c1f30a62d7e8a9093f7c9b1dac7b2b54151b4/src/js/mask.js#L41

2 instances of this in production moh-mali-chw running cht-core 4.0.1 cc @jkuester

garethbowen commented 1 year ago

It looks like that code was moved in this commit: https://github.com/enketo/enketo-core/commit/fd21204caab56250c70c08de698f82a693480179

Which means essentially the same code still exists in master: https://github.com/enketo/enketo-core/blob/030497118b2fc90a1aed94c2758298ede026147c/src/widget/number-input/number-input.js#L157

I can see some reports that the key is undefined on keydown events on mobile but if that were the case I would expect this error to be much more widespread.

@kennsippell Has anyone been able to reproduce the error? I'm particularly interested in if this is severe (eg: user cannot complete the form) or if it's just generating the feedback doc in the background.

kennsippell commented 1 year ago

Here is some more info about severity:

garethbowen commented 1 year ago

The error looks like a keydown event is being fired without an event.key property (stating the obvious...). This value can be undefined if the key can't be identified: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

It's possible your e2e test is sending an invalid or unusual key press to the input which the browser doesn't know causing this issue. This would make it less likely but not impossible to reproduce in a real browser.

Enketo core should be updated to protect against this.

garethbowen commented 1 year ago

Issue raised upstream: enketo/enketo#34

garethbowen commented 1 year ago

The upstream issue is fixed and released in enketo-core v7.2.4.

garethbowen commented 1 year ago

Leaving this open until we update enketo-core.

mrjones-plip commented 10 months ago

Enketo has been uplifted and I noted that:

confirm the upgrade fixes the bugs mentioned in cht-core#8102

Closing!