You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Glenn Nielsen <gl...@voyager.apg.more.net> on 2000/05/17 05:54:12 UTC

Tomcat 3.1 w/SecurityManager Jasper Compile AccessControlException

When testing execution of JSP with a SecurityManager I get an AccessControlException
when Jasper tries to compile a JSP using sun.tools.java.

Both tools.jar and jasper.jar are in a classpath's that are granted AllPermissions in
the policy file.

I tried using AccessController.doPrivileged() to execute the compile,
but the AccessControlException is still thrown.

Any ideas what is causing this?

Could it be that the URLClassLoader ends up getting used?

Will an alternate compiler have to be configured for Jasper?
And if so, how is that configured in server.xml?

Thanks,

Glenn

Here is the stack trace:


java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.tools.java )
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.fillInStackTrace(Compiled Code)
        at java.lang.Throwable.(Compiled Code)
        at java.lang.Exception.(Compiled Code)
        at java.lang.RuntimeException.(RuntimeException.java:47)
        at java.lang.SecurityException.(SecurityException.java:39)
        at java.security.AccessControlException.(AccessControlException.java:57)
        at java.security.AccessControlContext.checkPermission(Compiled Code)
        at java.security.AccessController.checkPermission(Compiled Code)
        at java.lang.SecurityManager.checkPermission(Compiled Code)
        at java.lang.SecurityManager.checkPackageAccess(Compiled Code)
        at sun.misc.Launcher$AppClassLoader.loadClass(Compiled Code)
        at java.lang.ClassLoader.loadClass(Compiled Code)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass0(Compiled Code)
        at java.lang.ClassLoader.defineClass(Compiled Code)
        at java.security.SecureClassLoader.defineClass(Compiled Code)
        at java.net.URLClassLoader.defineClass(Compiled Code)
        at java.net.URLClassLoader.access$1(Compiled Code)
        at java.net.URLClassLoader$1.run(Compiled Code)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessController.doPrivileged(Compiled Code)
        at java.net.URLClassLoader.findClass(Compiled Code)
        at java.lang.ClassLoader.loadClass(Compiled Code)
        at sun.misc.Launcher$AppClassLoader.loadClass(Compiled Code)
        at java.lang.ClassLoader.loadClass(Compiled Code)
        at
org.apache.jasper.compiler.SunJavaCompiler$1$doInit.run(SunJavaCompiler.java:140)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.jasper.compiler.SunJavaCompiler.compile(SunJavaCompiler.java:161)
        at org.apache.jasper.compiler.Compiler.compile(Compiled Code)
        at org.apache.jasper.runtime.JspServlet.loadJSP(JspServlet.java:413)
        at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:149)
        at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:161)
        at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
        at org.apache.jasper.runtime.JspServlet.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.handleRequest(Compiled Code)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:577)
        at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:156)
        at org.apache.tomcat.service.TcpWorkerThread.run(Compiled Code)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled Code)
        at java.lang.Thread.run(Thread.java:485)


----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Re: Tomcat 3.1 w/SecurityManager Jasper Compile AccessControlException

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
Costin Manolache wrote:
> 
> For "production" sites, where the security manager makes sense, I suppose we can assume
> pre-compiled JSPs ?
> 

The reason I am working on use of a SecurityManager is so that remote 
web publishers can publish jsp pages that get compiled dynamically.
But due to the SecurityManager being in place, they can't do anything
nasty like cat /etc/passwd or exec a shell command, etc. 

i.e. like a web hosting service that only allows content to be maintained
using ftp.  In this case the remote web publisher wouldn't have access to
the server, so it would not be possible for them to precompile the jsp.

In my case, between 8 production servers we have over 200 virtual hosts,
and about 750 people who can publish content using ftp only.

> The speed is significantly higher, not only the first time but for each access -
> you avoid the extra overhead of the second servlet invocation  ( JspServlet ),
> and avoid all the file accesses.
> I'm not very confortable with spawning an external process ( a compiler !) on a secure
> environment, even if javac works - it may be better to do the compilation on a stage
> server.
> 

