• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Executing untrusted code

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to execute Java code which users can enter into a form on a website. The output should be written to the console on my server.

I came up with the following setup:
1) Create a Docker container with a JVM where the code is executed.
2) Use the Java Security Manager to allow only the use of certain (Java core) classes, restrict network access, file access etc.

Here are some examples of website where you can upload code to be executed.
  • https://try.kotlinlang.org
  • https://www.jdoodle.com
  • https://www.hackerrank.com


  • What are your thoughts about this approach? What are the security issues with the above set up?
     
    Rancher
    Posts: 5008
    38
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Another area to look at is use of policy file:
    A batch file to execute the todo2.jar file:


    @Rem Test todo2jar file
    java -Djava.security.manager -Djava.security.policy=mypolicy.policy -jar todo2.jar
    MORE


    mypolicy.policy:


    /* AUTOMATICALLY GENERATED ON Tue Aug 10 13:23:54 CDT 2010*/
    /* DO NOT EDIT */

    grant {
     permission java.net.SocketPermission "world169.runescape.com:80", "connect, resolve";
     permission java.lang.RuntimePermission "createClassLoader";
     permission java.lang.RuntimePermission "setContextClassLoader";
     permission java.net.SocketPermission "*.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world3.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world12.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world15.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world19.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world22.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world30.runescape.com", "connect, accept, resolve";
     permission java.net.SocketPermission "world32.runescape.com", "connect, accept, resolve";
     permission java.awt.AWTPermission "createRobot";
    };

     
    Saloon Keeper
    Posts: 7594
    177
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    A combination of custom ClassLoader and custom SecurityManager might do the trick even without resorting to Docker. The article https://javaranch.com/journal/200607/Journal200607.jsp#a1 described such an approach.
    reply
      Bookmark Topic Watch Topic
    • New Topic