1

I built a large JAVA web application using SPRING & MongoDB, In some scenarios, I want to allow my users to upload their own code, and the application will run it later on when necessary. I called this operation "Plugin framework", the plugin is the user's code of course which I prefer to be in NodeJS for now.

There is any recommended / known architecture for that purpose? I've read about pf4j and senecajs, but they quite different from my needs.

Thanks!

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Sahar Ben-Shushan
  • 297
  • 1
  • 3
  • 20
  • If you are building kind of 'code compiler' or maybe 'code validation' then you should avoid framework like pf4j because it's providing 'architecture' model called 'modular application / microkernel' and it's one of substitute for OSGi frameworks [ex. Apache Felix] but i deduce [looking at tags] that you build architecture for your application and then you are using spring. Maybe you should look at microservice architecture rather then modular app. – underwater ranged weapon Aug 09 '17 at 09:37

1 Answers1

0

You loose complete control over code running on node. The uploaded code can access network, files, database, you name it. That is not a good plan.

I suggest to work with the embedded JS module in Java, called rhino. Here, you define which environment the code can access.

You find samples of using the scripting in Java here http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/programmer_guide/index.html for jdk7, the Javadocs https://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngine.html and here some info on Java8 changes http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html

UPDATE:

On the comment below, you state that you think you are safe, if the code runs on the other server. Actually, the problem is still the same. Just it won't hit your application's server but the JS code server.

My advice stands. Implement a JS execution service using the built-in Javascript engine (Rhino or Nashorn) and restrict the running JS to a sandbox, you control the script's reach out of the box through carefully implemented env-access methods. It is actually pretty easy to get started, no more complicated than implementing a remote javascript implementation engine on top of node...

thst
  • 4,592
  • 1
  • 26
  • 40
  • Actually I'm the JS code will be execute on defiantly separate server, with no access or impact on my code. Therefore I prefer it to be out of my core project, but with the ability to execute these JS files and use their output – Sahar Ben-Shushan Aug 09 '17 at 17:03
  • see my updated article. I think your design is flawed from a security point of view. – thst Aug 10 '17 at 20:15