views:

42

answers:

1

This an example problem to illustrates my point. I'm not looking for a solution to this problem but instead the general idea behind it.

Lets just say I've got a project that lets people load in dynamic assemblies -- the idea being "plug-ins". Lets say it runs on a Web Server. They inherit from the abstract plugin class and define a few methods... but one of them does this...

public class SomePlugin : PluginBaseClass {
    //Some method that is supposed to update the 
    //the plugin information
    public virtual void Update() {
        HttpContext.Current.Response.Redirect("http://new-website.com");
    }
}

I wouldn't want to allow a dynamic assembly to have access to something like that -- but since it is static, what can you do?

I'm not sure how you lock down assemblies, but it seems to me that you can't possibly cover all of your bases. You still want them to be able to create classes and have access to some things, but not others.

Any suggestions for protecting your static information in .NET from dynamic assemblies?

+1  A: 

The answer depends on what your plugins should be alowed to do. CAS might be a solution, but I'm not very good at that, so I cannot give you a general example. Another option could be to load plugins in their own app domain. Instances in a different app domain should not have access to your HttpContext.Current.

Achim
This answer will serve most of the time. Watch out that you do not load the assembly with full trust either or being in a different AppDomain won't help much.
Joshua