hn.today

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

github.com12 points13 comments
Screenshot of Show HN: SafeScript, a safe version of JavaScript for executing untrusted code

SafeScript is a restricted JavaScript language for running untrusted code inside applications. It aims to offer more flexibility than data-only formats such as JSON without exposing the host environment to arbitrary JavaScript. Scripts are function bodies that return results, and the compiler produces ordinary JavaScript or PHP. With no capabilities supplied, code can perform isolated computations using a curated set of safe built-ins; it cannot access I/O or the surrounding environment.

A .safe file can declare its language version, required and optional capabilities, expected environment, and methods it intends to call on returned types. Hosts can inspect those declarations, check that requirements are available, and validate type-method declarations before execution. Each file is intended to be a separate trust boundary: it has no imports, and the host decides what implementations to provide. SafeScript restricts the accepted syntax, blocks access to dangerous prototype properties, shadows native globals, and exposes limited frozen facades for common built-ins. Compiled checks limit execution time and operations, while hooks let hosts monitor calls to injected functions. Type declarations support preflight validation but do not themselves enforce runtime behavior. The design puts capability decisions in the host’s hands and avoids making scripts depend on package managers.

Read on github.com13 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Security

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.