Show HN: SafeScript, a safe version of JavaScript for executing untrusted code g...

@best

Show HN: SafeScript, a safe version of JavaScript for executing untrusted code github.com · 7 points · 1 comments · HN thread

TL;DR SafeScript is an MIT-licensed, Show HN project by Gregory Magarshak: a strict subset of JavaScript (no eval, new, globals or prototype access) that compiles to plain JS and PHP, aimed at running user-submitted code such as handlers, plugins and formulas in a sandbox. The README describes four defense layers, guard injection for timeouts and operation counts, and an object-capability model for injected host functions. The thread has only one comment, which raises a memory-exhaustion concern the README does not address.

  • Strict JavaScript subset with no eval, new, class, import, async/await, template literals or access to globalThis, window or document; the AST is rebuilt, so original source text never reaches the output.
  • Bracket access is rewritten to runtime guards that block constructor, proto, prototype, caller and callee, and built-in globals are replaced with frozen facade objects exposing only safe static methods.
  • Compile-time __check() calls enforce a timeout (hard ceiling 60s) and an operation limit (hard ceiling 100M ops) at function entries and loop iterations.
  • Scripts declare capabilities in a header (@needs, @uses, @type, @env) and never import or require anything; the host builds the scope and can validate declarations at load time.
  • Hooks let the host block, transform or rate-limit calls to injected functions, and Math.random is deterministic (mulberry32, seed 0) unless the host explicitly approves true randomness.
  • Compiler is about 48 KB minified (about 12 KB gzipped); integrations are listed for Express, browsers, a CLI, QuickJS and a pure PHP port.

Discussion The thread is essentially unanswered. A single top-level comment from Rohansi asks what prevents a malicious script from consuming the host's memory. The op-count and timeout guards described in the README cover CPU and loops, but nothing in the text mentions memory limits, so the question is unaddressed and no one has replied. The mood is neutral and questioning rather than enthusiastic.

  • Memory exhaustion by untrusted scripts is unaddressed (a few): The only comment asks what stops a malicious script from consuming the host's memory. The README's guards cover timeouts and operation counts, not allocation size, so the concern stands unanswered in the thread.

#javascript #sandboxing #security #untrustedCode #showHN