I installed a small example when I loaded the assembly into a new AppDomain without permission. This works great, the assembly cannot access the file system and cannot listen to sockets.
But there is one more thing I want to prevent: creating a theme. What for? Theoretically, theoretically, this assembly can create a thread that creates even more threads and floods my memory.
I thought of (in my opinion) the best way: AppDomain memory limitation. Is it possible? And if not, what can I do to avoid creating threads?
This code is used to create a stream.
Thread t = new Thread(this.DoWork); t.Start();
And this code is for AppDomain
PermissionSet set = new PermissionSet(PermissionState.None); set.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); set.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery, this.path)); AppDomainSetup info = new AppDomainSetup { ApplicationBase = this.path }; this.domain = AppDomain.CreateDomain("Sandbox", null, info, set, null);
(Well, I gave access to the file system in the folder where I want to load the assembly, it's just because StrongName fullTrustAssembly = typeof(SecureInstance).Assembly.Evidence.GetHostEvidence<StrongName>(); does not work for me either.
Hope s / o can help. (
source share