From f3acec538f3dd47e431356b58941322d7bf10db2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 23 Apr 2021 10:28:15 +0200 Subject: [PATCH] scripting: prevent crash (built-in client only) when using the variable `navigator` --- CHANGELOG.md | 1 + src/client/ui/ui-console.js | 3 ++- src/client/widgets/vm.js | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab6bf46a..e135246c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - button: allow writing strings like `"1.0"` in `label` without removing the decimals - editor: use css variable `--grid-width` at startup and after disabling & enabling the grid - launcher: regression preventing server halt when built-in client is closed manually beforehand + - scripting: prevent crash (built-in client only) when using the variable `navigator` - widgets - menu/switch/dropdown: reset value to `undefined` when receiving a value that's not defined in `values` diff --git a/src/client/ui/ui-console.js b/src/client/ui/ui-console.js index ddccd1e6..ad27506f 100644 --- a/src/client/ui/ui-console.js +++ b/src/client/ui/ui-console.js @@ -54,7 +54,8 @@ class UiConsole extends UiSidePanel { this.script = new Script({props:{ id: 'CONSOLE', - script: 'return eval(value)', + // detached context++ reading global navigator == crash electron + script: 'var navigator; return eval(value)', event: 'value' }, parent: widgetManager}) this.script._not_editable = true diff --git a/src/client/widgets/vm.js b/src/client/widgets/vm.js index 08416986..7e0a6155 100644 --- a/src/client/widgets/vm.js +++ b/src/client/widgets/vm.js @@ -90,6 +90,11 @@ class Vm { contextKeys = ['__VARS'], contextValues = [{}] + // detached context + reading global navigator == crash electron + if (code.indexOf('navigator') !== -1) { + contextInit += 'var navigator;' + } + if (defaultContext) { for (var k in defaultContext) { contextInit += `var ${k} = ${k} === undefined ? ${JSON.stringify(defaultContext[k])} : ${k};`