build: ship client script as esm, drop ios 10.3 and lift some protections in user scripts

This commit is contained in:
jean-emmanuel 2025-09-13 15:38:56 +02:00
parent 12bf4db1b6
commit 283c340f16
8 changed files with 19 additions and 67 deletions

View file

@ -1,12 +0,0 @@
{
"presets": [
["@babel/env", {
"targets": {
"ios": "10.3",
"chrome": "60"
},
"useBuiltIns": "usage",
"corejs": 3
}]
]
}

View file

@ -8,7 +8,13 @@
- widgets
- the html property is no longer restricted / sanitized
- input/textarea/select no longer have their appearance property reset in custom html
- canvas: added `contextType` property
- scripting
- user scripts are longer protected against infinite loop and the main window object may be reached (it's not supported to break out of scripting context, but resources are no longer wasted to prevent it)
- breaking change
- dropped support for iOS 10.3
## 1.29.8

View file

@ -14,13 +14,12 @@ module.exports = {
input: 'src/client/index.mjs',
output: [
{
file: 'app/client/index.js',
inlineDynamicImports: true,
format: 'iife',
dir: 'app/client/',
hoistTransitiveImports:true,
chunkFileNames: `[name]-${package.version}.js`,
entryFileNames: `[name]-${package.version}.js`,
format: 'es',
sourcemap: true,
strict: false,
indent: false,
name: '_'
},
],
treeshake: false,
@ -44,8 +43,8 @@ module.exports = {
'@babel/preset-env',
{
targets: {
ios: '10.3',
chrome: '60'
ios: '11',
chrome: '61'
},
useBuiltIns: 'usage',
corejs: 3,

View file

@ -591,7 +591,6 @@ class ScriptVm extends Vm {
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'cthislearTimeout', 'setFocus', 'unfocus' , 'setFocusable', 'setScroll', 'getScroll', 'toolbar',
'openUrl', 'getVar', 'setVar', 'runAs', 'reload', 'Image', 'updateCanvas', 'getNavigator', 'browseFile']) {
this.sanitize(this.sandbox.contentWindow[imports])
this.globals[imports] = true
}

View file

@ -1,4 +1,3 @@
import loopProtect from 'loop-protect'
import {deepCopy} from '../utils.mjs'
var sessionManager
@ -50,13 +49,6 @@ class Vm {
this.sandbox.contentWindow.document.write('<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'unsafe-eval\';">')
this.sandbox.contentWindow.document.close()
// init infinite loop guard
loopProtect.alias = '__protect'
loopProtect.hit = function(line){
throw 'Potential infinite loop found on line ' + line + '(script interrupted).\nAdd "// noprotect" to your code to disable loop protection.'
}
this.sandbox.contentWindow.__protect = loopProtect
// global context
this.registerGlobals()
@ -94,32 +86,6 @@ class Vm {
}
this.sandbox.contentWindow.globals = globals
// sanitize globals
for (var imports of ['__protect', 'console', 'setTimeout', 'setInterval', 'globals']) {
this.sanitize(this.sandbox.contentWindow[imports])
}
}
sanitize(object) {
// non-primitives created outside the sandbox context can leak
// the host window object... let's nuke that !
// (we only nuke functions and objects/arrays because we don't pass anything else)
var t = typeof o
if (t === 'function' || (t === 'object' && o !== null)) {
if (o.__proto__) {
if (t === 'function') {
o.__proto__.constructor = this.safeFunctionProto
} else {
o.__proto__.constructor.constructor = this.safeFunctionProto
}
}
for (var k in o) {
this.sanitize(o[k])
}
}
}
compile(code, defaultContext) {
@ -127,7 +93,7 @@ class Vm {
if (typeof code !== 'string') code = String(code)
// var contextInit = 'var locals = locals;',
var contextInit = '',
var contextInit = '"use strict";',
contextKeys = ['__VARS'],
contextValues = [{}]
@ -144,13 +110,9 @@ class Vm {
}
}
var compiledCode = new this.safeFunctionProto(
...contextKeys, 'locals',
loopProtect('"use strict";' + contextInit + code)
.replace(/;\n(if \(__protect.*break;)\n/g, ';$1') // prevent loop protect from breaking stack linenumber
.replace(/(VAR_[0-9]+)/g, '__VARS.$1')
)
code = contextInit + code.replace(/(VAR_[0-9]+)/g, '__VARS.$1')
var compiledCode = new this.safeFunctionProto(...contextKeys, 'locals', code)
return (context, locals)=>{
@ -167,8 +129,6 @@ class Vm {
__contextValues.push(locals)
this.sanitize(__contextValues)
return compiledCode.apply('this', __contextValues)
}

View file

@ -1,5 +1,5 @@
// Dirty browser window shim
import * as DOM from '../client/dom'
import * as DOM from '../client/dom.mjs'
// eslint-disable-next-line no-global-assign
document = {

View file

@ -15,7 +15,7 @@
<link rel="stylesheet" type="text/css" href="/assets/fonts/roboto.css?__OSC_ASSET__=1&version=${version}"/>
<link rel="shortcut icon" href="/assets/favicon.png?__OSC_ASSET__=1&version=${version}"/>
<script src="/client/ace/ace.js?__OSC_ASSET__=1&version=${version}"></script>
<script defer src="/client/index.js?__OSC_ASSET__=1&version=${version}"></script>
<script type="module" defer src="/client/index-${version}.js"></script>
</head>
<body class="editor-disabled" spellcheck="false">

View file

@ -163,7 +163,7 @@ class WebServer extends EventEmitter {
if (
url.indexOf('__OSC_ASSET__=1') != -1 ||
url.indexOf('open-stage-control-client.js.map') != -1 ||
url.indexOf('/client/ace/') != -1
url.indexOf('/client/') == 0
) {
// osc asset files