Reputation: 7475
I am working on a project where I will allow users to write some code, which will be compiled, loaded and ran, this code will allow the users to control certain parts of the application. However, with this just allowing them to insert C# into the running app, there are certain restrictions I'd preferably like to have in place.
Are there any ways that you can run a piece of code but lets say block out any System.Threading
use or any System.IO
use?
I know going through the code and removing any references would be possible, but I am sure there would be ways around that. Before writing this, I'd at least like to check there isn't an easier, more effective way.
I have googled but either I am looking in the wrong place or asking the wrong question. I do know, however, that you Stack Overflow people are geniuses. Any ideas?
Thanks, and any answer would be appreciated greatly!
Upvotes: 4
Views: 710
Reputation: 2007
Instead of going through the code and removing all the individual references, why not just limit the project references? Also, you might be able to leverage .NET permissions on a system by using the .NET framework configuration snap in to manage access to GAC, domain apps, etc. based on various options. (start > run > mscorcfg.msc to launch it) I don't know what the newer 4.0 option is to replace that configuration utility however. EDIT: To take it one step further you could, for example run the entered code with a service user account and limit that user's code access via this utility.
Upvotes: 0