Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a Thread be executed as another user? (.NET 2.0/3.5)
    primarykey
    data
    text
    <p>I have a C# application the performs some runtime compilation of source files containing calculations into dynamic assemblies. Obviously this presents a serious security issue.</p> <p>From the following 'formula', the code below would be generated, and a dynamic assembly created:</p> <p>Formula:</p> <pre><code>Int32 _index = value.LastIndexOf('.'); String _retVal = value.Substring(_index + 1); return _retVal; </code></pre> <p>Code Generated:</p> <pre><code>using System; namespace Dynamics { public class Evaluator { public Object Evaluate(String value) { // Begin external code Int32 _index = value.LastIndexOf('.'); String _retVal = value.Substring(_index + 1); return _retVal; // End external code } } } </code></pre> <p>The dynamic assembly is then loaded and the Evaluate method executed via Reflection. This works Great.</p> <p>The problem is that the potential for malicious code injection is huge, so I want to run the Evaluate method in a 'Sandboxed' thread (without any unmanaged API calls). For testing purposes I'm using the built in Anonymous Windows user, and have come up with the following code:</p> <pre><code>Thread tSandbox = new Thread( new ParameterizedThreadStart(this.DoSandboxedEvaluation)); WindowsIdentity tIdentity = WindowsIdentity.GetAnonymous(); WindowsPrincipal tPrincipal = new WindowsPrincipal(i); </code></pre> <p>This gives me the Anonymous users' Identity and Principal. How can this be applied to thread tSandbox so the code on that thread runs in the specified Security Context, without using Unmanaged API calls?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload