How to protect object fields from being modified?

21 views
Skip to first unread message

Tomaž Kunaver

unread,
Apr 2, 2018, 10:05:31 AM4/2/18
to mozilla-rhino
Hi,
I'd like to know how can I achieve the following: Java classes, that my javascript code accesses, must not be modifiable by it.
For example, currently I can simply modify any field by simply assigning it:

com.betalord.sgx.core.GameState.simulation.map.planets.get(0).name = "bla"

I am trying to prevent that. I'd like to create a sandbox. A more detailed post is here:
Any ideas/suggestions are most welcome!

Gregory Brail

unread,
Apr 20, 2018, 12:33:05 PM4/20/18
to mozill...@googlegroups.com
Sorry about the late answer...

Rhino does have the concept of a "Class shutter" -- you can look it up in the source or the Context class. It lets you restrict which Java classes an app can access. That can help a lot. with basic problems like limiting the ability of Rhino code to access arbitrary Java objects.

That said, most Java security experts (and I'm not going to pretend to be one) recommend using the Java security manager as well to ensure that any customer-written code is run in a less-privileged manner, and I've had them tell me over the years that they trust that method a lot more than the class shutter.

Finally, many have also recommended consistently over the years that untrusted code is the least unsafe when run in a separate container or virtual machine, as even the Java security manager doesn't protect you from runaway code, memory leaks, and as-yet-unknown bugs in the whole stack.

So it's really a matter of how must risk you are able to take.

--
You received this message because you are subscribed to the Google Groups "mozilla-rhino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-rhin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tomaž Kunaver

unread,
Apr 23, 2018, 3:13:37 PM4/23/18
to mozill...@googlegroups.com
Actually, I am well aware of the class shutter thing (I am using it actually) and security manager (which I am not using since I'm not willing to risk slowing down the entire application just for a higher security... I'm developing a game, so high FPS is a priority), however that was not my question. I am wondering if Rhino has any mechanism that would block any attempts to assign to classes fields. For example:
myObject.x = 0;
I want to disallow the above code (but still want to be able to use myObject and also read myObject.x field). Any way to do that?

To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-rhino+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mozilla-rhino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-rhino+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages