tags:

views:

166

answers:

2

I asked a while ago how to restrict plugins access ( I want to prevent them from writing to the disk or network ) and i was told to use AppDomain. I have searched and tried and failed on how to get this working.

Can anyone provide some information so i can get started, simply put make a AppDomain that does not allows writing to the file or network.

A: 

If you're using plugins, you might perhaps know about proxies.

While loading your assembly through a proxy, you can specify the security policy level for this particular assembly through the LoadAssembly() method or so, if I remember correctly. In other words, this is done through reflection.

I know my answer isn't that much detailed, but I hope it will give you an idea of where to look for your solution. I shall take an eye out to find further details on the subject so that I may be of better help. =)

Hope you will share your findings when you've done it.

Will Marcouiller
+1  A: 

I guess this is what you need, if I understand correctly your point.

System.Security.PermissionSet ps = 
    new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
ps.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.NoAccess, "C:\\"));
System.Security.Policy.PolicyLevel pl = System.Security.Policy.PolicyLevel.CreateAppDomainLevel();
pl.RootCodeGroup.PolicyStatement = new System.Security.Policy.PolicyStatement(ps);
AppDomain.CurrentDomain.SetAppDomainPolicy(pl);
System.Reflection.Assembly myPluginAssembly = AppDomain.CurrentDomain.Load("MyPluginAssembly");

Is this more precisely what you meant?

Notice that you may provide an array of string containg the paths where you don't want the plugin to have access. You may provide if when initializing the new instance of FileIOPermission class.

Let me know if this helps. :-)

Will Marcouiller
That seems to be exacly what im after, i get The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) now but i have not had the time yet to look more into it ( Im proberbly doing something wrong ). Il get more time tomorrow and il let you know
EKS
So, finally, was this what you were looking for? I guess, since you seem to have checked it. :-)
Will Marcouiller
@EKS you have to load from the same folder or one of the children of the folder.
Dave Hillier