Skip to content Skip to sidebar Skip to footer

Is It Possible To Read Local Variables Of Parent Stackframes?

Scenario: I am working on Javascript code that allows running arbitrary user-supplied code in a web worker environment, similar to this approach. Let's call the two parties host (l

Solution 1:

is not possible for code to read scriptId in any execution environment?

Yes. Code can only access variables in its current scope (of the execution context), not local variables from scopes on the call stack.

However, eval'd code can access and possibly overwrite/intercept the global postMessage and onmessage functions. If you have prevented that, they still would be able to call them, so you need to verify that the calls came from your worker manager and not from the custom code. If you have ensured that, everything should be fine.

Notice that when you're running multiple scripts in the same "worker session", you might need to clean up the global scope after each run (or prevent any modifications in beforehand). Otherwise, independent scripts might be able to communicate with each other.

Post a Comment for "Is It Possible To Read Local Variables Of Parent Stackframes?"