You should never rely on private , public , etc. to ensure security (as in the section "Protection against malicious code and external threats"). They are designed so that the programmer does not shoot in the leg, and not as a (computer) security measure. You can also easily access the private member fields of C ++ objects if you bypass static compiler checks and go directly to memory, but can you say that C ++ lacks true encapsulation?
That way, you would never use private or protected as a security measure against malicious plugins in C ++ or Java, and I also assume that C #.
It’s best to run the plugins in a separate process and expose the main API via IPC / RPC or even a web service or run them in the sandbox (according to what @MarkHildreth indicated). In addition, you can set up a certification and signature process for your plugins so that you can view and filter potentially harmful plugins before they even get distributed.
Note:
In fact, you can achieve true encapsulation with lexical closures:
def Foo(param): param = [param]
... but even then the value is actually still relatively easily accessible through reflection:
>>> foo.__class__.param.fget.__closure__[0].cell_contents[0] = 'hey' >>> foo.param 'hey'
... and even if this is not possible, we will still be ctypes with ctypes , which allows direct access to memory, bypassing any remaining cosmetic "restrictions":
import ctypes arr = (ctypes.c_ubyte * 64).from_address(id(foo))
and now you can just assign arr or read it; although you have to work hard to traverse the pointers from there to the actual memory location where .param is stored, but this proves the point.
Erik allik
source share