I'm making a piece of rendering software and I want to make the tools it encompasses extensible. I've built a UI that lets the user write custom C# functions for blending values. The functions (and accompanying values/constants) are added to a class and compiled using CodeDom, and the blend function is used from there. The functions must take the signature:

public float Blend(float baseValue, float value);

The trouble I'm having is that someone could very easily write a script that does all manner of malicious stuff. They know that this blend function is the entry point, but they could put any kind of code in there. Is there any way to restrict what assemblies are available to the CodeDom compiler? For example could I blacklist or whitelist certain assemblies? Could I prevent the script from accessing System.IO for example?

Regards and thanks in advance.


I've seen in other places where it is suggested to use AppDomain to sandbox your code.

The recommended approach for this is to execute the suspect code in a sandboxed appdomain. Several reasons are given at http://blogs.msdn.com/b/shawnfa/archive/2006/04/19/579066.aspx, and an even more important one is that most of the other potential approaches are deprecated as of .NET 4.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.