Пример #1
0
        public ScriptSandbox(SandboxSecurityParameters securityParameters, string sandboxName)
        {
            SandboxDomain = CreateSandboxedAppDomain(securityParameters, sandboxName);
            foreach (Assembly availableAssembly in securityParameters.AvailableAssemblies)
            {
                SandboxDomain.Load(availableAssembly.FullName);
            }

            var isolated = new SandboxedCommand <ScriptingEngine>(SandboxDomain);

            SandboxedEngine = isolated.Value;
        }
Пример #2
0
        private AppDomain CreateSandboxedAppDomain(SandboxSecurityParameters securityParameters, string sandboxName)
        {
            PermissionSet securityManager = null;

            if (securityParameters.UseZoneSecurity)
            {
                var evidence = new Evidence();
                evidence.AddHostEvidence(securityParameters.ZoneSecurityEvidence);
                securityManager = SecurityManager.GetStandardSandbox(evidence);
            }
            else
            {
                //Use explicit permission security
                securityManager = securityParameters.AppDomainPermissions;
            }

            var appDomainSetup = new AppDomainSetup()
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
            };

            return(AppDomain.CreateDomain(sandboxName, null, appDomainSetup, securityManager, securityParameters.FullTrustAssemblies));
        }