I assume this isn’t something many people are concerned about, but as someone who’s heavily security conscious, I’m very interested in the number of precautions taken to limit the vulnerability surface of the C# programming layer. I’m fairly confident garry and co. have well-thought this through, but it would be nice to receive some actual confirmation.
A while back I’ve researched the various security hardening methods available for .NET Framework and .NET Core, and my findings have been somewhat… concerning, to say the least. Here they are in no particular order:
-
AppDomains are deprecated and virtually all Microsoft documentation suggests they shouldn’t be used anymore and don’t offer a strong security guarantee. There have also been mentions of performance penalties associated with using the .NET access control system. In .NET Core the whole subsystem is entirely removed and there is no way to instantiate separate AppDomains.
-
It is fairly hard to verify compiled .NET assemblies because they might contain unsafe code, which can pretty much do anything. This can be limited to an extent by using PEVerify (the MS .NET tool to verify the safety of .NET assemblies), but this method also seems fairly limited to me because it requires inspecting an assembly post-factum rather than restricting the number of available operations on the language level. The other way in which I can see this being implemented is by using an AST-level verifier that checks that the code contains no unsafe blocks and other operations that might expose a client to a vulnerability, but this also feels fragile to me.
-
Microsoft has explicitly stated in various sources (if I remember correctly) that .NET does not offer strong sandboxing guarantees and shouldn’t be used in scenarios where untrusted or semi-trusted code is being run. This puts yet another level of concern on top of the points listed above. This also seems to be the reason why they chose to stop supporting and updating the AppDomain and security access control subsystems.
-
C# and .NET are not without vulnerabilities. Humans are fallible, and I have no doubts that .NET is a fairly secure runtime environment, simply because it has been tested ad-nauseam by millions of people. Still, due to the sheer size of the .NET code-base, which is written mostly in C++, this means that there are likely many more vulnerabilities to be discovered. Most of these are probably fairly benign ones like buffer overruns causing an immediate crash, or some other unwanted behaviour of limited scope, but anything that may read or alter unwanted sections of memory can cause a lot of havoc.
-
Reflection is a fairly important feature of C# that, unfortunately, has the potential to wreak a lot of havoc as well, in particular if access is gained to methods that are not supposed to be exposed to the user code. I can imagine this is limited by not loading restricted standard assemblies, but it would be nice to have some confirmation.
This is pretty much everything I can think off the top of my head. I can only hope that S&box does not place an excessive vulnerability burden on its player, and I hope that Facepunch has given this whole topic reasonable amount of planning and forethought. It would be really nice to have that confirmation, though.