AnthonyOSX
AnthonyOSX

Reputation: 348

Restrict untrusted code from making web requests and opening ports

I'm developing an application that will execute untrusted code in a sandboxed AppDomain. The AppDomain is created like so:

AppDomain.CreateDomain("Sandbox: " + Guid.NewGuid().ToString("N"), AppDomain.CurrentDomain.Evidence, new AppDomainSetup(), grantSet);

Where grantSet is a PermissionSet that I am using to restrict what this untrusted code can do. One of my requirements is to block web calls and ports (similar to SocketPermission in Java). I've looked and haven't been able to find an IPermission that seems to be able to do this.

How can I prevent untrusted code from making web requests to non whitelisted sites and opening ports?

Upvotes: 1

Views: 54

Answers (1)

usr
usr

Reputation: 171206

.NET does not support untrusted code in practice.

Although CAS policy in theory does what you want .Net is insecure in practice. For example you can see numerous JIT bugs in the CoreClr commit logs that can be used to escape the sandbox. Only execution permission required.

The JVM is the same: Theoretically safe, a Swiss cheese in practice. That's why modern browsers do not run "safe" Java applets anymore.

If "not trivial to exploit" is enough for you do not grant SocketPermission.

Also, are you sure you want to use trusted evidence (AppDomain.CurrentDomain.Evidence)? Seems unsafe.

Upvotes: 1

Related Questions