Re: Compile assembly in runtime and execute in sandbox

From: Henning Krause [MVP] (newsgroup.no_at_spam.infinitec.de)
Date: 02/26/05

  • Next message: Mantas Miliukas: "Re: User Control in IE (authentication)?"
    Date: Sat, 26 Feb 2005 10:22:22 +0100
    
    

    Hello,

    I'm not very proficient on this topic, but I believe you should load the
    newly created type into another app domain and execute it there.

    The new app domain can be initialized with a custom set of evidence.

    Greetings,
    Henning Krause [MVP]
    ==========================
    Visit my website: http://www.infinitec.de
    Try my free Exchange Explorer: Mistaya
    (http://www.infinitec.de/software/mistaya.aspx)

    "JFN" <andre@ipmouse.com> wrote in message
    news:OtQ8l44GFHA.904@tk2msftngp13.phx.gbl...
    > Hello,
    >
    > I'm trying to use C# as a script language for my .NET application.
    > Users able to write a method (say, Foo(Myclass parameter))
    > Then in run time I'm wrapping this method into namespace code, compile
    into
    > assembly signed with special key and execute.
    >
    > Here is a problem - I'd like to apply some restrictions on user's code.
    > I.e. "Internet" set of permissions.
    >
    > But it doesn't work. When I create code group for this special key, any
    > permission set besides "Full trust" gives me
    > "Security error". Even "Everything" set. I have "This policy level"
    > checkbox in Code Group properties dialog checked (if it not checked then
    > compiled assembly got all permissions from main application)
    > So, is it possible at all? Am I doing something wrong or may be just
    don't
    > understand something about security model?
    >
    > Please, help!
    >
    > Here is code snippet
    >
    > CodeDomProvider provider = new CSharpCodeProvider();
    > ICodeCompiler compiler = provider.CreateCompiler();
    > CompilerParameters compilerParams = new CompilerParameters();
    > compilerParams.GenerateInMemory = false;
    > compilerParams.ReferencedAssemblies.Add("System.dll");
    >
    >
    compilerParams.ReferencedAssemblies.Add(Path.Combine(Application.StartupPath
    > , "MyCompany.MyFramework.dll"));
    >
    > string code = "[assembly: AssemblyKeyName(\"MyKey\")]";
    > code += myNamespaceAndMethodText;
    >
    > CompilerResults results =
    > compiler.CompileAssemblyFromSource(compilerParams, code);
    > object o = results.CompiledAssembly.CreateInstance("MyClass",
    true);
    >
    > //this is where Security exception throws:
    > object retVal = o.GetType().InvokeMember("Foo", new object[]
    > {myClassInstance});
    >
    >
    > regards,
    > Ken
    >
    >
    >
    >


  • Next message: Mantas Miliukas: "Re: User Control in IE (authentication)?"

    Relevant Pages

    • Re: Compile assembly in runtime and execute in sandbox
      ... newly created type into another app domain and execute it there. ... The new app domain can be initialized with a custom set of evidence. ... When I create code group for this special key, ...
      (microsoft.public.dotnet.framework.clr)
    • Re: LoadFrom problem in Web Service
      ... > execute a method via reflection without a problem (the assembly was ... Did you make sure the assembly was a Service Component, ... I am not creating any new app domain in my code, ...
      (microsoft.public.dotnet.framework.remoting)
    • Re: Help on Asp.Net Code Syncronization
      ... Since each ASP.NET request is executed on a separate thread, you can take advantage of the .NET thread synchronization support. ... For synchronization within the same App Domain take a look at System.Threading.Monitor class or the syntactic sugar for this in C# is lock and SyncLock in VB.NET ... This is because this method execute some code that can't be execute twice at the same time. ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: AppDomain.UnhandledException in Windows Forms and Windows Service
      ... "An UnhandledExceptionEventHandler can only be specified for the ... default application domain that is created by the system to execute an ... default app domain. ... are you re-throwing the error in your handler? ...
      (microsoft.public.dotnet.languages.vb)