scriptable 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +5 -1
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.github/workflows/release.yml +0 -62
- package/CHANGELOG.md +0 -42
- package/SECURITY_FIXES.md +0 -81
- package/scripts/release.js +0 -127
- package/src/__tests__/audit-followups.test.ts +0 -206
- package/src/__tests__/break-out.test.ts +0 -43
- package/src/__tests__/builtin-functions-date.test.ts +0 -75
- package/src/__tests__/builtin-functions.test.ts +0 -56
- package/src/__tests__/expressions.test.ts +0 -13
- package/src/__tests__/functions.test.ts +0 -81
- package/src/__tests__/logic.test.ts +0 -54
- package/src/__tests__/new-features.test.ts +0 -158
- package/src/__tests__/security.test.ts +0 -790
- package/src/__tests__/semantic-fixes.test.ts +0 -171
- package/src/__tests__/variables.test.ts +0 -200
- package/src/binary-ops.ts +0 -18
- package/src/builtin-functions.ts +0 -177
- package/src/environment.ts +0 -192
- package/src/evaluate.ts +0 -414
- package/src/index.ts +0 -83
- package/tsconfig.json +0 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jason Galea
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scriptable",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/lecstor/scriptable.git"
|
|
18
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"acorn": "^8.14.1"
|
|
21
24
|
},
|
|
@@ -25,6 +28,7 @@
|
|
|
25
28
|
"vitest": "^4.1.4"
|
|
26
29
|
},
|
|
27
30
|
"scripts": {
|
|
31
|
+
"prebuild": "rm -rf dist",
|
|
28
32
|
"build": "tsc",
|
|
29
33
|
"test": "vitest run",
|
|
30
34
|
"test:watch": "vitest",
|
package/.changeset/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# Changesets
|
|
2
|
-
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
-
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
|
|
6
|
-
|
|
7
|
-
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
-
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).
|
package/.changeset/config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@3.1.3/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": false,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "public",
|
|
8
|
-
"baseBranch": "main",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
name: release
|
|
2
|
-
|
|
3
|
-
# Publishes to npm via OIDC trusted publishing — no NPM_TOKEN secret.
|
|
4
|
-
#
|
|
5
|
-
# Triggered by pushing an annotated tag like `v0.1.1`. The local `pnpm release`
|
|
6
|
-
# script handles versioning, committing, tagging, and pushing — the tag push
|
|
7
|
-
# is what starts this workflow.
|
|
8
|
-
#
|
|
9
|
-
# If this workflow file is renamed, update the matching Trusted Publisher
|
|
10
|
-
# config at https://www.npmjs.com/package/scriptable/access — the
|
|
11
|
-
# "Workflow filename" field takes the basename only (e.g. `release.yml`).
|
|
12
|
-
|
|
13
|
-
on:
|
|
14
|
-
push:
|
|
15
|
-
tags:
|
|
16
|
-
- "v*"
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
publish:
|
|
20
|
-
runs-on: ubuntu-latest
|
|
21
|
-
permissions:
|
|
22
|
-
# id-token: write is required for OIDC trusted publishing to npm.
|
|
23
|
-
# This lets `changeset publish` exchange a short-lived GitHub Actions
|
|
24
|
-
# token for an npm publish token — no long-lived NPM_TOKEN secret
|
|
25
|
-
# ever exists in this repo.
|
|
26
|
-
id-token: write
|
|
27
|
-
contents: read
|
|
28
|
-
|
|
29
|
-
steps:
|
|
30
|
-
- uses: actions/checkout@v6
|
|
31
|
-
|
|
32
|
-
- uses: pnpm/action-setup@v5
|
|
33
|
-
with:
|
|
34
|
-
version: 10
|
|
35
|
-
|
|
36
|
-
# Node 24, NOT 22. npm trusted publishing requires npm >= 11.5.1, and
|
|
37
|
-
# Node 22 LTS is permanently stuck on npm 10.9.x.
|
|
38
|
-
- uses: actions/setup-node@v6
|
|
39
|
-
with:
|
|
40
|
-
node-version: 24
|
|
41
|
-
registry-url: https://registry.npmjs.org
|
|
42
|
-
cache: pnpm
|
|
43
|
-
|
|
44
|
-
- name: Install dependencies
|
|
45
|
-
run: pnpm install --frozen-lockfile --ignore-scripts
|
|
46
|
-
|
|
47
|
-
- name: Test
|
|
48
|
-
run: pnpm test
|
|
49
|
-
|
|
50
|
-
- name: Build
|
|
51
|
-
run: pnpm build
|
|
52
|
-
|
|
53
|
-
# --no-git-tag: the tag already exists (we pushed it from the
|
|
54
|
-
# maintainer's laptop — that tag push is what triggered this
|
|
55
|
-
# workflow), so skip changesets' tag creation step.
|
|
56
|
-
# NPM_CONFIG_PROVENANCE=true: stamps the package with an npm
|
|
57
|
-
# provenance attestation so the npmjs.com page shows "Built
|
|
58
|
-
# and signed on GitHub Actions".
|
|
59
|
-
- name: Publish to npm
|
|
60
|
-
run: pnpm exec changeset publish --no-git-tag
|
|
61
|
-
env:
|
|
62
|
-
NPM_CONFIG_PROVENANCE: "true"
|
package/CHANGELOG.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# scriptable
|
|
2
|
-
|
|
3
|
-
## 0.2.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 3fcb7fc: Add `maxAllocSize` option to `runner()` (default 1,000,000). Caps the length of any string or array value produced during a run. Without this bound, exponential growth from string concat (`s = s + s`), template literals, or `concat()` stayed well within the step budget — 26 doublings from an 8-char seed could allocate ~512 MiB. Array spread now also enforces projected length before growing, using a loop instead of `push(...spread)` so enforcement fires at `maxAllocSize` rather than V8's ~65K argument-stack ceiling. Set to `0` to disable.
|
|
8
|
-
- ae442ce: Add `maxCodeSize` option to `runner()` (default 64 KiB). The step counter bounds execution but not parsing — acorn still reads multi-megabyte input before the interpreter sees it, which is ~200ms of CPU per 50 MB on a modern machine. Sources over the limit now throw before `acorn.parse` is called. Set to `0` to disable.
|
|
9
|
-
|
|
10
|
-
### Patch Changes
|
|
11
|
-
|
|
12
|
-
- ed90a55: Address the remaining findings from the v0.1.1 security audit:
|
|
13
|
-
|
|
14
|
-
- **Computed keys with literal dots are preserved** (audit #4). `evalAsPath` now returns `string[]` segments instead of a dotted string, so `a["x.y"] = 1` stores under the literal key `"x.y"` rather than being silently re-split into `a.x.y` by `deepSet`. Read and write are now consistent. The change is internal — `evalAsPath` and the `Environment` get/set/def/defined methods now take `string[]`; the public `runner` API is unchanged.
|
|
15
|
-
- **Dotted paths resolve through parent scope** (audit #5). `deepHas`/`deepGet` used `hasOwnProperty` on every segment, but `env.vars = Object.create(parent.vars)` makes outer-scope variables visible only via the prototype chain — so `obj.method()` inside a nested function threw `"obj.method is not a function"` whenever `obj` lived in an enclosing scope. First segment now uses `in` (walks the chain); subsequent segments still use `hasOwn` so user-land objects can't leak `Object.prototype` members through the lookup.
|
|
16
|
-
- **`maxAllocSize` now bounds object key count** (audit #7). Previously only strings and arrays were size-checked, so `reduce(arr, (acc, k) => ({...acc, [k]: k}), {})` could grow an accumulator to `maxSteps` keys without tripping any cap. `ObjectExpression` now projects `ownCount + (spread ? spread.keys : 1)` against `maxAllocSize` before each write.
|
|
17
|
-
- **New `options.maxDurationMs`** bounds wall-clock time per run (audit #6). The step counter only increments inside `evaluate()`, so long native builtin calls (`sort` on a 1M-element array ≈ 1.7s) run uninterrupted. The deadline is checked in `Runtime.step()` between interpreter steps — a single long native call can overshoot by up to its own duration, but subsequent work is rejected. Defaults to `0` (disabled); opt in for hostile multi-tenant workloads.
|
|
18
|
-
|
|
19
|
-
- 4548bd1: Block `__proto__`, `constructor`, `prototype`, and the legacy descriptor methods as keys in object literals (`{ "__proto__": … }`, `{ [expr]: … }`, shorthand, and spread). Previously user code could set the prototype of a fresh object via literal `__proto__` and emit booby-trapped "constructor" own properties that would ride along when the caller merged `env.vars` into a host object. Also fixes `{[identifier]: value}` — the computed key now evaluates to the identifier's value instead of the literal name.
|
|
20
|
-
- b950626: Fix computed member access on the LHS of assignments and on call targets. Previously `a[k] = v` wrote to a property named `k` (the identifier name) instead of the property named by the _value_ of `k`; the same bug affected dotted-path resolution of call targets. The LHS and callee resolver now evaluates the key of a computed member (`a[expr]`) in the current environment, and rejects runtime-resolved blocked keys (`k = "constructor"; a[k] = …`). CallExpression now also handles dynamic callees (e.g. `f()()`, `((x) => x)(v)`) by evaluating the callee as a value when it isn't a static path.
|
|
21
|
-
- ed90a55: Harden builtin lookup and fix two long-standing semantic bugs surfaced by a security audit:
|
|
22
|
-
|
|
23
|
-
- `CallExpression` now resolves builtins with `hasOwn` instead of `functions[name]`. A plain-object `functions` map inherits from `Object.prototype`, so `constructor()` previously resolved to `Object` and returned `{}`, `toString()` resolved to `Object.prototype.toString`, etc. Not directly exploitable (blocked property access on the returned wrappers still threw) but a defense-in-depth gap that vanished the moment a builtin name collided with an `Object.prototype` member.
|
|
24
|
-
- `LogicalExpression` now short-circuits. `a || b` and `a && b` used to eagerly evaluate both sides, so `guard && action()` always ran `action()`. `??` is also supported.
|
|
25
|
-
- `AssignmentExpression` now honours its operator. `a += 1` used to silently behave as `a = 1`; compound ops (`+=`, `-=`, `*=`, `/=`, `%=`, `||=`, `&&=`, `??=`) now read-combine-write, with the logical compounds short-circuiting. The LHS still goes through the blocked-property checks.
|
|
26
|
-
|
|
27
|
-
- 9b3897a: Fix `return` statements nested inside `if` (or any other non-`ReturnStatement` node) so they correctly short-circuit the enclosing function body. Previously `BlockStatement` only broke its iteration loop when the _immediate_ statement was a `ReturnStatement`, so `function f(n) { if (n == 0) return 1; … }` would evaluate the guarded return but then continue executing the statements after the `if`. `ReturnStatement` now throws a `ReturnValue` sentinel that unwinds to the nearest function boundary (`makeFunc`), which is the standard control-flow mechanism for tree-walking interpreters. This also unblocks idiomatic recursive functions that use a guard-then-recurse pattern.
|
|
28
|
-
- 0cea1d6: Give each function invocation its own scope. `makeFunc` previously hoisted `const scope = env.extend()` to closure-creation time and reused it for every call, so a recursive call overwrote the caller's params (and any `let`/`const` set on the function scope). Moved the `env.extend()` inside the returned closure so every call gets a fresh child of the captured lexical parent.
|
|
29
|
-
- 0fbe14e: Move execution step counter from module-global state onto a per-run `Runtime` carried by `Environment`. Previously, a synchronously re-entrant run (e.g. a caller-injected function that itself invokes the interpreter) would reset the shared counter and silently bypass the outer run's `maxSteps` budget. Each run now owns its own step state.
|
|
30
|
-
|
|
31
|
-
## 0.1.1
|
|
32
|
-
|
|
33
|
-
### Patch Changes
|
|
34
|
-
|
|
35
|
-
- e243ccb: Releases are now published from GitHub Actions via npm OIDC trusted publishing. Each published artifact carries an npm provenance attestation, and no `NPM_TOKEN` secret is stored anywhere.
|
|
36
|
-
|
|
37
|
-
## 0.1.0
|
|
38
|
-
|
|
39
|
-
### Minor Changes
|
|
40
|
-
|
|
41
|
-
- Rewritten in TypeScript, using the `acorn` parser. All legacy runtime dependencies have been dropped.
|
|
42
|
-
- Hardened the sandbox: fixed a set of sandbox-escape and prototype-pollution vectors, and added DoS protections (execution limits) so runaway scripts can no longer lock up the host process.
|
package/SECURITY_FIXES.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# Security Audit — scriptable@0.1.1
|
|
2
|
-
|
|
3
|
-
## Scope
|
|
4
|
-
|
|
5
|
-
`scriptable` is a sandboxed JavaScript expression evaluator. User code is parsed by `acorn` into an AST and executed by a tree-walking interpreter in `src/evaluate.ts`. The audit covered the interpreter surface, the environment/scope implementation, builtin functions, and the dependency tree.
|
|
6
|
-
|
|
7
|
-
## Audit findings
|
|
8
|
-
|
|
9
|
-
### Code-injection sinks (eval / new Function / child_process)
|
|
10
|
-
|
|
11
|
-
**None present.** `rg "\beval\b|new Function|child_process|execSync"` across `src/` matches only identifiers inside *user-supplied script strings in tests* (e.g. `eval("1+1")` as an attacker payload, which the sandbox correctly rejects with `"eval is not a function"`). The interpreter never lowers user code into the host's `eval` or `Function` — it walks the acorn AST directly.
|
|
12
|
-
|
|
13
|
-
> Explicit non-change: **did not introduce `vm2`.** `vm2` was deprecated in 2023 after multiple unfixable sandbox-escape CVEs (GHSA-ch3r-j5x3-6q2m, GHSA-g644-9gfx-q4q4, GHSA-cchq-frhr-rjg8). Swapping the current AST-walker for `vm2` would be a security regression, not a mitigation. The existing "interpret the AST, never hand a string to the host runtime" design is strictly safer than any `vm`-module–based sandbox.
|
|
14
|
-
|
|
15
|
-
### Prototype pollution / sandbox escape
|
|
16
|
-
|
|
17
|
-
Already hardened. `BLOCKED_PROPS = {constructor, __proto__, prototype, __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__}` is enforced in four places:
|
|
18
|
-
|
|
19
|
-
1. `evaluate.ts` `MemberExpression` — blocks `a.constructor`, `a["__proto__"]`, and variable-indirected forms (`k = "constructor"; a[k]`).
|
|
20
|
-
2. `evaluate.ts` `evalAsPath` — blocks the same names on assignment LHS and call callees (`a.__proto__ = x`, `a.constructor(...)`).
|
|
21
|
-
3. `evaluate.ts` `ObjectExpression` — rejects blocked keys as object-literal keys (static, computed, and shorthand), so `{__proto__: {...}}` cannot set the prototype of a fresh literal; spreads drop blocked own-keys by manual copy (not `Object.assign`, which invokes the `__proto__` setter).
|
|
22
|
-
4. `environment.ts` `assertSafeParts` — `deepHas` / `deepGet` / `deepSet` re-check every segment so nothing slips through a deep path.
|
|
23
|
-
|
|
24
|
-
Host-provided `env` values flow through the same sandbox (`env.constructor` still throws). 84 tests in `security.test.ts` plus 17 in `audit-followups.test.ts` cover these paths.
|
|
25
|
-
|
|
26
|
-
### Forbidden language surface
|
|
27
|
-
|
|
28
|
-
`ThisExpression`, `NewExpression`, `ImportExpression`, and `arguments` have no `evals[...]` handler, so they throw `"Cannot evaluate <Type>"` or `"<name> is not defined"` — i.e. `eval`, `Function`, `require`, `process`, `globalThis`, and `import()` are all unreachable.
|
|
29
|
-
|
|
30
|
-
### DoS controls (per-run limits)
|
|
31
|
-
|
|
32
|
-
Already in place via `Runtime`:
|
|
33
|
-
|
|
34
|
-
- `maxSteps` (default 100 000) — interpreter step budget, checked every `evaluate()`.
|
|
35
|
-
- `maxCodeSize` (default 64 KiB) — bounds parser work before acorn runs.
|
|
36
|
-
- `maxAllocSize` (default 1 000 000) — bounds string length, array length, and object own-key count; checked on every value returned from a handler and projected before array/spread growth to trip before V8's 65 K argument-stack limit.
|
|
37
|
-
- `maxDurationMs` (default 0, opt-in) — wall-clock deadline checked between steps; guards against long native builtin calls (`sort` on 1M-element array) that don't advance the step counter.
|
|
38
|
-
|
|
39
|
-
Counters live on a per-run `Runtime` instance (not a module global), so re-entrant runs (`runInner` callback pattern) can't leak budget between caller and callee — regression test at `security.test.ts:297`.
|
|
40
|
-
|
|
41
|
-
### Dependencies
|
|
42
|
-
|
|
43
|
-
`pnpm audit` reported:
|
|
44
|
-
|
|
45
|
-
| Severity | Package | Advisory |
|
|
46
|
-
|----------|---------|----------|
|
|
47
|
-
| high | vite (transitive via vitest) | [GHSA-v2wj-q39q-566r](https://github.com/advisories/GHSA-v2wj-q39q-566r) — `server.fs.deny` bypass |
|
|
48
|
-
| high | vite | [GHSA-p9ff-h696-f583](https://github.com/advisories/GHSA-p9ff-h696-f583) — arbitrary file read via dev-server WebSocket |
|
|
49
|
-
| moderate | vite | [GHSA-4w7w-66w2-5vf9](https://github.com/advisories/GHSA-4w7w-66w2-5vf9) — path traversal in optimized deps |
|
|
50
|
-
|
|
51
|
-
All three are **dev-dependency-only** (vitest's test-runner dev-server) and do not ship to consumers of `@lecstor/scriptable`. Runtime dep is only `acorn@^8.14.1`, which has no open advisories.
|
|
52
|
-
|
|
53
|
-
## Changes made
|
|
54
|
-
|
|
55
|
-
### 1. `package.json` — update vitest and pin vite to a patched version
|
|
56
|
-
|
|
57
|
-
```diff
|
|
58
|
-
- "vitest": "^3.1.0"
|
|
59
|
-
+ "vitest": "^4.1.4"
|
|
60
|
-
+ "pnpm": { "overrides": { "vite": "^7.3.2" } }
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
- Bumped `vitest` 3.2.4 → 4.1.4.
|
|
64
|
-
- Added a `pnpm.overrides` entry forcing `vite` to ≥ 7.3.2 (earliest version patched for all three advisories). `vitest@4.1.4`'s peer resolves to `vite@7.3.1`, which is still vulnerable; the override pulls 7.3.2+ without breaking the peer range.
|
|
65
|
-
- Regenerated `pnpm-lock.yaml`; `pnpm audit` now reports **"No known vulnerabilities found"**.
|
|
66
|
-
|
|
67
|
-
### 2. Validation
|
|
68
|
-
|
|
69
|
-
All 198 existing tests pass on the updated toolchain (`pnpm test`), including the 101 security/audit-followup tests exercising prototype-chain blocks, `__proto__` handling, deep-path pollution, DoS caps, and re-entrance isolation.
|
|
70
|
-
|
|
71
|
-
## Items considered and deliberately not changed
|
|
72
|
-
|
|
73
|
-
- **`var` in `src/`** — the only occurrence is `if (exp.kind === "var")` in `evaluate.ts:379`, where the interpreter handles the `var` keyword from *user scripts*. No TypeScript source uses `var` itself.
|
|
74
|
-
- **CSP / strict headers** — not applicable. `scriptable` is a library, not a server; it emits no HTTP responses. A CSP would belong to the embedder, not the library.
|
|
75
|
-
- **"Use strict"** — `type: "module"` in `package.json` makes every `src/*.ts` implicit strict mode; adding `"use strict"` directives would be dead code.
|
|
76
|
-
- **Replacing the AST walker with `vm2` / `vm` / `isolated-vm`** — see note above. The current design is strictly safer than `vm2` and does not require a native addon the way `isolated-vm` does.
|
|
77
|
-
|
|
78
|
-
## Residual risk
|
|
79
|
-
|
|
80
|
-
- Host-provided builtins (`functions` map) and host-provided `env` values run with full host privilege. A caller that passes `{ fs }` into `env` has voluntarily handed the sandbox a filesystem. This is by design and documented in the README; the sandbox only guarantees that the *script text* cannot reach host capabilities it was not explicitly given.
|
|
81
|
-
- `maxDurationMs` defaults to `0` (disabled). Single-tenant callers running trusted templates don't need it; multi-tenant hostile workloads should opt in.
|
package/scripts/release.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Release a new version end-to-end.
|
|
4
|
-
*
|
|
5
|
-
* Guards:
|
|
6
|
-
* 1. Refuses to run on a dirty tree.
|
|
7
|
-
* 2. Refuses to run off main.
|
|
8
|
-
* 3. Refuses to run if local main is behind origin/main (fetches first).
|
|
9
|
-
* 4. Refuses to run with no pending changesets.
|
|
10
|
-
*
|
|
11
|
-
* Steps:
|
|
12
|
-
* 5. Runs tests + build as a safety gate.
|
|
13
|
-
* 6. Consumes changesets to bump package.json + CHANGELOG.md.
|
|
14
|
-
* 7. Commits the result as "Version X.Y.Z".
|
|
15
|
-
* 8. Shows the commit and prompts for confirmation.
|
|
16
|
-
* 9. On confirm: pushes main, creates the vX.Y.Z annotated tag,
|
|
17
|
-
* pushes the tag. The tag push triggers .github/workflows/release.yml,
|
|
18
|
-
* which publishes to npm via OIDC (with provenance).
|
|
19
|
-
* 10. On abort: prints instructions to undo the version commit and exits 1.
|
|
20
|
-
*
|
|
21
|
-
* There is deliberately only one user-facing pnpm script (`pnpm release`) —
|
|
22
|
-
* the interactive prompt at step 8 is the abort window. Everything before
|
|
23
|
-
* the prompt is local-only and reversible with `git reset --hard HEAD^`.
|
|
24
|
-
*/
|
|
25
|
-
import { execSync } from "node:child_process";
|
|
26
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
27
|
-
import { createInterface } from "node:readline/promises";
|
|
28
|
-
import { stdin, stdout } from "node:process";
|
|
29
|
-
|
|
30
|
-
function run(cmd) {
|
|
31
|
-
execSync(cmd, { stdio: "inherit" });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function capture(cmd) {
|
|
35
|
-
return execSync(cmd, { encoding: "utf-8" }).trim();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function fail(msg) {
|
|
39
|
-
console.error(`release: ${msg}`);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function prompt(question) {
|
|
44
|
-
const rl = createInterface({ input: stdin, output: stdout });
|
|
45
|
-
try {
|
|
46
|
-
return (await rl.question(question)).trim().toLowerCase();
|
|
47
|
-
} finally {
|
|
48
|
-
rl.close();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 1. Clean tree check.
|
|
53
|
-
if (capture("git status --porcelain")) {
|
|
54
|
-
fail("working tree is not clean — commit or stash first.");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 2. On main?
|
|
58
|
-
const branch = capture("git rev-parse --abbrev-ref HEAD");
|
|
59
|
-
if (branch !== "main") {
|
|
60
|
-
fail(`not on main branch (currently on ${branch}).`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 3. Up-to-date check.
|
|
64
|
-
run("git fetch origin main");
|
|
65
|
-
const localMain = capture("git rev-parse main");
|
|
66
|
-
const remoteMain = capture("git rev-parse origin/main");
|
|
67
|
-
if (localMain !== remoteMain) {
|
|
68
|
-
const behind = capture(`git rev-list --count ${localMain}..${remoteMain}`);
|
|
69
|
-
if (behind !== "0") {
|
|
70
|
-
fail(`local main is ${behind} commit(s) behind origin/main — pull first.`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 4. Pending changeset check.
|
|
75
|
-
const pending = readdirSync(".changeset").filter(
|
|
76
|
-
(f) => f.endsWith(".md") && f.toLowerCase() !== "readme.md",
|
|
77
|
-
);
|
|
78
|
-
if (pending.length === 0) {
|
|
79
|
-
fail("no pending changesets — run `pnpm changeset` first.");
|
|
80
|
-
}
|
|
81
|
-
console.log(
|
|
82
|
-
`Found ${pending.length} pending changeset(s): ${pending.join(", ")}\n`,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// 5. Safety gate.
|
|
86
|
-
run("pnpm test");
|
|
87
|
-
run("pnpm build");
|
|
88
|
-
|
|
89
|
-
// 6. Consume changesets → bump package.json + CHANGELOG.md.
|
|
90
|
-
run("pnpm exec changeset version");
|
|
91
|
-
|
|
92
|
-
// 7. Commit. Stage only the files changeset version touches.
|
|
93
|
-
const { version } = JSON.parse(readFileSync("./package.json", "utf-8"));
|
|
94
|
-
run("git add package.json CHANGELOG.md .changeset");
|
|
95
|
-
run(`git commit -m "Version ${version}"`);
|
|
96
|
-
|
|
97
|
-
// 8. Show the commit and prompt.
|
|
98
|
-
console.log("");
|
|
99
|
-
run("git --no-pager show HEAD --stat");
|
|
100
|
-
console.log("");
|
|
101
|
-
console.log("-".repeat(60));
|
|
102
|
-
console.log(` About to release scriptable v${version}`);
|
|
103
|
-
console.log("-".repeat(60));
|
|
104
|
-
console.log(` Next: push main, create tag v${version}, push tag`);
|
|
105
|
-
console.log(" -> tag push triggers .github/workflows/release.yml");
|
|
106
|
-
console.log(" -> CI publishes to npm via OIDC (with provenance)");
|
|
107
|
-
console.log("");
|
|
108
|
-
console.log(" This is your last chance to abort. Once the tag is pushed,");
|
|
109
|
-
console.log(" publishing happens automatically.");
|
|
110
|
-
console.log("");
|
|
111
|
-
const answer = await prompt("Proceed? [y/N] ");
|
|
112
|
-
|
|
113
|
-
if (answer !== "y" && answer !== "yes") {
|
|
114
|
-
console.log("\nAborted. To undo the version commit locally:");
|
|
115
|
-
console.log(" git reset --hard HEAD^");
|
|
116
|
-
console.log(" # your .changeset files will come back from the reset");
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 9. Push main, tag, push tag.
|
|
121
|
-
run("git push origin main");
|
|
122
|
-
run("pnpm exec changeset tag");
|
|
123
|
-
run("git push --follow-tags");
|
|
124
|
-
|
|
125
|
-
console.log(`\nv${version} tag pushed.`);
|
|
126
|
-
console.log(` https://github.com/lecstor/scriptable/actions`);
|
|
127
|
-
console.log(` The release workflow will publish to npm shortly.`);
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import runner from "../index.js";
|
|
3
|
-
|
|
4
|
-
// Regressions for four additional findings from the v0.1.1 audit that were
|
|
5
|
-
// deferred until after the initial hardening pass. See
|
|
6
|
-
// `.changeset/audit-followups.md` for narrative context.
|
|
7
|
-
|
|
8
|
-
describe("Finding 4 — literal-dot keys survive the path refactor", () => {
|
|
9
|
-
// Pre-fix, evalAsPath built a dotted string ("a.x.y"), so a key like
|
|
10
|
-
// `a["x.y"]` was split by deepSet into `a.x.y` on write but read back via
|
|
11
|
-
// a flat `obj["x.y"]` lookup — silent inconsistency. Post-fix, paths are
|
|
12
|
-
// string[] segments and dots inside a segment stay literal.
|
|
13
|
-
const run = runner();
|
|
14
|
-
|
|
15
|
-
it("a['x.y'] = 1 stores under the literal key 'x.y'", () => {
|
|
16
|
-
const { env } = run(`a = {}; a["x.y"] = 1;`);
|
|
17
|
-
expect(Object.prototype.hasOwnProperty.call(env.a, "x.y")).toBe(true);
|
|
18
|
-
expect(env.a["x.y"]).toBe(1);
|
|
19
|
-
expect(env.a.x).toBeUndefined();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("read-after-write through the same bracket expression round-trips", () => {
|
|
23
|
-
const { result } = run(`a = {}; a["x.y"] = 42; a["x.y"];`);
|
|
24
|
-
expect(result).toBe(42);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("compound assignment on a dotted literal key still works", () => {
|
|
28
|
-
const { env } = run(`a = { "x.y": 1 }; a["x.y"] += 10;`);
|
|
29
|
-
expect(env.a["x.y"]).toBe(11);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("blocked props remain blocked even when embedded in a dotted string", () => {
|
|
33
|
-
// 'a.__proto__' as a full literal key is NOT the blocked string "__proto__"
|
|
34
|
-
// (it's the 11-char string), so this is allowed as a plain property. The
|
|
35
|
-
// real prototype-pollution vector is the literal "__proto__" segment,
|
|
36
|
-
// still caught by assertSafeProperty.
|
|
37
|
-
expect(() => run(`a = {}; a["__proto__"] = 1;`)).toThrow(
|
|
38
|
-
"Access to property '__proto__' is not allowed"
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("Finding 5 — dotted paths resolve through parent scope", () => {
|
|
44
|
-
// Pre-fix, env.vars = Object.create(parent.vars) made parent variables
|
|
45
|
-
// visible via prototype chain, but deepHas used hasOwn on the first segment
|
|
46
|
-
// so `obj.method()` inside a nested function threw "obj.method is not a
|
|
47
|
-
// function". Post-fix, the first segment uses `in` (walks the chain);
|
|
48
|
-
// subsequent segments still use hasOwn so Object.prototype can't leak in.
|
|
49
|
-
const run = runner();
|
|
50
|
-
|
|
51
|
-
it("calls a method on a parent-scope object from inside a function", () => {
|
|
52
|
-
const { result } = run(`
|
|
53
|
-
obj = { double: (x) => x * 2 };
|
|
54
|
-
function f() { return obj.double(5); }
|
|
55
|
-
f();
|
|
56
|
-
`);
|
|
57
|
-
expect(result).toBe(10);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("reads a nested property on a parent-scope object", () => {
|
|
61
|
-
const { result } = run(`
|
|
62
|
-
config = { db: { host: "localhost", port: 5432 } };
|
|
63
|
-
function f() { return config.db.port; }
|
|
64
|
-
f();
|
|
65
|
-
`);
|
|
66
|
-
expect(result).toBe(5432);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("still blocks Object.prototype leak on subsequent segments", () => {
|
|
70
|
-
// `obj.toString` would resolve to Object.prototype.toString if hasOwn
|
|
71
|
-
// weren't applied after the first segment. Make sure it doesn't.
|
|
72
|
-
expect(() =>
|
|
73
|
-
run(`
|
|
74
|
-
obj = {};
|
|
75
|
-
function f() { return obj.toString(); }
|
|
76
|
-
f();
|
|
77
|
-
`)
|
|
78
|
-
).toThrow(/is not a function|is not defined/);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("still blocks constructor on any segment", () => {
|
|
82
|
-
expect(() =>
|
|
83
|
-
run(`
|
|
84
|
-
obj = {};
|
|
85
|
-
function f() { return obj.constructor; }
|
|
86
|
-
f();
|
|
87
|
-
`)
|
|
88
|
-
).toThrow("Access to property 'constructor' is not allowed");
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("Finding 7 — maxAllocSize bounds object key growth", () => {
|
|
93
|
-
it("spread accumulation under the cap still works", () => {
|
|
94
|
-
const run = runner({ maxSteps: 0, maxAllocSize: 50 });
|
|
95
|
-
const { env } = run(`
|
|
96
|
-
acc = {};
|
|
97
|
-
acc = {...acc, a: 1};
|
|
98
|
-
acc = {...acc, b: 2};
|
|
99
|
-
acc = {...acc, c: 3};
|
|
100
|
-
`);
|
|
101
|
-
expect(env.acc).toEqual({ a: 1, b: 2, c: 3 });
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("recursive {...acc, [k]: k} growth trips the cap", () => {
|
|
105
|
-
// Use recursion instead of reduce(bigArr, ...) so the array literal check
|
|
106
|
-
// doesn't fire first — all that's in scope is a primitive counter. Each
|
|
107
|
-
// ObjectExpression spread projects ownCount + 1; once that exceeds
|
|
108
|
-
// maxAllocSize, checkLength throws.
|
|
109
|
-
const run = runner({ maxSteps: 0, maxAllocSize: 10 });
|
|
110
|
-
expect(() =>
|
|
111
|
-
run(`
|
|
112
|
-
grow = (acc, n) => n > 0 ? grow({...acc, ["k" + n]: n}, n - 1) : acc;
|
|
113
|
-
grow({}, 50);
|
|
114
|
-
`)
|
|
115
|
-
).toThrow(/Length.*exceeds maxAllocSize/);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("object literal with > maxAllocSize keys throws on construction", () => {
|
|
119
|
-
const run = runner({ maxAllocSize: 3 });
|
|
120
|
-
const keys = ["a: 1", "b: 2", "c: 3", "d: 4"].join(", ");
|
|
121
|
-
expect(() => run(`({ ${keys} })`)).toThrow(
|
|
122
|
-
/Length.*exceeds maxAllocSize/
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("repeated keys within one literal don't over-count", () => {
|
|
127
|
-
// Same key written twice is still one own key; cap shouldn't trip.
|
|
128
|
-
const run = runner({ maxAllocSize: 1 });
|
|
129
|
-
expect(() => run(`({ a: 1, a: 2 })`)).not.toThrow();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("objects under the cap still build", () => {
|
|
133
|
-
const run = runner({ maxAllocSize: 10 });
|
|
134
|
-
const { result } = run(`({ a: 1, b: 2, c: 3 })`);
|
|
135
|
-
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("Finding 6 — maxDurationMs bounds wall-clock runs", () => {
|
|
140
|
-
it("a long-running injected builtin trips the deadline on the next step", () => {
|
|
141
|
-
const run = runner({
|
|
142
|
-
maxSteps: 0,
|
|
143
|
-
maxDurationMs: 20,
|
|
144
|
-
functions: {
|
|
145
|
-
slow: (ms: number) => {
|
|
146
|
-
const end = Date.now() + ms;
|
|
147
|
-
while (Date.now() < end) {
|
|
148
|
-
/* burn */
|
|
149
|
-
}
|
|
150
|
-
return 1;
|
|
151
|
-
},
|
|
152
|
-
add: (a: number, b: number) => a + b,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
// slow(100) runs inside V8 (~100ms), overshoots the 20ms deadline. The
|
|
156
|
-
// next interpreter step — evaluating `add(1, 2)` — sees the deadline
|
|
157
|
-
// passed and throws.
|
|
158
|
-
expect(() => run(`slow(100); add(1, 2);`)).toThrow(
|
|
159
|
-
"Execution time exceeded"
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("scripts that finish inside the deadline succeed", () => {
|
|
164
|
-
const run = runner({ maxDurationMs: 5000 });
|
|
165
|
-
const { result } = run(`1 + 2 + 3`);
|
|
166
|
-
expect(result).toBe(6);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("maxDurationMs=0 disables the deadline", () => {
|
|
170
|
-
const run = runner({
|
|
171
|
-
maxDurationMs: 0,
|
|
172
|
-
maxSteps: 1000,
|
|
173
|
-
functions: {
|
|
174
|
-
slow: () => {
|
|
175
|
-
const end = Date.now() + 30;
|
|
176
|
-
while (Date.now() < end) {
|
|
177
|
-
/* burn */
|
|
178
|
-
}
|
|
179
|
-
return 1;
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
expect(() => run(`slow()`)).not.toThrow();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("deadline supersedes subsequent work even if maxSteps would still allow it", () => {
|
|
187
|
-
// Step counter never trips (maxSteps=0 disables), so wall-clock is the
|
|
188
|
-
// only gate. Confirm the deadline still fires.
|
|
189
|
-
const run = runner({
|
|
190
|
-
maxSteps: 0,
|
|
191
|
-
maxDurationMs: 10,
|
|
192
|
-
functions: {
|
|
193
|
-
slow: (ms: number) => {
|
|
194
|
-
const end = Date.now() + ms;
|
|
195
|
-
while (Date.now() < end) {
|
|
196
|
-
/* burn */
|
|
197
|
-
}
|
|
198
|
-
return 1;
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
expect(() => run(`slow(50); slow(50);`)).toThrow(
|
|
203
|
-
"Execution time exceeded"
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import runner from "../index.js";
|
|
3
|
-
|
|
4
|
-
const run = runner();
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* https://blog.liftsecurity.io/2015/04/27/when-this-is-really-that/
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
describe("try to get require", () => {
|
|
11
|
-
it("this.constructor.constructor", () => {
|
|
12
|
-
const code = `bar = this.constructor.constructor`;
|
|
13
|
-
const env = {};
|
|
14
|
-
expect(() => run(code, env)).toThrow("Cannot evaluate ThisExpression");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("object.constructor", () => {
|
|
18
|
-
const code = `
|
|
19
|
-
bar = { any: "thing" };
|
|
20
|
-
func = bar.constructor;
|
|
21
|
-
func2 = func("return process");
|
|
22
|
-
process = func2();
|
|
23
|
-
`;
|
|
24
|
-
const env = {};
|
|
25
|
-
expect(() => run(code, env)).toThrow(
|
|
26
|
-
"Access to property 'constructor' is not allowed"
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("arguments.callee.caller", () => {
|
|
31
|
-
const code = `
|
|
32
|
-
function getFunc () {
|
|
33
|
-
return arguments.callee.caller.arguments.callee.caller.arguments.callee.caller.arguments.callee.arguments.callee.caller;
|
|
34
|
-
}
|
|
35
|
-
func = getFunc();
|
|
36
|
-
func.call(func, "var fs = process.mainModule.require('fs');");
|
|
37
|
-
`;
|
|
38
|
-
const env = {};
|
|
39
|
-
expect(() => run(code, env)).toThrow(
|
|
40
|
-
new ReferenceError(`"arguments" is not defined (3:15)`)
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
});
|