views:

152

answers:

3

I'm setting up a web application to use IronPython for scripting various user actions and I'll be exposing various business objects ready for accessing by the script. I want to make it impossible for the user to import the CLR or other assemblies in order to keep the script's capabilities simple and restricted to the functionality I expose in my business objects.

How do I prevent the CLR and other assemblies/modules from being imported?

+1  A: 

You'll have to search the script for the imports you don't want them to use, and reject the script in toto if it contains any of them.

Basically, just reject the script if it contains Assembly.Load, import or AddReference.

Robert Harvey
I take it then I can't set an option to do this. No problem, I can parse the code, it just seemed a little sticky doing it that way.
Nathan Ridley
A: 

If you'd like to disable certain built-in modules I'd suggest filing a feature request over at ironpython.codeplex.com. This should be an easy enough thing to implement.

Otherwise you could simply look at either Importer.cs and disallow the import there or you could simply delete ClrModule.cs from IronPython and re-build (and potentially remove any references to it).

Dino Viehland
+1  A: 

You might want to implement the protection using Microsoft's Code Access Security. I myself am not fully aware of its workings (or how to make it work with IPy), but its something which I feel you should consider.

There's a discussion thread on the IPy mailing list which you might want to look at. The question asked is similar to yours.

Rohit