0

If I

delete global.process

in a nodejs worker thread can it be restored or has it been permanently removed from the worker thread?

Trusted user code is running in the worker thread via Function() object which means that require is not available. In this post Node "ReferenceError: require is not defined" when executing a Function object it shows that require can be defined via:

var testF = new Function("x","y", "var require = global.require || global.process.mainModule.constructor._load; var http = require('http');");

but since process is not available on global (because of delete global.process in worker) that does not work and attempt to restore process via require("process") will fail.

The code is run by trusted users but I nevertheless want to assert some control over it, hence the question.

J. Reynolds
  • 151
  • 3
  • 14
  • You are aware that it can be required again, `const process=require("process")`? A "restore" would be simple `global.process = require("process")` – Marc Apr 28 '23 at 10:09
  • @Marc The code is running via Function() script. I did not want to include it in the question as I do not want to elicit unnecesary "Don't do it becuase of security blah blah..." answers. – J. Reynolds Apr 30 '23 at 06:28
  • Not an answer, but take a look at this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/deleteProperty – Parzh from Ukraine Apr 30 '23 at 06:41

0 Answers0