For now, I'll take the performance hit of an external compiler so that
security can be enforced on jsp's.  I don't see where spawning an external
compiler is a problem, the command and args to compile the JSP is totally 
controlled by Jasper.  Its not like perl CGI where form input can potentially 
be passed through to an executable as a command line arg.

I noticed a potential security problem with Jasper, when it sets up the
classpath for the compiler it includes the "work" directory.  This could
allow someone to create a JSP that uses a java class for someone elses 
precompiled JSP class file.

Now that I can get jasper to compile a jsp, I'll start delving into the
JSPLoader so that its class loader can use the SecurityManager.

Regards,

Glenn

> 
> Glenn Nielsen wrote:
> 
> > I think I figured this one out, the security designed into
> > sun.tools.javac.Main is so strict that it prevents the compiler
> > from being run if a SecurityManager is installed.
> >

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Re: Tomcat 3.1 w/SecurityManager Jasper Compile AccessControlException

Posted by Costin Manolache <co...@eng.sun.com>.
For "production" sites, where the security manager makes sense, I suppose we can assume
pre-compiled JSPs ?

The speed is significantly higher, not only the first time but for each access -
you avoid the extra overhead of the second servlet invocation  ( JspServlet ),
and avoid all the file accesses.
I'm not very confortable with spawning an external process ( a compiler !) on a secure
environment, even if javac works - it may be better to do the compilation on a stage
server.

I don't know - at least that's how I would run it.

Costin


Glenn Nielsen wrote:

> I think I figured this one out, the security designed into
> sun.tools.javac.Main is so strict that it prevents the compiler
> from being run if a SecurityManager is installed.
>
> sun.tools.javac.Main fails with an AccessControlException if a SecurityManager is
> in use, regardless of what permissions you grant in your java.policy file.
>
> So I did a test outside of Tomcat:
>
> I created a system level java.policy file that contained
>
> grant {
>         permission java.security.AllPermission;
> };
>
> Then I wrote the TestCompile.java class as follows
>
> import sun.tools.javac.Main;
>
> public class TestCompile {
>   public static void main (String args[]) {
>     Main compiler = new Main(System.out, "jsp->javac");
>
>     String[] cargs = new String[]
>       {
>         "TestCompile.java"
>       };
>
>     compiler.compile(cargs);
>   }
> }
>
> I compiled the above with
>
> javac TestCompile.java
>
> Then executed the above without a SecurityManager
>
> java TestCompile
>
> and the compiler ran without an AccessControlException.
>
> Then executed it with the default java.policy file above
>
> java -Djava.security.manager TestCompile
>
> and it generated the following stack trace.
>
> Exception in thread "main" java.security.AccessControlException: access denied
> (java.lang.RuntimePermission accessClassInPackage.sun.tools.java )
>         at java.lang.Throwable.fillInStackTrace(Native Method)
>         at java.lang.Throwable.<init>(Throwable.java:94)
>         at java.lang.Exception.<init>(Exception.java:42)
>         at java.lang.RuntimeException.<init>(RuntimeException.java:47)
>         at java.lang.SecurityException.<init>(SecurityException.java:39)
>         at java.security.AccessControlException.<init>(AccessControlException.java:57)
>         at java.security.AccessControlContext.checkPermission(Compiled Code)
>         at java.security.AccessController.checkPermission(Compiled Code)
>         at java.lang.SecurityManager.checkPermission(Compiled Code)
>         at java.lang.SecurityManager.checkPackageAccess(Compiled Code)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:238)
>         at java.lang.ClassLoader.defineClass0(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:404)
>         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:101)
>         at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
>         at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:281)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:238)
>         at TestCompile.main(TestCompile.java:5)
>
> The only conclusion I can reach is that the security designed into
> sun.tools.javac.Main is so strict that it prevents the compiler from
> being run if a SecurityManager is installed.
>
> I was able to get Jasper to compile a JSP by using the Jikes compiler config,
> I changed jikes to javac since I don't have jikes installed.
>
> Regards,
>
> Glenn
>
> Glenn Nielsen wrote:
> >
> > When testing execution of JSP with a SecurityManager I get an AccessControlException
> > when Jasper tries to compile a JSP using sun.tools.java.
> >
> > Both tools.jar and jasper.jar are in a classpath's that are granted AllPermissions in
> > the policy file.
> >
> > I tried using AccessController.doPrivileged() to execute the compile,
> > but the AccessControlException is still thrown.
> >
> > Any ideas what is causing this?
> >
> > Could it be that the URLClassLoader ends up getting used?
> >
> > Will an alternate compiler have to be configured for Jasper?
> > And if so, how is that configured in server.xml?
> >
> > Thanks,
> >
> > Glenn
> >
>
> ----------------------------------------------------------------------
> Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
> MOREnet System Programming               |  * if iz ina coment.      |
> Missouri Research and Education Network  |  */                       |
> ----------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: Tomcat 3.1 w/SecurityManager Jasper Compile AccessControlException

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
I think I figured this one out, the security designed into 
sun.tools.javac.Main is so strict that it prevents the compiler 
from being run if a SecurityManager is installed.

