endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
761 stars 68 forks source link

`endo make` leaves behind temp bundle if `make()` result is bad #2290

Closed FUDCo closed 1 month ago

FUDCo commented 1 month ago

Describe the bug

I'm not 100% sure what the required nature of the result returned by the make() function defining a worker should be (I suspect it's supposed to be serializable), but if you return something unsuitable (such as a function) and creating the worker required creating a temp bundle, the temp bundle will be left behind as debris.

Steps to reproduce

Create the following nonsense worker source file zot.js:

export const make = () => {
  return () => 47;
}

If you then try to use it with endo make -name stuff zot.js it produces an error:

CapTP cli exception: (RemoteError(error:captp:Endo#20001)#1)
RemoteError(error:captp:Endo#20001)#1: Remotables must be explicitly declared: "[Function <anon>]"
  at makeError (file:///Users/chip/GitRepos/endo/packages/ses/src/error/assert.js:347:61)
  at decodeErrorCommon (file:///Users/chip/GitRepos/endo/packages/marshal/src/marshal.js:309:24)
  at decodeErrorFromCapData (file:///Users/chip/GitRepos/endo/packages/marshal/src/marshal.js:337:14)
  at decodeFromCapData (file:///Users/chip/GitRepos/endo/packages/marshal/src/encodeToCapData.js:382:27)
  at fromCapData (file:///Users/chip/GitRepos/endo/packages/marshal/src/marshal.js:401:23)
  at CTP_RETURN (file:///Users/chip/GitRepos/endo/packages/captp/src/captp.js:696:24)
  at dispatch (file:///Users/chip/GitRepos/endo/packages/captp/src/captp.js:775:7)
  at file:///Users/chip/GitRepos/endo/packages/daemon/src/connection.js:36:7
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

(RemoteError(error:captp:Endo#20001)#1)

A subsequent endo list command produces:

AGENT
APPS
ENDO
INFO
NETS
NONE
SELF
stuff
tmp-bundle-ac5d43080cd293fe6348d5a5f3c869d1

Expected behavior

The temp bundle should not be left behind.

NOTE: If the zot.js file simply contains syntactically invalid JavaScript, the temp bundle is cleaned up properly.

FUDCo commented 1 month ago

Note: I have a fix but apparently no longer have access to the repo.