@ai-ecoverse/slicc-kernel 1.53.1 → 1.53.2

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/README.md CHANGED
@@ -236,7 +236,7 @@ A program that throws, or leaves an error or a rejected promise unhandled with n
236
236
 
237
237
  The module has the trust of an Emscripten program's glue or a WASI program's imports module: it comes from a package that was installed, and it runs in the worker of its own process. The kernel withholds the worker's own ways out before it loads the module: `XMLHttpRequest`, `WebSocketStream`, `WebTransport`, `EventSource`, `importScripts`, `indexedDB`, `caches`, `cookieStore`, `Worker`, `SharedWorker`, `BroadcastChannel`, `postMessage`, `close`, and `navigator.storage`, `navigator.locks` and `navigator.serviceWorker` are `undefined`, and a worker where one of them cannot be removed refuses to run the program (126). `fetch` and `WebSocket` are `undefined` too, but stay writable and configurable, so a program can install its own over `ctx.fetch` and `ctx.websocket` (as slicc-jsh does). A program's files are the kernel's, through the context; it reaches the kernel only through its own process's system calls, as the context makes them, and no other process's. This is a guard against programs going around the kernel, not a sandbox: `import()` of a URL is a request the kernel cannot withhold.
238
238
 
239
- Under the Node entry, the kernel also withholds the host's Node from the program before its module loads ([#297](https://github.com/ai-ecoverse/slicc-kernel/issues/297)). `require`, `module`, `exports`, `__filename`, `__dirname`, `localStorage` and `sessionStorage` are `undefined` for good. `process`, `global`, `setImmediate` and `clearImmediate` are `undefined` too, but stay writable, so a program can install its own (as slicc-jsh does). `Buffer` stays Node's own, since Node's `Response`, `Request`, `Blob` and stream bodies read it when they run; it reaches nothing outside the program, and a program can replace it. Imports of Node's builtin modules (`node:fs`, `fs`, `node:worker_threads`, …) and of anything but a `data:` URL, `file:` included, fail with `ERR_ACCESS_DENIED`, whether static, dynamic or through `import.meta.resolve`. A process worker that exits or crashes on its own ends its process with 70. This is the same guard, not a sandbox: a host that runs code it does not trust, such as an agent's, needs its own isolation around the Node process as well.
239
+ Under the Node entry, the kernel also withholds the host's Node from the program before its module loads ([#297](https://github.com/ai-ecoverse/slicc-kernel/issues/297)). `require`, `module`, `exports`, `__filename`, `__dirname`, `localStorage` and `sessionStorage` are `undefined` for good. `process`, `global`, `setImmediate` and `clearImmediate` are `undefined` too, but stay writable, so a program can install its own (as slicc-jsh does). `Buffer` stays Node's own, since Node's `Response`, `Request`, `Blob` and stream bodies read it when they run, and a program can replace it. Process workers share Node's memory allocator, so its `allocUnsafe` and `allocUnsafeSlow` zero-fill and its pool is off (`Buffer.poolSize` is 0): a program never sees memory another process freed. A host can also start Node with `--zero-fill-buffers`. Imports of Node's builtin modules (`node:fs`, `fs`, `node:worker_threads`, …) and of anything but a `data:` URL, `file:` included, fail with `ERR_ACCESS_DENIED`, whether static, dynamic or through `import.meta.resolve`. A process worker that exits or crashes on its own ends its process with 70. This is the same guard, not a sandbox: a host that runs code it does not trust, such as an agent's, needs its own isolation around the Node process as well.
240
240
 
241
241
  ## Network
242
242
 
@@ -11325,6 +11325,15 @@ var NODE_SLOTS = [
11325
11325
  "setImmediate",
11326
11326
  "clearImmediate"
11327
11327
  ];
11328
+ function zeroedBuffers(buffer) {
11329
+ const alloc = buffer.alloc.bind(buffer);
11330
+ const fixed = (value2) => ({ value: value2, writable: false, configurable: false });
11331
+ Object.defineProperties(buffer, {
11332
+ allocUnsafe: fixed((size) => alloc(size)),
11333
+ allocUnsafeSlow: fixed((size) => alloc(size)),
11334
+ poolSize: fixed(0)
11335
+ });
11336
+ }
11328
11337
  function refused(specifier) {
11329
11338
  return Object.assign(new Error(`slicc-kernel: a JS program cannot import ${specifier}`), {
11330
11339
  code: "ERR_ACCESS_DENIED"
@@ -11341,6 +11350,7 @@ function refuseModules() {
11341
11350
  });
11342
11351
  }
11343
11352
  function nodeLockdown(scope2 = globalThis) {
11353
+ zeroedBuffers(Buffer);
11344
11354
  lockdown(scope2);
11345
11355
  hide(scope2, NODE_GLOBALS);
11346
11356
  vacate(scope2, NODE_SLOTS);