sun.tools.javac.Main fails with an AccessControlException if a SecurityManager is
in use, regardless of what permissions you grant in your java.policy file.

So I did a test outside of Tomcat:

I created a system level java.policy file that contained

grant {
        permission java.security.AllPermission;
};

Then I wrote the TestCompile.java class as follows

import sun.tools.javac.Main;

public class TestCompile {
  public static void main (String args[]) {
    Main compiler = new Main(System.out, "jsp->javac");

    String[] cargs = new String[]
      {
        "TestCompile.java"
      };
        
    compiler.compile(cargs);
  }
}

I compiled the above with

javac TestCompile.java

Then executed the above without a SecurityManager

java TestCompile

and the compiler ran without an AccessControlException.

Then executed it with the default java.policy file above

java -Djava.security.manager TestCompile

and it generated the following stack trace.

Exception in thread "main" java.security.AccessControlException: access denied
(java.lang.RuntimePermission accessClassInPackage.sun.tools.java )
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.<init>(Throwable.java:94)
        at java.lang.Exception.<init>(Exception.java:42)
        at java.lang.RuntimeException.<init>(RuntimeException.java:47)
        at java.lang.SecurityException.<init>(SecurityException.java:39)
        at java.security.AccessControlException.<init>(AccessControlException.java:57)
        at java.security.AccessControlContext.checkPermission(Compiled Code)
        at java.security.AccessController.checkPermission(Compiled Code)
        at java.lang.SecurityManager.checkPermission(Compiled Code)
        at java.lang.SecurityManager.checkPackageAccess(Compiled Code)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:238)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:404)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:101)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
        at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:281)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:238)
        at TestCompile.main(TestCompile.java:5)

The only conclusion I can reach is that the security designed into 
sun.tools.javac.Main is so strict that it prevents the compiler from 
being run if a SecurityManager is installed.

I was able to get Jasper to compile a JSP by using the Jikes compiler config,
I changed jikes to javac since I don't have jikes installed.

Regards,

Glenn

Glenn Nielsen wrote:
> 
> When testing execution of JSP with a SecurityManager I get an AccessControlException
> when Jasper tries to compile a JSP using sun.tools.java.
> 
> Both tools.jar and jasper.jar are in a classpath's that are granted AllPermissions in
> the policy file.
> 
> I tried using AccessController.doPrivileged() to execute the compile,
> but the AccessControlException is still thrown.
> 
> Any ideas what is causing this?
> 
> Could it be that the URLClassLoader ends up getting used?
> 
> Will an alternate compiler have to be configured for Jasper?
> And if so, how is that configured in server.xml?
> 
> Thanks,
> 
> Glenn
> 

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------