You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Mike Blan <bl...@us.ibm.com> on 2007/02/28 06:03:05 UTC

BSF with Rhino, Java 2 Security problem

I have made extensive use of BSF with Rhino over the past several years to
code business logic in a Servlet based application in WebSphere v4. (upwards
of 100,000 loc in javascript) Moving to Websphere v5 and Java 1.4 with Java
2 Security has resulted in the exception below. 

BSF v2.4
Rhino v1.6.4

org.apache.bsf.BSFException: JavaScript Error:
java.lang.IllegalAccessException: Class org.mozilla.javascript.MemberBox can
not access a member of class java.util.TreeMap$KeyIterator with modifiers
"public"
	at
org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(JavaScriptEngine.java:195)
	at
org.apache.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java:147)
	at org.apache.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:141)
	at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
	at java.security.AccessController.doPrivileged1(Native Method)
	at
java.security.AccessController.doPrivileged(AccessController.java(Compiled
Code))
	at org.apache.bsf.BSFManager.exec(BSFManager.java(Compiled Code))
	at
tools.JavaScriptEngineWrapper.jsExec(JavaScriptEngineWrapper.java(Inlined
Compiled Code))


For stack trace above: 
  Package tools is the app
  jsExec calls BSF to execute a javascript 
  the javascript starts to run in   JavaScriptEngine.eval
  this particular script creates a TreeMap object and then uses an iterator
over its contents, which results in the
  IllegalAccessException

Here's the policy file 

grant codeBase "file:${application}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${jars}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${connectorComponent}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${webComponent}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${ejbComponent}" {
  permission java.security.AllPermission;
};

grant {
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
};

The JavaScript which results in the exception (but many other various
examples also fail)

   var map = new java.util.TreeMap();
   // put data in map
   var it = map.keySet().iterator();


I stress that this code works as designed with Java 2 Security disabled.


Can anyone suggest a policy file change to allow code like this to work? I
can supply additional documentation upon request. 

Thank you!

-- 
View this message in context: http://www.nabble.com/BSF-with-Rhino%2C-Java-2-Security-problem-tf3306796.html#a9198064
Sent from the BSF - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: BSF with Rhino, Java 2 Security problem

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Mike,

Mike Blan wrote:
> I will post this in case anyone else runs into same. This worked for my
> application.
>
> See   https://bugzilla.mozilla.org/show_bug.cgi?id=190841#c3 bugzilla 
>
> In   cookxml.cookjs.util.ProxyHandler.invoke(...)
>
> 			// return JavaAdapter.callMethod (m_delegate, function, args,
> convertionMask);
> 			// JavaAdapter.callMethod in Rhino 1.6.4 requires at least a null factory
> reference.
> 			ContextFactory factory = null;
> 			return JavaAdapter.callMethod(factory, m_delegate, function, args,
> convertionMask);
>
> In  org.apache.bsf.engines.javascript.JavaScriptEngine.call(...)  and
> eval(...) 
>
>             cx.setOptimizationLevel(-1);
>             cx.setGeneratingDebug(false);
>             cx.setGeneratingSource(false);
>             //cx.setOptimizationLevel(0); 
>             cx.setDebugger(null, null);
>             // Mozilla Bug 190841 – Generated classes have too low
> privileges 
>             ProxyJavaAdapter.init (cx, global, true);
>             
>             retval =
>                 ((Function) fun).call(cx, global, global, args);
>   
Could you be so kind and supply a patch under the Apache license?
[AFAICS the ProxyJavaAdapter.init() needs to be invoked from the
BSF-Javascript/Rhino engine?]


Regards,

---rony


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: BSF with Rhino, Java 2 Security problem

Posted by Mike Blan <bl...@us.ibm.com>.
I will post this in case anyone else runs into same. This worked for my
application.

See   https://bugzilla.mozilla.org/show_bug.cgi?id=190841#c3 bugzilla 

In   cookxml.cookjs.util.ProxyHandler.invoke(...)

			// return JavaAdapter.callMethod (m_delegate, function, args,
convertionMask);
			// JavaAdapter.callMethod in Rhino 1.6.4 requires at least a null factory
reference.
			ContextFactory factory = null;
			return JavaAdapter.callMethod(factory, m_delegate, function, args,
convertionMask);

In  org.apache.bsf.engines.javascript.JavaScriptEngine.call(...)  and
eval(...) 

            cx.setOptimizationLevel(-1);
            cx.setGeneratingDebug(false);
            cx.setGeneratingSource(false);
            //cx.setOptimizationLevel(0); 
            cx.setDebugger(null, null);
            // Mozilla Bug 190841 – Generated classes have too low
privileges 
            ProxyJavaAdapter.init (cx, global, true);
            
            retval =
                ((Function) fun).call(cx, global, global, args);



-- 
View this message in context: http://www.nabble.com/BSF-with-Rhino%2C-Java-2-Security-problem-tf3306796.html#a9292215
Sent from the BSF - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: BSF with Rhino, Java 2 Security problem

Posted by Anthony Elder <an...@uk.ibm.com>.
Maybe you should try asking over on the Rhino mailing list as this looks 
more like something they could help with than a BSF problem. 

See http://groups.google.co.uk/group/mozilla.dev.tech.js-engine/topics

       ...ant


Please respond to "Bean Scripting Framework users" 
<bs...@jakarta.apache.org> 
To:     bsf-user@jakarta.apache.org
cc:      
Subject:        BSF with Rhino, Java 2 Security problem



I have made extensive use of BSF with Rhino over the past several years to
code business logic in a Servlet based application in WebSphere v4. 
(upwards
of 100,000 loc in javascript) Moving to Websphere v5 and Java 1.4 with 
Java
2 Security has resulted in the exception below. 

BSF v2.4
Rhino v1.6.4

org.apache.bsf.BSFException: JavaScript Error:
java.lang.IllegalAccessException: Class org.mozilla.javascript.MemberBox 
can
not access a member of class java.util.TreeMap$KeyIterator with modifiers
"public"
                 at
org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(JavaScriptEngine.java:195)
                 at
org.apache.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java:147)
                 at 
org.apache.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:141)
                 at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
                 at java.security.AccessController.doPrivileged1(Native 
Method)
                 at
java.security.AccessController.doPrivileged(AccessController.java(Compiled
Code))
                 at 
org.apache.bsf.BSFManager.exec(BSFManager.java(Compiled Code))
                 at
tools.JavaScriptEngineWrapper.jsExec(JavaScriptEngineWrapper.java(Inlined
Compiled Code))


For stack trace above: 
  Package tools is the app
  jsExec calls BSF to execute a javascript 
  the javascript starts to run in   JavaScriptEngine.eval
  this particular script creates a TreeMap object and then uses an 
iterator
over its contents, which results in the
  IllegalAccessException

Here's the policy file 

grant codeBase "file:${application}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${jars}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${connectorComponent}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${webComponent}" {
  permission java.security.AllPermission;
};

grant codeBase "file:${ejbComponent}" {
  permission java.security.AllPermission;
};

grant {
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
};

The JavaScript which results in the exception (but many other various
examples also fail)

   var map = new java.util.TreeMap();
   // put data in map
   var it = map.keySet().iterator();


I stress that this code works as designed with Java 2 Security disabled.


Can anyone suggest a policy file change to allow code like this to work? I
can supply additional documentation upon request. 

Thank you!

-- 
View this message in context: 
http://www.nabble.com/BSF-with-Rhino%2C-Java-2-Security-problem-tf3306796.html#a9198064

Sent from the BSF - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org








Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU